添加项目文件。
This commit is contained in:
1 parent
05e131ca4e
commit
514d6f5255
1162 files changed
+81255
No files matched your search
@@ -0,0 +1,179 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Core.Auth;
|
||||
using WalkingTec.Mvvm.Core.Extensions;
|
||||
using WalkingTec.Mvvm.Mvc;
|
||||
|
||||
namespace HHWMS.Web.Controllers
|
||||
{
|
||||
public class HomeController : BaseController
|
||||
{
|
||||
[AllRights]
|
||||
public IActionResult Index(string redirect)
|
||||
{
|
||||
ViewData["title"] = "WTM";
|
||||
return View();
|
||||
}
|
||||
|
||||
|
||||
[AllowAnonymous]
|
||||
public IActionResult PIndex()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[AllRights]
|
||||
[ActionDescription("FrontPage")]
|
||||
public IActionResult FrontPage()
|
||||
{
|
||||
|
||||
return PartialView();
|
||||
}
|
||||
[AllowAnonymous]
|
||||
|
||||
public IActionResult GetActionChart()
|
||||
{
|
||||
var areas = GlobaInfo.AllModule.Select(x => x.Area).Distinct();
|
||||
var data = new List<ChartData>();
|
||||
|
||||
foreach (var area in areas)
|
||||
{
|
||||
var controllers = GlobaInfo.AllModule.Where(x => x.Area == area);
|
||||
data.Add(new ChartData
|
||||
{
|
||||
Category = "Controllers",
|
||||
Value = controllers.Count(),
|
||||
Series = area?.AreaName ?? "Default"
|
||||
});
|
||||
data.Add(new ChartData
|
||||
{
|
||||
Category = "Actions",
|
||||
Value = controllers.SelectMany(x=>x.Actions).Count(),
|
||||
Series = area?.AreaName ?? "Default"
|
||||
});
|
||||
}
|
||||
var rv = data.ToChartData();
|
||||
return Json(rv);
|
||||
}
|
||||
[AllowAnonymous]
|
||||
public IActionResult GetModelChart()
|
||||
{
|
||||
var models = new List<Type>();
|
||||
|
||||
//获取所有模型
|
||||
var pros = Wtm.ConfigInfo.Connections.SelectMany(x => x.DcConstructor.DeclaringType.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance));
|
||||
if (pros != null)
|
||||
{
|
||||
foreach (var pro in pros)
|
||||
{
|
||||
if (pro.PropertyType.IsGeneric(typeof(DbSet<>)))
|
||||
{
|
||||
models.Add(pro.PropertyType.GetGenericArguments()[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
var data = new List<ChartData>();
|
||||
|
||||
foreach (var m in models)
|
||||
{
|
||||
data.Add(new ChartData
|
||||
{
|
||||
Value = m.GetProperties().Count(),
|
||||
Category = m.GetPropertyDisplayName(),
|
||||
Series = "Model"
|
||||
}) ;
|
||||
}
|
||||
var rv = data.ToChartData();
|
||||
return Json(rv);
|
||||
}
|
||||
[AllowAnonymous]
|
||||
public IActionResult GetSampleChart()
|
||||
{
|
||||
var data = new List<ChartData>();
|
||||
Random r = new Random();
|
||||
int maxi = r.Next(3, 10);
|
||||
int maxy = r.Next(3, 10);
|
||||
for (int i = 0; i < maxi; i++)
|
||||
{
|
||||
for (int j = 0; j < maxy; j++)
|
||||
{
|
||||
data.Add(new ChartData
|
||||
{
|
||||
Category = "x" + i,
|
||||
Value = r.Next(100, 1000),
|
||||
ValueX = r.Next(200, 2000),
|
||||
Series = "y" + j,
|
||||
Addition = r.Next(100, 1000),
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
var rv = data.ToChartData();
|
||||
return Json(rv);
|
||||
}
|
||||
|
||||
[AllRights]
|
||||
[ActionDescription("Layout")]
|
||||
public IActionResult Layout()
|
||||
{
|
||||
ViewData["debug"] = Wtm.ConfigInfo.IsQuickDebug;
|
||||
return PartialView();
|
||||
}
|
||||
|
||||
[AllRights]
|
||||
public IActionResult UserInfo()
|
||||
{
|
||||
if (HttpContext.Request.Cookies.TryGetValue(CookieAuthenticationDefaults.CookiePrefix + AuthConstants.CookieAuthName, out string cookieValue))
|
||||
{
|
||||
var protectedData = Base64UrlTextEncoder.Decode(cookieValue);
|
||||
var dataProtectionProvider = HttpContext.RequestServices.GetRequiredService<IDataProtectionProvider>();
|
||||
var _dataProtector = dataProtectionProvider
|
||||
.CreateProtector(
|
||||
"Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware",
|
||||
CookieAuthenticationDefaults.AuthenticationScheme,
|
||||
"v2");
|
||||
var unprotectedData = _dataProtector.Unprotect(protectedData);
|
||||
|
||||
string cookieData = Encoding.UTF8.GetString(unprotectedData);
|
||||
return JsonMore(cookieData);
|
||||
}
|
||||
else
|
||||
return JsonMore("No Data");
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
public github GetGithubInfo()
|
||||
{
|
||||
var rv = Wtm.ReadFromCache<github>("githubinfo", () =>
|
||||
{
|
||||
var s = Wtm.CallAPI<github>("github", "repos/dotnetcore/wtm", 60).Result;
|
||||
return s.Data;
|
||||
}, 1800);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
public class github
|
||||
{
|
||||
public int stargazers_count { get; set; }
|
||||
public int forks_count { get; set; }
|
||||
public int subscribers_count { get; set; }
|
||||
public int open_issues_count { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Core.Extensions;
|
||||
using WalkingTec.Mvvm.Mvc;
|
||||
using WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkUserVms;
|
||||
using HHWMS.Web.ViewModels.HomeVMs;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace HHWMS.Web.Controllers
|
||||
{
|
||||
[AllRights]
|
||||
public class LoginController : BaseController
|
||||
{
|
||||
[Public]
|
||||
[ActionDescription("Login")]
|
||||
public IActionResult Login()
|
||||
{
|
||||
LoginVM vm = Wtm.CreateVM<LoginVM>();
|
||||
vm.Redirect = HttpContext.Request.Query["ReturnUrl"];
|
||||
if (Wtm.ConfigInfo.IsQuickDebug == true)
|
||||
{
|
||||
vm.ITCode = "admin";
|
||||
vm.Password = "000000";
|
||||
}
|
||||
return View(vm);
|
||||
}
|
||||
|
||||
[Public]
|
||||
[HttpPost]
|
||||
public async Task<ActionResult> Login(LoginVM vm)
|
||||
{
|
||||
/*if (Wtm.ConfigInfo.IsQuickDebug == false)
|
||||
{
|
||||
var verifyCode = HttpContext.Session.Get<string>("verify_code");
|
||||
if (string.IsNullOrEmpty(verifyCode) || verifyCode.ToLower() != vm.VerifyCode.ToLower())
|
||||
{
|
||||
vm.MSD.AddModelError("", Localizer["Login.ValidationFail"]);
|
||||
return View(vm);
|
||||
}
|
||||
}*/
|
||||
var user = Wtm.DoLogin(vm.ITCode, vm.Password, vm.Tenant);
|
||||
if (user == null)
|
||||
{
|
||||
vm.MSD.AddModelError("", Localizer["Sys.LoginFailed"]);
|
||||
return View(vm);
|
||||
}
|
||||
else
|
||||
{
|
||||
//其他属性可以通过user.Attributes["aaa"] = "bbb"方式赋值
|
||||
Wtm.LoginUserInfo = user;
|
||||
string url = string.Empty;
|
||||
if (!string.IsNullOrEmpty(vm.Redirect))
|
||||
{
|
||||
url = vm.Redirect;
|
||||
}
|
||||
else
|
||||
{
|
||||
url = "/";
|
||||
}
|
||||
|
||||
AuthenticationProperties properties = null;
|
||||
if (vm.RememberLogin)
|
||||
{
|
||||
properties = new AuthenticationProperties
|
||||
{
|
||||
IsPersistent = true,
|
||||
ExpiresUtc = DateTimeOffset.UtcNow.Add(TimeSpan.FromDays(30))
|
||||
};
|
||||
}
|
||||
var principal = user.CreatePrincipal();
|
||||
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, properties);
|
||||
return Redirect(HttpUtility.UrlDecode(url));
|
||||
}
|
||||
}
|
||||
|
||||
[Public]
|
||||
public IActionResult Reg()
|
||||
{
|
||||
if (ConfigInfo.HasMainHost)
|
||||
{
|
||||
|
||||
return Content(Localizer["_Admin.HasMainHost"]);
|
||||
}
|
||||
var vm = Wtm.CreateVM<RegVM>();
|
||||
return PartialView(vm);
|
||||
}
|
||||
|
||||
[Public]
|
||||
[HttpPost]
|
||||
public IActionResult Reg(RegVM vm)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return PartialView(vm);
|
||||
}
|
||||
else
|
||||
{
|
||||
var rv = vm.DoReg();
|
||||
if (rv == true)
|
||||
{
|
||||
return FFResult().CloseDialog().Message(Localizer["Reg.Success"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return PartialView(vm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[AllRights]
|
||||
[ActionDescription("Logout")]
|
||||
public async Task Logout()
|
||||
{
|
||||
HttpContext.Session.Clear();
|
||||
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
||||
if (ConfigInfo.HasMainHost == false || Wtm.LoginUserInfo?.CurrentTenant != null)
|
||||
{
|
||||
HttpContext.Response.Redirect("/");
|
||||
}
|
||||
else
|
||||
{
|
||||
Wtm.CallAPI<string>("mainhost", "/api/_account/logout", HttpMethodEnum.GET, new { }, 10).Wait();
|
||||
HttpContext.Response.Redirect(ConfigInfo.MainHost);
|
||||
}
|
||||
}
|
||||
|
||||
[AllRights]
|
||||
[ActionDescription("ChangePassword")]
|
||||
public ActionResult ChangePassword()
|
||||
{
|
||||
var vm = Wtm.CreateVM<ChangePasswordVM>();
|
||||
vm.ITCode = Wtm.LoginUserInfo.ITCode;
|
||||
return PartialView(vm);
|
||||
}
|
||||
|
||||
[AllRights]
|
||||
[HttpPost]
|
||||
[ActionDescription("ChangePassword")]
|
||||
public ActionResult ChangePassword(ChangePasswordVM vm)
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
var result = Wtm.CallAPI<string>("mainhost", "/api/_account/ChangePassword", HttpMethodEnum.POST, vm, 10).Result;
|
||||
if (result.StatusCode == System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
return FFResult().CloseDialog().Alert(Localizer["Login.ChangePasswordSuccess"]);
|
||||
}
|
||||
else if (result.StatusCode == System.Net.HttpStatusCode.BadRequest)
|
||||
{
|
||||
ModelState.Clear();
|
||||
foreach (var item in result.Errors.Form)
|
||||
{
|
||||
ModelState.AddModelError(item.Key, item.Value);
|
||||
}
|
||||
foreach (var item in result.Errors.Message)
|
||||
{
|
||||
ModelState.AddModelError(" ", item);
|
||||
}
|
||||
return PartialView(vm);
|
||||
}
|
||||
else
|
||||
{
|
||||
return FFResult().CloseDialog().Alert(Localizer["Sys.Error"]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return PartialView(vm);
|
||||
}
|
||||
else
|
||||
{
|
||||
vm.DoChange();
|
||||
return FFResult().CloseDialog().Alert(Localizer["Login.ChangePasswordSuccess"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user