用户在线管理,一个账号只准在一台设备上登陆,其他设备登陆后,此设备自动退出。

This commit is contained in:
zhougf committed 2024-07-08 15:58:37 +08:00
1 parent 12e16e0c6c
commit 209e88a905
9 files changed
+182 -15

No files matched your search

+13
View File
@@ -4,6 +4,8 @@ using System.Linq;
using System.Reflection;
using System.Text;
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;
@@ -153,6 +155,17 @@ 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()
//{
+18 -1
View File
@@ -14,6 +14,7 @@ using WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkUserVms;
using HHWMS.Web.ViewModels.HomeVMs;
using System.Collections.Generic;
using System.Linq;
using HHWMS.Web.Support;
namespace HHWMS.Web.Controllers
{
@@ -48,13 +49,19 @@ namespace HHWMS.Web.Controllers
}
}*/
var user = Wtm.DoLogin(vm.ITCode, vm.Password, vm.Tenant);
if (user == null)
if (user == null)
{
vm.MSD.AddModelError("", Localizer["Sys.LoginFailed"]);
return View(vm);
}
else
{
var signined = UserSessionManager.IsUserSignined(user.Name);
if (signined)
{
// 踢人下线
await KickUser(user.Name);
}
//其他属性可以通过user.Attributes["aaa"] = "bbb"方式赋值
Wtm.LoginUserInfo = user;
string url = string.Empty;
@@ -77,7 +84,9 @@ 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));
}
}
@@ -133,6 +142,14 @@ namespace HHWMS.Web.Controllers
}
}
[AllRights]
public async Task<IActionResult> KickUser(string ITcode)
{
UserSessionManager.KickUser(ITcode);
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
return Ok();
}
[AllRights]
[ActionDescription("ChangePassword")]
public ActionResult ChangePassword()