⚡强退功能优化
This commit is contained in:
parent
4d914ead0e
commit
ab98cf30c1
@ -16,7 +16,7 @@ namespace ZR.Admin.WebApi.Controllers.System
|
|||||||
[ApiExplorerSettings(GroupName = "sys")]
|
[ApiExplorerSettings(GroupName = "sys")]
|
||||||
public class SysLoginController : BaseController
|
public class SysLoginController : BaseController
|
||||||
{
|
{
|
||||||
static readonly NLog.Logger logger = NLog.LogManager.GetLogger("LoginController");
|
//static readonly NLog.Logger logger = NLog.LogManager.GetLogger("LoginController");
|
||||||
private readonly IHttpContextAccessor httpContextAccessor;
|
private readonly IHttpContextAccessor httpContextAccessor;
|
||||||
private readonly ISysUserService sysUserService;
|
private readonly ISysUserService sysUserService;
|
||||||
private readonly ISysMenuService sysMenuService;
|
private readonly ISysMenuService sysMenuService;
|
||||||
@ -68,14 +68,7 @@ namespace ZR.Admin.WebApi.Controllers.System
|
|||||||
return ToResponse(ResultCode.CAPTCHA_ERROR, "验证码错误");
|
return ToResponse(ResultCode.CAPTCHA_ERROR, "验证码错误");
|
||||||
}
|
}
|
||||||
|
|
||||||
var lockTimeStamp = CacheService.GetLockUser(loginBody.ClientId + loginBody.Username);
|
sysLoginService.CheckLockUser(loginBody.Username);
|
||||||
var lockTime = DateTimeHelper.ToLocalTimeDateBySeconds(lockTimeStamp);
|
|
||||||
var ts = lockTime - DateTime.Now;
|
|
||||||
|
|
||||||
if (lockTimeStamp > 0 && ts.TotalSeconds > 0)
|
|
||||||
{
|
|
||||||
return ToResponse(ResultCode.LOGIN_ERROR, $"你的账号已被锁,剩余{Math.Round(ts.TotalMinutes, 0)}分钟");
|
|
||||||
}
|
|
||||||
string location = HttpContextExtension.GetIpInfo(loginBody.LoginIP);
|
string location = HttpContextExtension.GetIpInfo(loginBody.LoginIP);
|
||||||
var user = sysLoginService.Login(loginBody, new SysLogininfor() { LoginLocation = location });
|
var user = sysLoginService.Login(loginBody, new SysLogininfor() { LoginLocation = location });
|
||||||
|
|
||||||
@ -252,15 +245,9 @@ namespace ZR.Admin.WebApi.Controllers.System
|
|||||||
{
|
{
|
||||||
if (dto == null) { return ToResponse(ResultCode.CUSTOM_ERROR, "扫码失败"); }
|
if (dto == null) { return ToResponse(ResultCode.CUSTOM_ERROR, "扫码失败"); }
|
||||||
var name = App.HttpContext.GetName();
|
var name = App.HttpContext.GetName();
|
||||||
var lockTimeStamp = CacheService.GetLockUser(dto.DeviceId + name);
|
|
||||||
var lockTime = DateTimeHelper.ToLocalTimeDateBySeconds(lockTimeStamp);
|
|
||||||
var ts = lockTime - DateTime.Now;
|
|
||||||
|
|
||||||
if (lockTimeStamp > 0 && ts.TotalSeconds > 0)
|
sysLoginService.CheckLockUser(name);
|
||||||
{
|
|
||||||
return ToResponse(ResultCode.LOGIN_ERROR, $"当前设备已被锁,剩余{Math.Round(ts.TotalMinutes, 0)}分钟");
|
|
||||||
}
|
|
||||||
//var token = HttpContextExtension.GetToken(HttpContext);
|
|
||||||
TokenModel tokenModel = JwtUtil.GetLoginUser(HttpContext);
|
TokenModel tokenModel = JwtUtil.GetLoginUser(HttpContext);
|
||||||
if (CacheService.GetScanLogin(dto.Uuid) is not null)
|
if (CacheService.GetScanLogin(dto.Uuid) is not null)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -4,7 +4,6 @@ using ZR.Admin.WebApi.Filters;
|
|||||||
using ZR.Admin.WebApi.Hubs;
|
using ZR.Admin.WebApi.Hubs;
|
||||||
using ZR.Model;
|
using ZR.Model;
|
||||||
using ZR.Model.System.Dto;
|
using ZR.Model.System.Dto;
|
||||||
using ZR.Service.System;
|
|
||||||
|
|
||||||
namespace ZR.Admin.WebApi.Controllers.monitor
|
namespace ZR.Admin.WebApi.Controllers.monitor
|
||||||
{
|
{
|
||||||
@ -37,36 +36,37 @@ namespace ZR.Admin.WebApi.Controllers.monitor
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 单条强退
|
/// 单个强退
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpDelete("lock")]
|
[HttpDelete("force")]
|
||||||
[Log(Title = "强退", BusinessType = BusinessType.FORCE)]
|
[Log(Title = "强退", BusinessType = BusinessType.FORCE)]
|
||||||
[ActionPermissionFilter(Permission = "monitor:online:forceLogout")]
|
[ActionPermissionFilter(Permission = "monitor:online:forceLogout")]
|
||||||
public async Task<IActionResult> Lock([FromBody] LockUserDto dto)
|
public async Task<IActionResult> Force([FromBody] LockUserDto dto)
|
||||||
{
|
{
|
||||||
if (dto == null) { return ToResponse(ResultCode.PARAM_ERROR); }
|
if (dto == null) { return ToResponse(ResultCode.PARAM_ERROR); }
|
||||||
|
|
||||||
await HubContext.Clients.Client(dto.ConnnectionId).SendAsync(HubsConstant.LockUser, new { dto.Reason, dto.Time });
|
await HubContext.Clients.Client(dto.ConnnectionId)
|
||||||
|
.SendAsync(HubsConstant.ForceUser, new { dto.Reason, dto.Time });
|
||||||
|
|
||||||
var expirTime = DateTimeHelper.GetUnixTimeSeconds(DateTime.Now.AddMinutes(dto.Time));
|
//var expirTime = DateTimeHelper.GetUnixTimeSeconds(DateTime.Now.AddMinutes(dto.Time));
|
||||||
//PC 端采用设备 + 用户名的方式进行封锁
|
////PC 端采用设备 + 用户名的方式进行封锁
|
||||||
CacheService.SetLockUser(dto.ClientId + dto.Name, expirTime, dto.Time);
|
//CacheService.SetLockUser(dto.ClientId + dto.Name, expirTime, dto.Time);
|
||||||
return SUCCESS(new { expirTime });
|
return SUCCESS(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 批量强退
|
/// 批量强退
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpDelete("batchlock")]
|
[HttpDelete("batchForce")]
|
||||||
[Log(Title = "强退", BusinessType = BusinessType.FORCE)]
|
[Log(Title = "强退", BusinessType = BusinessType.FORCE)]
|
||||||
[ActionPermissionFilter(Permission = "monitor:online:batchLogout")]
|
[ActionPermissionFilter(Permission = "monitor:online:batchLogout")]
|
||||||
public async Task<IActionResult> BatchLock([FromBody] LockUserDto dto)
|
public async Task<IActionResult> BatchforceLogout([FromBody] LockUserDto dto)
|
||||||
{
|
{
|
||||||
if (dto == null) { return ToResponse(ResultCode.PARAM_ERROR); }
|
if (dto == null) { return ToResponse(ResultCode.PARAM_ERROR); }
|
||||||
|
|
||||||
await HubContext.Clients.All.SendAsync(HubsConstant.LockUser, new { dto.Reason, dto.Time });
|
await HubContext.Clients.All.SendAsync(HubsConstant.ForceUser, new { dto.Reason });
|
||||||
|
|
||||||
return SUCCESS(1);
|
return SUCCESS(1);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
public static string MoreNotice = "moreNotice";
|
public static string MoreNotice = "moreNotice";
|
||||||
public static string OnlineUser = "onlineUser";
|
public static string OnlineUser = "onlineUser";
|
||||||
public static string LockUser = "lockUser";
|
public static string LockUser = "lockUser";
|
||||||
|
public static string ForceUser = "forceUser";
|
||||||
public static string ConnId = "connId";
|
public static string ConnId = "connId";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
using ZR.Model;
|
using Infrastructure;
|
||||||
|
using System;
|
||||||
|
using ZR.Model;
|
||||||
using ZR.Model.System;
|
using ZR.Model.System;
|
||||||
using ZR.Model.System.Dto;
|
using ZR.Model.System.Dto;
|
||||||
|
|
||||||
@ -40,5 +42,7 @@ namespace ZR.Service.System.IService
|
|||||||
/// <param name="ids"></param>
|
/// <param name="ids"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public int DeleteLogininforByIds(long[] ids);
|
public int DeleteLogininforByIds(long[] ids);
|
||||||
|
|
||||||
|
void CheckLockUser(string userName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -121,5 +121,18 @@ namespace ZR.Service.System
|
|||||||
{
|
{
|
||||||
return Delete(ids);
|
return Delete(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void CheckLockUser(string userName)
|
||||||
|
{
|
||||||
|
var lockTimeStamp = CacheService.GetLockUser(userName);
|
||||||
|
var lockTime = DateTimeHelper.ToLocalTimeDateBySeconds(lockTimeStamp);
|
||||||
|
var ts = lockTime - DateTime.Now;
|
||||||
|
|
||||||
|
if (lockTimeStamp > 0 && ts.TotalSeconds > 0)
|
||||||
|
{
|
||||||
|
throw new CustomException(ResultCode.LOGIN_ERROR, $"你的账号已被锁,剩余{Math.Round(ts.TotalMinutes, 0)}分钟");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user