public ActionResult EditCurrentUserPassword(string newPassword, string Password) { var resultModel = new RespResultCountViewModel(); try { if (string.IsNullOrEmpty(newPassword) || string.IsNullOrEmpty(Password)) { resultModel.code = -1; resultModel.msg = "修改失败,缺少密码"; resultModel.data = null; return(Ok(resultModel)); } var user = _userService.IsExistByUserName(User.GetCurrentUserName()); if (user == null) { resultModel.code = -1; resultModel.msg = "修改失败,用户不存在"; resultModel.data = null; return(Ok(resultModel)); } if (!AccountAuthHelper.VerifyPassword(Password, user.SecretKey, user.Password)) { resultModel.code = -1; resultModel.msg = "当前密码输入错误!"; resultModel.data = null; return(Ok(resultModel)); } UserEntity userEntity = new UserEntity(); userEntity.ModifyDate = DateTime.Now; userEntity.ModifyUserId = User.GetCurrentUserId(); userEntity.ModifyUserName = User.GetCurrentUserName(); bool result = _userService.RevisePassword(User.GetCurrentUserId(), newPassword); if (result) { resultModel.code = 0; resultModel.msg = "修改成功"; } else { resultModel.code = -1; resultModel.msg = "修改失败"; } return(Ok(resultModel)); } catch (Exception ex) { resultModel.code = -1; resultModel.msg = "操作失败:" + ex.ToString(); return(Ok(resultModel)); } }
public IActionResult LoginCheck(LoginViewModel loginViewModel) { var result = new RespLoginViewModel(); #region 非空验证 if (string.IsNullOrEmpty(loginViewModel.username)) { result.code = -1; result.msg = "用户名不能为空!"; return(new JsonResult(result)); } if (string.IsNullOrEmpty(loginViewModel.password)) { result.code = -1; result.msg = "密码不能为空!"; return(new JsonResult(result)); } #endregion try { #region 用户名和密码验证 var user = _authorizeService.CheckLogin(loginViewModel.username); if (user != null) { if (AccountAuthHelper.VerifyPassword(loginViewModel.password, user.SecretKey, user.Password)) { if (user.UserName == DataDictConst.USER_SUPERADMIN) { user.IsAdmin = 1; } result.code = 0; result.msg = "登录验证成功"; } else { result.code = -1; result.msg = "密码和用户名不匹配!"; return(new JsonResult(result)); } } else { result.code = -1; result.msg = "用户名不存在!"; return(new JsonResult(result)); } #endregion #region 策略授权 var ip = HttpContext.Features.Get <Microsoft.AspNetCore.Http.Features.IHttpConnectionFeature>()?.RemoteIpAddress?.ToString();//获取IP地址 var claims = new Claim[] { new Claim(ClaimTypes.Name, user.UserName), new Claim(ClaimTypes.NameIdentifier, user.UserId), new Claim("OrganizeId", user.OrganizeId), new Claim("OrganizeName", user.OrganizeName), new Claim("DepId", user.DepId), new Claim("DepName", user.DepName), new Claim("RealName", user.RealName), new Claim("RoleName", _authorizeService.GetRoleName(user.UserId)), new Claim("IsAdmin", user.IsAdmin.ToString()) }; //生成token //var token = _tokenBuilder.BuildJwtToken(claims, ip, DateTime.UtcNow, DateTime.Now.AddSeconds(Convert.ToInt32(_audienceModel.expiration))); var token = _tokenBuilder.BuildJwtToken(claims, ip, DateTime.UtcNow, DateTime.Now.AddSeconds(1008000)); if (token != null) { result.data = token; result.RoleName = _authorizeService.GetRoleName(user.UserId); } else { result.code = -1; result.msg = "生成token出错!"; } #endregion } catch (Exception ex) { result.code = -1; result.msg = "异常错误!" + ex.Message; } return(new JsonResult(result)); }