public async Task ChangePassword(ChangePasswordInput input) { await CheckPasswordComplexity(input.NewPassword); var user = await GetCurrentUserAsync(); CheckErrors(await UserManager.ChangePasswordAsync(user.Id, input.CurrentPassword, input.NewPassword)); }
public async Task ChangePassword(ChangePasswordInput input) { await UserManager.InitializeOptionsAsync(AbpSession.TenantId); var user = await GetCurrentUserAsync(); CheckErrors(await UserManager.ChangePasswordAsync(user, input.CurrentPassword, input.NewPassword)); }
public async Task ChangePassword(ChangePasswordInput input) { User currentUserAsync = await this.GetCurrentUserAsync(); IdentityResult identityResult = await this.UserManager.ChangePasswordAsync(currentUserAsync.Id, input.CurrentPassword, input.NewPassword); this.CheckErrors(identityResult); }
public ActionResult ChangePassword(ChangePasswordInput input) { if (!ModelState.IsValid) { return(View(input)); } service.ChangePassword(input.Id, input.Password); return(Json(new{ Login = service.Get(input.Id).Login })); }
public ActionResult ChangePassword(ChangePasswordInput input) { if (!ModelState.IsValid) { return(View(input)); } s.ChangePassword(input.Id, input.Password); return(Content("ok")); }
public ActionResult ChangePassword(ChangePasswordInput input) { if (!ModelState.IsValid) { return(View(input)); } s.ChangePassword(input.Id, input.Password); return(Json(new { input.Id })); }
public async Task <IActionResult> ChangePassword([FromBody] ChangePasswordInput input) { if (input.NewPassword != input.ConfirmNewPassword) { return(BadRequest(new { Message = "As senhas precisam ser iguais!" })); } var result = _handler.Handle(input); return(await ApiResponse(result)); }
public async Task ChangePassword(ChangePasswordInput input) { //await CheckPasswordComplexity(input.NewPassword); var user = await UserManager.GetUserByIdAsync(AbpSession.GetUserId()); //await UserManager.ChangePasswordAsync(user, input.CurrentPassword, input.NewPassword); CheckErrors(await UserManager.ChangePasswordAsync(user, input.CurrentPassword, input.NewPassword)); //CheckErrors(await _userManager.ChangePasswordAsync(user, input.User.Password)); }
/// <summary> /// 修改密码 /// </summary> /// <param name="input"></param> /// <param name="output"></param> /// <param name="errMsg"></param> /// <returns></returns> public bool ChangePassword(ChangePasswordInput input, ref ChangePasswordOutput output, ref string errMsg) { bool doChange = HttpCommonMethod <ChangePasswordInput, ChangePasswordOutput>("/antuser/user.resetPassword.do", GlobalVariable.RequestMethod.POST, input, ref output, ref errMsg); if (doChange && output.result == (int)GlobalVariable.Result.Failure) { errMsg = string.IsNullOrEmpty(output.errorCode) ? "修改密码失败" : resources.GetString("E_" + output.errorCode); return(false); } return(doChange); }
public async Task ChangePassword(ChangePasswordInput input) { var user = await _userManager.GetUserByIdAsync(AbpSession.UserId.Value); var result = await _userManager.ChangePasswordAsync(user, input.CurrentPassword, input.NewPassword); if (!result.Succeeded) { throw new AbpProjectNameBusinessException(ErrorCode.ChangePasswordFailed, string.Join(" ", result.Errors.Select(e => L(e.Code)))); } }
public void ChangePassword(ChangePasswordInput input) { var currentUser = _userRepository.Get(AbpUser.CurrentUserId.Value); if (currentUser.Password != input.CurrentPassword) { throw new UserFriendlyException("Current password is invalid!"); } currentUser.Password = input.NewPassword; currentUser.Password = new PasswordHasher().HashPassword(currentUser.Password); }
public async Task <IActionResult> SubmitChangePassword([FromBody] ChangePasswordInput input) { var userId = _userApp.GetCurrentUserId(); userId.CheckArgumentIsNull(nameof(userId)); var userEntity = await _userApp.FindUserAsync(userId); userEntity.CheckArgumentIsNull(nameof(userEntity)); var(succeeded, error) = await _userApp.ChangePasswordAsync(userEntity, input.OldUserPassword, input.UserPassword); return(succeeded ? Success("重置密码成功") : Error(error)); }
public void ChangePassword(ChangePasswordInput input) { Assert.IfNullOrWhiteSpaceThrow(input.Password1, "密码不能为空"); Assert.IfNullOrWhiteSpaceThrow(input.Password2, "密码不能为空"); Assert.IfTrueThrow(input.Password1 != input.Password2, "密码不一致"); var user = _userRepository.GetById(input.Id); Assert.IfNullThrow(user, "用户不存在"); user.Password = input.Password1.ToMD5(); _userRepository.Update(user); }
public async Task ChangePasswordFromAdmin(ChangePasswordInput input) { if (input.UserId == null) { throw new UserFriendlyException(L("UserNotFound")); } var user = await UserManager.GetUserByIdAsync(input.UserId.Value); var hasher = new PasswordHasher(); user.Password = hasher.HashPassword(input.NewPassword); user.ShouldChangePasswordOnLogin = true; await UserManager.UpdateAsync(user); }
/// <summary> /// 修改当前用户密码 /// </summary> /// <returns></returns> public async Task <bool> ChangePassword(ChangePasswordInput input) { var user = await _userManager.GetUserByIdAsync(GetSessionUserId()); // 检查密码是否正确 if (!await _userManager.CheckPasswordAsync(user, input.CurrentPassword)) { throw new UserFriendlyException("输入的当前密码错误"); } // 修改密码 var result = await _userManager.ChangePasswordAsync(user, input.NewPassword); return(result.Succeeded); }
public async Task ChangePassword(ChangePasswordInput input) { await CheckPasswordComplexity(input.NewPassword); var user = await GetCurrentUserAsync(); user.ShouldChangePasswordOnNextLogin = false; var loginAsync = await _logInManager.LoginAsync(user.UserName, input.CurrentPassword, shouldLockout : false); if (loginAsync.Result != AbpLoginResultType.Success) { throw new UserFriendlyException("原密码错误"); } user.Password = _passwordHasher.HashPassword(user, input.NewPassword); //CheckErrors(await UserManager.ChangePasswordAsync(user, input.CurrentPassword, input.NewPassword)); }
public async Task ChangePassword(ChangePasswordInput input) { var user = await UserManager.FindByIdAsync(AbpSession.UserId.Value); if (user == null) { throw new UserFriendlyException("用户不存在"); } if (!await UserManager.CheckPasswordAsync(user, input.Password)) { throw new UserFriendlyException("原密码错误"); } UserManager.RemovePassword(user.Id); UserManager.AddPassword(user.Id, input.NewPassword); }
public async Task ChangePassword(ChangePasswordInput input) { Debug.Assert(_abpSession.UserId != null, "_abpSession.UserId != null"); var userId = _abpSession.UserId.Value; var user = await _userManager.GetUserByIdAsync(userId); var loginAsync = await _logInManager.LoginAsync(user.UserName, input.CurrentPassword, shouldLockout : false); if (loginAsync.Result != AbpLoginResultType.Success) { throw new UserFriendlyException( "Your 'Existing Password' did not match the one on record. Please try again or contact an administrator for assistance in resetting your password."); } user.Password = _passwordHasher.HashPassword(user, input.NewPassword); }
public ICommandResult Handle(ChangePasswordInput input) { var user = _repository.FirstOrDefault(p => p.Username == input.Username); user.ResetPassword(input.NewPassword); var validator = new UserValidator().Validate(user); if (validator.IsValid) { _repository.Update(user); } _mailService.Send(user.Email.Address, "Senha resetada!", $"Sua nova senha é: {input.NewPassword}"); return(new CommandResult($"A senha de {user.Name} foi resetada com sucesso e enviada para o e-mail {user.Email}.", validator.Errors)); }
public async Task ChangePassword(ChangePasswordInput input) { await UserManager.InitializeOptionsAsync(AbpSession.TenantId); var user = await GetCurrentUserAsync(); if (await UserManager.CheckPasswordAsync(user, input.CurrentPassword)) { CheckErrors(await UserManager.ChangePasswordAsync(user, input.NewPassword)); } else { CheckErrors(IdentityResult.Failed(new IdentityError { Description = "Incorrect password." })); } }
public async Task <bool> ChangePassword([FromBody] ChangePasswordInput changePasswordInput) { if (!ModelState.IsValid) { return(false); } try { return(await this.userService.ChangePassword(changePasswordInput)); } catch (Exception exception) { Debug.Write($"An error occured: {exception.Message}"); return(false); } }
public virtual async Task ChangePasswordAsync(Guid id, ChangePasswordInput input) { var user = await UserManager.GetByIdAsync(id); if (user.IsExternal) { throw new BusinessException(code: Volo.Abp.Identity.IdentityErrorCodes.ExternalUserPasswordChange); } if (user.PasswordHash == null) { (await UserManager.AddPasswordAsync(user, input.NewPassword)).CheckErrors(); return; } (await UserManager.ChangePasswordAsync(user, input.CurrentPassword, input.NewPassword)).CheckErrors(); }
public async Task <ActionResult> ChangePassword([FromBody] ChangePasswordInput input) { if (input.NewPassword != input.PasswordRepeat) { return(BadRequest("Passwords are not matched!")); // TODO: Make these messages static object } var user = await _authenticationAppService.FindUserByUserNameAsync(User.Identity.Name); var result = await _authenticationAppService.ChangePasswordAsync(user, input.CurrentPassword, input.NewPassword); if (!result.Succeeded) { return(BadRequest(string.Join(Environment.NewLine, result.Errors.Select(e => e.Description)))); } return(Ok()); }
public async Task <IActionResult> ChangePassword(ChangePasswordInput input) { if (string.IsNullOrEmpty(input.Password)) { return(BadRequest(EmptyPasswordErrorMessage)); } var userExists = await this.userService.ExistsByIdAsync(input.UserId); if (!userExists) { return(BadRequest(UserNotExistsErrorMessage)); } await this.identityService.ChangePassword(input.UserId, input.Password); return(Ok("Password changed!")); }
public async Task ChangePassword(ChangePasswordInput input) { var user = await UserManager.GetUserByIdAsync(StudioXSession.GetUserId()); var hashedPassword = passwordHasher.HashPassword(user, input.Password); var verificationResult = passwordHasher.VerifyHashedPassword(user, hashedPassword, input.Password); if (verificationResult != PasswordVerificationResult.Success) { throw new UserFriendlyException("Current password must match old password!"); } var identityResult = await UserManager.ChangePasswordAsync(user, input.NewPassword); if (!identityResult.Succeeded) { throw new UserFriendlyException(identityResult.Errors.JoinAsString(", ")); } }
public async Task ChangePassword(ChangePasswordInput input) { if (AbpSession.UserName == "demo") { throw new UserFriendlyException("少年不要调皮,demo的密码不能修改。"); } if (AbpSession.UserName == "admin") { throw new UserFriendlyException("少年不要调皮,Admin的密码不能修改。"); } await CheckPasswordComplexity(input.NewPassword); var user = await GetCurrentUserAsync(); CheckErrors(await UserManager.ChangePasswordAsync(user.Id, input.CurrentPassword, input.NewPassword)); }
public async Task Execute(ChangePasswordInput input) { if (input == null) { outputPort.WriteError(""); return; } var user = await userRepository.Get(input.UserId); if (user == null) { outputPort.NotFound(""); return; } user.Password = passwordHasher.EncodePassword(input.NewPassword); bool success = await userRepository.Update(user); outputPort.Standart(new ChangePasswordOutput(success)); }
public virtual async Task ChangePasswordAsync(ChangePasswordInput input) { await IdentityOptions.SetAsync(); var currentUser = await UserManager.GetByIdAsync(CurrentUser.GetId()); if (currentUser.IsExternal) { throw new BusinessException(code: IdentityErrorCodes.ExternalUserPasswordChange); } if (currentUser.PasswordHash == null) { (await UserManager.AddPasswordAsync(currentUser, input.NewPassword)).CheckErrors(); return; } (await UserManager.ChangePasswordAsync(currentUser, input.CurrentPassword, input.NewPassword)).CheckErrors(); }
/// <summary> /// Reset user password /// </summary> /// <param name="changePasswordInput"></param> /// <returns></returns> public async Task <bool> ChangePassword(ChangePasswordInput changePasswordInput) { var user = await this.applicationDbContext.ApplicationUsers.FirstOrDefaultAsync( x => x.Username == changePasswordInput.Username); if (user == null) { return(false); } var passwordDetails = CreatePassword(changePasswordInput.Password); user.HashedPassword = passwordDetails.HashedPassword; user.Salt = passwordDetails.Salt; this.applicationDbContext.ApplicationUsers.Update(user); await this.applicationDbContext.SaveChangesAsync(); return(true); }
public async Task <ApiResult> ChangePassword([FromBody] ChangePasswordInput input) { ApiResult result = new ApiResult(); var user = await userManager.FindByNameAsync(session.Username); if (user != null) { var changeRs = await userManager.ChangePasswordAsync(user, input.CurrentPassword, input.NewPassword); result.success = changeRs.Succeeded; result.message = string.Join(',', changeRs.Errors.Select(x => x.Description)); } else { result.success = false; result.message = "用户不存在"; } return(result); }