public async Task <string> RetrievePassword(PassWordInput input) { if (input.Account.IsNullOrEmpty()) { throw new LotteryDataException("账号不允许为空"); } if (input.Password.IsNullOrEmpty()) { throw new LotteryDataException("密码不允许为空"); } var accountBase = await _userManager.GetAccountBaseInfo(input.Account); var encryptNewPwd = EncryptPassword(accountBase.Account, input.Password, accountBase.AccountRegistType); await SendCommandAsync(new UpdatePasswordCommand(accountBase.Id, encryptNewPwd, accountBase.Id)); return("修改密码成功"); }
public async Task <IActionResult> UpdatePassWord([FromBody] PassWordInput input) { var claimsIdentity = User.Identity as ClaimsIdentity; int id = Convert.ToInt32(claimsIdentity.Claims.FirstOrDefault(c => c.Type == "userId").Value); User user = await dbContext.Users.FirstOrDefaultAsync(u => u.Id == id); if (user == null) { return(NotFound(Json(new { Error = "该用户不存在" }))); } if (!user.PassWord.Equals(Encrypt.Md5Encrypt(input.OldPassWord))) { return(BadRequest(Json(new { Error = "原密码错误" }))); } user.PassWord = Encrypt.Md5Encrypt(input.NewPassWord); dbContext.Update(user); await dbContext.SaveChangesAsync(); return(new NoContentResult()); }