|
@@ -152,6 +152,107 @@ namespace OASystem.API.Controllers
|
|
|
return Ok(JsonView(view));
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ [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);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ 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);
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ 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 JwtHelper.IssueJwtAsync(new TokenModelJwt() { UserId = uId, UserName = uName, Role = role });
|
|
|
+ TimeSpan ts = view.Expires.AddMinutes(-1) - createZebraTime;
|
|
|
+ await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync<string>(authorId, view.Token, ts);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ #region 测试添加系统消息
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ return Ok(JsonView(view));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|