/// <summary> /// 修改用户密码 /// </summary> public async Task ModifyPasswordAsync(ProfileModifyPasswordModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } string pwdHash = this.encryptService.PasswordHash(model.NewPassword); PersonView person = await this.GetCurrentPersonViewAsync(); using (var work = this.dbFactory.StartWork()) { if (person.Password != this.encryptService.PasswordHash(model.Password)) { throw new ModelException(nameof(model.Password), "登录密码错误"); } using (var trans = work.BeginTransaction()) { try { await work.Person.ModifyPasswordAsync(person.Id, pwdHash, trans); await work.Person.UpdateLastTimeAsync(person.Id, trans); trans.Commit(); } catch { trans.Rollback(); throw; } } } }
public async Task <IActionResult> ModifyPassword(ProfileModifyPasswordModel model) { if (ModelState.IsValid) { string code = HttpContext.Session.GetVerifyCode(); if (code.ToLower() == model.Code.ToLower()) { try { await personService.ModifyPasswordAsync(model); return(this.Json(AjaxResult.CreateDefaultSuccess())); } catch (ModelException ex) { return(this.Json(ex.ToAjaxResult())); } catch (Exception ex) { return(this.Json(AjaxResult.CreateByMessage(ex.Message, false))); } } else { await HttpContext.Session.RefreshVerifyCodeAsync(); AjaxResult result = new AjaxResult(); result.Success = false; result.ErrorMessages.Add(nameof(model.Code), "验证码不正确,请重新输入"); return(this.Json(result)); } } else { return(this.Json(ModelState.ToAjaxResult())); } }
public IActionResult ModifyPassword() { ProfileModifyPasswordModel model = new ProfileModifyPasswordModel(); return(View(model)); }