|
@@ -152,6 +152,107 @@ namespace OASystem.API.Controllers
|
|
|
return Ok(JsonView(view));
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 移动端用户登录
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [Route("MobileLogin")]
|
|
|
+ [HttpPost]
|
|
|
+ [ProducesResponseType(typeof(LoginView), StatusCodes.Status200OK)]
|
|
|
+ public async Task<IActionResult> MobileLoginAsync(LoginDto dto)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrWhiteSpace(dto.Number) || string.IsNullOrWhiteSpace(dto.Password))
|
|
|
+ {
|
|
|
+ return Ok(JsonView(false, "账号或密码不能为空!!"));
|
|
|
+ }
|
|
|
+
|
|
|
+ #region 校验用户信息
|
|
|
+ var userData = _loginRep.Login(dto).Result;
|
|
|
+ if (userData.Code != 0) return Ok(JsonView(false, userData.Msg));
|
|
|
+
|
|
|
+ #endregion
|
|
|
+ Result authData = null;
|
|
|
+ string uName = string.Empty;
|
|
|
+ string role = string.Empty;
|
|
|
+ int uId = 0;
|
|
|
+ int unReadCount = 0;
|
|
|
+ int announcementUnReadCount = 0;
|
|
|
+ if (userData.Data != null)
|
|
|
+ {
|
|
|
+ uId = (userData.Data as UserLoginInfoView).UserId;
|
|
|
+ uName = (userData.Data as UserLoginInfoView).CnName;
|
|
|
+ role = (userData.Data as UserLoginInfoView).JobName;
|
|
|
+ authData = _SystemMenuPermissionRepository.MobileMenuLoad(uId, dto.PortType);
|
|
|
+ unReadCount = await _messageRep.GetUnReadCount(uId);
|
|
|
+ announcementUnReadCount = await _messageRep.GetAnnouncementUnReadCount(uId);
|
|
|
+ }
|
|
|
+
|
|
|
+ //_hubContext.Login(uId, uName);
|
|
|
+ var view = new LoginView
|
|
|
+ {
|
|
|
+ UserInfo = userData == null ? null : userData.Data,
|
|
|
+ AuthData = authData == null ? null : authData.Data,
|
|
|
+ UnReadCount = unReadCount,
|
|
|
+ AnnouncementUnReadCount = announcementUnReadCount
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+ DateTime createZebraTime = DateTime.Now;
|
|
|
+ string authorId = dto.Number + "Token";
|
|
|
+ string authorToken = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>(authorId);//string 取
|
|
|
+ if (authorToken != null)
|
|
|
+ {
|
|
|
+ #region 解析出过期时间
|
|
|
+ var jwtHandler = new JwtSecurityTokenHandler();
|
|
|
+ JwtSecurityToken securityToken = jwtHandler.ReadJwtToken(authorToken);
|
|
|
+ DateTime expDt = (securityToken.Payload[JwtRegisteredClaimNames.Exp] ?? 0).GetInt().GetTimeSpmpToDate();
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ if (expDt >= createZebraTime) //超时重新获取token
|
|
|
+ {
|
|
|
+ authorToken = await JwtHelper.IssueJwtAsync(new TokenModelJwt() { UserId = uId, UserName = uName, Role = role }); //
|
|
|
+ }
|
|
|
+
|
|
|
+ view.Expires = expDt;
|
|
|
+ view.Token = authorToken;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ view.Expires = createZebraTime.AddMinutes(30);
|
|
|
+ //view.Token = await GeneralMethod.GetToken(_config, dto.Number, uId, uName, createZebraTime); //JwtHelper
|
|
|
+ view.Token = await JwtHelper.IssueJwtAsync(new TokenModelJwt() { UserId = uId, UserName = uName, Role = role }); //
|
|
|
+ TimeSpan ts = view.Expires.AddMinutes(-1) - createZebraTime; //设置redis 过期时间 比 jwt 时间 快一分钟
|
|
|
+ await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync<string>(authorId, view.Token, ts);//string 存
|
|
|
+ }
|
|
|
+
|
|
|
+ //#region 添加登录用户上线信息
|
|
|
+ //_hubContext.SignalRLogin(uId);
|
|
|
+ //#endregion
|
|
|
+
|
|
|
+ #region 测试添加系统消息
|
|
|
+
|
|
|
+ //await _message.AddMsg(new MessageDto()
|
|
|
+ //{
|
|
|
+ // Type = 1,
|
|
|
+ // IssuerId = 208,
|
|
|
+ // Title = "测试添加消息标题",
|
|
|
+ // Content = "消息体测试",
|
|
|
+ // ReleaseTime = DateTime.Now,
|
|
|
+ // UIdList = new List<int> {
|
|
|
+ // 5,
|
|
|
+ // 208,
|
|
|
+ // 219
|
|
|
+ // }
|
|
|
+ //});
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ return Ok(JsonView(view));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 申请注册 数据Data
|
|
|
/// </summary>
|