diff --git a/HHWMS.Web/Controllers/HomeController.cs b/HHWMS.Web/Controllers/HomeController.cs index 7b6f262..430e469 100644 --- a/HHWMS.Web/Controllers/HomeController.cs +++ b/HHWMS.Web/Controllers/HomeController.cs @@ -3,15 +3,11 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; -using System.Threading.Tasks; using System.Web; -using HHWMS.Web.Support; -using HHWMS.Web.ViewModels.HomeVMs; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.DataProtection; -using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; @@ -157,18 +153,6 @@ namespace HHWMS.Web.Controllers return JsonMore("No Data"); } - [Public] - public IActionResult CheckLogin() - { - return Ok(); - } - - [Public] - public IActionResult BeforeLogin(LoginVM vm) - { - return JsonMore(UserSessionManager.AllSignined().ToList()); - } - //[AllowAnonymous] //public github GetGithubInfo() //{ diff --git a/HHWMS.Web/Controllers/LoginController.cs b/HHWMS.Web/Controllers/LoginController.cs index 54cca77..9f45cef 100644 --- a/HHWMS.Web/Controllers/LoginController.cs +++ b/HHWMS.Web/Controllers/LoginController.cs @@ -14,11 +14,6 @@ using WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkUserVms; using HHWMS.Web.ViewModels.HomeVMs; using System.Collections.Generic; using System.Linq; -using System.Text; -using HHWMS.Web.Support; -using Microsoft.AspNetCore.Identity; -using Microsoft.Extensions.Caching.Distributed; -using WalkingTec.Mvvm.Core.Support.Quartz; namespace HHWMS.Web.Controllers { @@ -38,7 +33,7 @@ namespace HHWMS.Web.Controllers } return View(vm); } - + [Public] [HttpPost] public async Task Login(LoginVM vm) @@ -52,9 +47,7 @@ namespace HHWMS.Web.Controllers return View(vm); } }*/ - var user = Wtm.DoLogin(vm.ITCode, vm.Password, vm.Tenant); - if (user == null) { vm.MSD.AddModelError("", Localizer["Sys.LoginFailed"]); @@ -62,13 +55,6 @@ namespace HHWMS.Web.Controllers } else { - var bb = UserSessionManager.IsUserSignined(user.Name); - if (bb) - { - // 踢人下线 - await KickUser(user.Name); - } - //其他属性可以通过user.Attributes["aaa"] = "bbb"方式赋值 Wtm.LoginUserInfo = user; string url = string.Empty; @@ -91,9 +77,7 @@ namespace HHWMS.Web.Controllers }; } var principal = user.CreatePrincipal(); - await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, properties); - UserSessionManager.AddUserSession(user.Name,principal.Claims.First(c => c.Type == "SessionId").Value); return Redirect(HttpUtility.UrlDecode(url)); } } @@ -136,7 +120,6 @@ namespace HHWMS.Web.Controllers [ActionDescription("Logout")] public async Task Logout() { - UserSessionManager.RemoveUserSession(Wtm.LoginUserInfo.Name); HttpContext.Session.Clear(); await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); if (ConfigInfo.HasMainHost == false || Wtm.LoginUserInfo?.CurrentTenant != null) @@ -149,15 +132,7 @@ namespace HHWMS.Web.Controllers HttpContext.Response.Redirect(ConfigInfo.MainHost); } } - - [AllRights] - public async Task KickUser(string ITcode) - { - UserSessionManager.KickUser(ITcode); - await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); - return Ok(); - } - + [AllRights] [ActionDescription("ChangePassword")] public ActionResult ChangePassword() diff --git a/HHWMS.Web/Program.cs b/HHWMS.Web/Program.cs index 1f62ec5..b763197 100644 --- a/HHWMS.Web/Program.cs +++ b/HHWMS.Web/Program.cs @@ -76,7 +76,6 @@ app.UseSession(); app.UseWtmSwagger(false); app.UseSwaggerExt(); app.UseWtm(); -app.UseMiddleware(); app.AddQuartzJobs(); app.UseEndpoints(endpoints => { diff --git a/HHWMS.Web/Support/SessionValidationMiddleware.cs b/HHWMS.Web/Support/SessionValidationMiddleware.cs deleted file mode 100644 index 794bb6e..0000000 --- a/HHWMS.Web/Support/SessionValidationMiddleware.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Authentication.Cookies; -using Microsoft.AspNetCore.Http; -using WalkingTec.Mvvm.Core; -using WalkingTec.Mvvm.Core.Support.Quartz; - -namespace HHWMS.Web.Support; - -public class SessionValidationMiddleware -{ - private readonly RequestDelegate _next; - - public SessionValidationMiddleware(RequestDelegate next) - { - _next = next; - } - - public async Task InvokeAsync(HttpContext context) - { - if (context.User.Identity.IsAuthenticated) - { - var userId = context.User.Identity.Name; - var sessionId = context.User.Claims.FirstOrDefault(c => c.Type == "SessionId")?.Value; - - if (!UserSessionManager.IsUserSessionValid(userId, sessionId)) - { - // UserSessionManager.RemoveUserSession(userId); - await context.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); - context.Response.Redirect(new Configs().CookieOptions.LogoutPath); - return; - } - } - - await _next(context); - } -} \ No newline at end of file diff --git a/HHWMS.Web/Support/UserSessionManger.cs b/HHWMS.Web/Support/UserSessionManger.cs deleted file mode 100644 index 3c16139..0000000 --- a/HHWMS.Web/Support/UserSessionManger.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System.Linq; -using Microsoft.AspNetCore.Mvc; -using WalkingTec.Mvvm.Core; - -namespace HHWMS.Web.Support; - -using System.Collections.Concurrent; - -public class UserSessionManager -{ - private static ConcurrentDictionary userSessions = new ConcurrentDictionary(); - - public static void AddUserSession(string userId, string sessionId) - { - userSessions[userId.ToLower()] = sessionId; - } - - public static void RemoveUserSession(string userId) - { - userSessions.TryRemove(userId, out _); - } - - public static bool IsUserSessionValid(string userId, string sessionId) - { - return userSessions.TryGetValue(userId.ToLower(), out var storedSessionId) && storedSessionId == sessionId; - } - - public static bool IsUserSignined(string userId) - { - return userSessions.ContainsKey(userId); - } - - public static void KickUser(string userId) - { - userSessions.TryRemove(userId, out _); - } - - public static ConcurrentDictionary AllSignined() - { - return userSessions; - } -} \ No newline at end of file diff --git a/HHWMS.Web/Views/Home/Index.cshtml b/HHWMS.Web/Views/Home/Index.cshtml index 03041ee..b1d2e1d 100644 --- a/HHWMS.Web/Views/Home/Index.cshtml +++ b/HHWMS.Web/Views/Home/Index.cshtml @@ -1,28 +1 @@ - diff --git a/HHWMS.Web/Views/Login/Login.cshtml b/HHWMS.Web/Views/Login/Login.cshtml index d2ac63d..cab682e 100644 --- a/HHWMS.Web/Views/Login/Login.cshtml +++ b/HHWMS.Web/Views/Login/Login.cshtml @@ -36,7 +36,7 @@ - diff --git a/HHWMS.Web/appsettings.json b/HHWMS.Web/appsettings.json index 9c5095c..c58d986 100644 --- a/HHWMS.Web/appsettings.json +++ b/HHWMS.Web/appsettings.json @@ -41,9 +41,9 @@ //} ], "CookiePre": "HHWMS", //cookie前缀 - "IsQuickDebug": false, //是否启用debug模式 + "IsQuickDebug": true, //是否启用debug模式 "EnableTenant": false, //是否启动多租户 - "SyncDb": false, //是否自动同步数据库 + "SyncDb": true, //是否自动同步数据库 "EncryptKey": "", //加密密钥 "PageMode": "Tab", //页面显示模式,Single或者Tab "TabMode": "Simple", //Tab页显示方式,Default或者Simple diff --git a/src/WalkingTec.Mvvm.Core/Extensions/LoginUserInfoExtension.cs b/src/WalkingTec.Mvvm.Core/Extensions/LoginUserInfoExtension.cs index 272dd03..5b90d9f 100644 --- a/src/WalkingTec.Mvvm.Core/Extensions/LoginUserInfoExtension.cs +++ b/src/WalkingTec.Mvvm.Core/Extensions/LoginUserInfoExtension.cs @@ -15,11 +15,7 @@ namespace WalkingTec.Mvvm.Core.Extensions public static ClaimsPrincipal CreatePrincipal(this LoginUserInfo self) { if (string.IsNullOrEmpty(self.ITCode)) throw new ArgumentException("Id is mandatory", nameof(self.ITCode)); - var claims = new List - { - new Claim(AuthConstants.JwtClaimTypes.Subject, self.ITCode) , - new Claim("SessionId", Guid.NewGuid().ToString()) - }; + var claims = new List { new Claim(AuthConstants.JwtClaimTypes.Subject, self.ITCode) }; if (!string.IsNullOrEmpty(self.Name)) { diff --git a/src/WalkingTec.Mvvm.Mvc/GeneratorFiles/Mvc/Controller.txt b/src/WalkingTec.Mvvm.Mvc/GeneratorFiles/Mvc/Controller.txt index 1be2795..6bdd2a8 100644 --- a/src/WalkingTec.Mvvm.Mvc/GeneratorFiles/Mvc/Controller.txt +++ b/src/WalkingTec.Mvvm.Mvc/GeneratorFiles/Mvc/Controller.txt @@ -12,11 +12,11 @@ namespace $namespace$ [ActionDescription("$des$")] public partial class $modelname$Controller : BaseController { - private readonly IUnitWork _unitWork; + private readonly IUnitWork _unitwork; - public $modelname$Controller(IUnitWork unitWork) + public $modelname$Controller(IUnitWork unitwork) { - _unitWork = unitWork; + _unitwork = unitwork; } #region Search diff --git a/version.props b/version.props index a044000..8b097df 100644 --- a/version.props +++ b/version.props @@ -1,6 +1,6 @@ - 6.4.0 + 6.3.7