From 55733f07e89f9eef25f33b6652c5b4712e957efe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Sat, 26 Aug 2023 16:39:31 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=E4=BC=98=E5=8C=96=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Infrastructure/Extensions/HttpContextExtension.cs | 2 +- .../Controllers/System/SysLoginController.cs | 10 +++++++++- .../System/monitor/SysUserOnlineController.cs | 4 ++-- ZR.Admin.WebApi/Framework/JwtUtil.cs | 5 +---- ZR.Admin.WebApi/Hubs/MessageHub.cs | 1 - ZR.Model/System/Dto/LockUserDto.cs | 1 + 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Infrastructure/Extensions/HttpContextExtension.cs b/Infrastructure/Extensions/HttpContextExtension.cs index 6b92670..28bf657 100644 --- a/Infrastructure/Extensions/HttpContextExtension.cs +++ b/Infrastructure/Extensions/HttpContextExtension.cs @@ -52,7 +52,7 @@ namespace Infrastructure.Extensions if (result.Contains("::1")) result = "127.0.0.1"; - result = result.Replace("::ffff:", "127.0.0.1"); + result = result.Replace("::ffff:", ""); result = result.Split(':')?.FirstOrDefault() ?? "127.0.0.1"; result = IsIP(result) ? result : "127.0.0.1"; return result; diff --git a/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs b/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs index 6105e69..bb52ce6 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs @@ -74,7 +74,7 @@ namespace ZR.Admin.WebApi.Controllers.System return ToResponse(ResultCode.CAPTCHA_ERROR, "验证码错误"); } - var lockTimeStamp = CacheService.GetLockUser(loginBody.ClientId); + var lockTimeStamp = CacheService.GetLockUser(loginBody.ClientId + loginBody.Username); var lockTime = DateTimeHelper.ToLocalTimeDateBySeconds(lockTimeStamp); var ts = lockTime - DateTime.Now; @@ -278,7 +278,15 @@ namespace ZR.Admin.WebApi.Controllers.System public IActionResult ScanLogin([FromBody] ScanDto dto) { if (dto == null) { return ToResponse(ResultCode.CUSTOM_ERROR, "扫码失败"); } + 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) + { + return ToResponse(ResultCode.LOGIN_ERROR, $"当前设备已被锁,剩余{Math.Round(ts.TotalMinutes, 0)}分钟"); + } var token = HttpContextExtension.GetToken(HttpContext); if (CacheService.GetScanLogin(dto.Uuid) is not null) { diff --git a/ZR.Admin.WebApi/Controllers/System/monitor/SysUserOnlineController.cs b/ZR.Admin.WebApi/Controllers/System/monitor/SysUserOnlineController.cs index 7501236..b51eba2 100644 --- a/ZR.Admin.WebApi/Controllers/System/monitor/SysUserOnlineController.cs +++ b/ZR.Admin.WebApi/Controllers/System/monitor/SysUserOnlineController.cs @@ -50,8 +50,8 @@ namespace ZR.Admin.WebApi.Controllers.monitor await HubContext.Clients.Client(dto.ConnnectionId).SendAsync(HubsConstant.LockUser, new { dto.Reason, dto.Time }); var expirTime = DateTimeHelper.GetUnixTimeSeconds(DateTime.Now.AddMinutes(dto.Time)); - - CacheService.SetLockUser(dto.ClientId, expirTime, dto.Time); + //PC 端采用设备 + 用户名的方式进行封锁 + CacheService.SetLockUser(dto.ClientId + dto.Name, expirTime, dto.Time); return SUCCESS(new { expirTime }); } } diff --git a/ZR.Admin.WebApi/Framework/JwtUtil.cs b/ZR.Admin.WebApi/Framework/JwtUtil.cs index c6ef113..f1cb56f 100644 --- a/ZR.Admin.WebApi/Framework/JwtUtil.cs +++ b/ZR.Admin.WebApi/Framework/JwtUtil.cs @@ -1,11 +1,8 @@ -using Infrastructure; -using Infrastructure.Extensions; -using Microsoft.IdentityModel.Tokens; +using Microsoft.IdentityModel.Tokens; using Newtonsoft.Json; using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; using System.Text; -using ZR.Admin.WebApi.Extensions; using ZR.Model.System.Dto; using ZR.Service.System; diff --git a/ZR.Admin.WebApi/Hubs/MessageHub.cs b/ZR.Admin.WebApi/Hubs/MessageHub.cs index edef352..6e6069f 100644 --- a/ZR.Admin.WebApi/Hubs/MessageHub.cs +++ b/ZR.Admin.WebApi/Hubs/MessageHub.cs @@ -3,7 +3,6 @@ using IPTools.Core; using Microsoft.AspNetCore.SignalR; using System.Web; using UAParser; -using ZR.Admin.WebApi.Extensions; using ZR.Service.System.IService; namespace ZR.Admin.WebApi.Hubs diff --git a/ZR.Model/System/Dto/LockUserDto.cs b/ZR.Model/System/Dto/LockUserDto.cs index c1219f4..868f260 100644 --- a/ZR.Model/System/Dto/LockUserDto.cs +++ b/ZR.Model/System/Dto/LockUserDto.cs @@ -2,6 +2,7 @@ { public class LockUserDto { + public string Name { get; set; } public string ClientId { get; set; } public string ConnnectionId { get; set; } public string Reason { get; set; }