完善扫码登录(生成新的token)

This commit is contained in:
不做码农 2023-08-30 07:50:06 +08:00
parent b67c59710b
commit 4d914ead0e

View File

@ -247,6 +247,7 @@ namespace ZR.Admin.WebApi.Controllers.System
/// <returns></returns> /// <returns></returns>
[HttpPost("/ScanLogin")] [HttpPost("/ScanLogin")]
[Log(Title = "扫码登录")] [Log(Title = "扫码登录")]
[Verify]
public IActionResult ScanLogin([FromBody] ScanDto dto) public IActionResult ScanLogin([FromBody] ScanDto dto)
{ {
if (dto == null) { return ToResponse(ResultCode.CUSTOM_ERROR, "扫码失败"); } if (dto == null) { return ToResponse(ResultCode.CUSTOM_ERROR, "扫码失败"); }
@ -259,14 +260,15 @@ namespace ZR.Admin.WebApi.Controllers.System
{ {
return ToResponse(ResultCode.LOGIN_ERROR, $"当前设备已被锁,剩余{Math.Round(ts.TotalMinutes, 0)}分钟"); return ToResponse(ResultCode.LOGIN_ERROR, $"当前设备已被锁,剩余{Math.Round(ts.TotalMinutes, 0)}分钟");
} }
var token = HttpContextExtension.GetToken(HttpContext); //var token = HttpContextExtension.GetToken(HttpContext);
TokenModel tokenModel = JwtUtil.GetLoginUser(HttpContext);
if (CacheService.GetScanLogin(dto.Uuid) is not null) if (CacheService.GetScanLogin(dto.Uuid) is not null)
{ {
Dictionary<string, object> dict = new() { }; Dictionary<string, object> dict = new() { };
dict.Add("status", "success"); dict.Add("status", "success");
dict.Add("token", token.Replace("Bearer ", "")); dict.Add("token", JwtUtil.GenerateJwtToken(JwtUtil.AddClaims(tokenModel)));
CacheService.SetScanLogin(dto.Uuid, dict); CacheService.SetScanLogin(dto.Uuid, dict);
//TODO 待优化应该生成新的token
return SUCCESS(1); return SUCCESS(1);
} }
return ToResponse(ResultCode.FAIL, "二维码已失效"); return ToResponse(ResultCode.FAIL, "二维码已失效");