public async Task <IActionResult> ResetPasswordPost([FromBody] ResetPasswordInput input) { if (!ModelState.IsValid) { return(Ok(ModelState)); } var user = await _userManager.FindByEmailAsync(input.Email); if (user == null) { // Don't reveal that the user does not exist return(Ok(new RedirectResponse() { Pathname = "/Account/ResetPasswordConfirmation" })); } var result = await _userManager.ResetPasswordAsync(user, input.Code, input.Password); if (result.Succeeded) { return(Ok(new RedirectResponse() { Pathname = "/Account/ResetPasswordConfirmation" })); } foreach (var error in result.Errors) { ModelState.AddModelError("ModelErrors", error.Description); } return(Ok(ModelState)); }
public async Task <string> ResetPassword(ResetPasswordInput input) { string RandomPassword = GlobalFunction.MakeRandomPassword(); var currentUser = await _userRepository.FirstOrDefaultAsync(w => w.UserName == input.UserName && w.EmailAddress == input.EmailAddress); if (currentUser != null) { if (!currentUser.IsActive) { throw new UserFriendlyException(L("UserIsNotActiveOrLocked")); } currentUser.Password = _passwordHasher.HashPassword(currentUser, RandomPassword); CurrentUnitOfWork.SaveChanges(); // Gửi mail cho User try { await _sendEmail.ResetPasswordEmail(input.EmailAddress, RandomPassword); } catch (Exception ex) { Logger.Error("Lỗi gửi mail reset mật khẩu", ex); throw new UserFriendlyException(L("SendEmailFailed"), ex.Message); } return(L("SendEmailSuccessfully")); } else { throw new UserFriendlyException(L("WrongUserNameOrEmail")); } }
public async Task Should_Reset_Password() { var testUser = await CreateAndGetTestUserAsync(); var token = await LoginAndGetTokenAsync(testUser.UserName, "123qwe"); var input = new ForgotPasswordInput { UserNameOrEmail = testUser.Email }; var requestMessage = new HttpRequestMessage(HttpMethod.Post, "/api/forgotPassword"); requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token); requestMessage.Content = input.ToStringContent(Encoding.UTF8, "application/json"); var response = await TestServer.CreateClient().SendAsync(requestMessage); var result = await response.Content.ReadAsAsync <ForgotPasswordOutput>(); var inputResetPassword = new ResetPasswordInput { UserNameOrEmail = testUser.Email, Token = result.ResetToken, Password = "******" }; var requestMessageResetPassword = new HttpRequestMessage(HttpMethod.Post, "/api/resetPassword"); requestMessageResetPassword.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token); requestMessageResetPassword.Content = inputResetPassword.ToStringContent(Encoding.UTF8, "application/json"); var responseResetPassword = await TestServer.CreateClient().SendAsync(requestMessageResetPassword); Assert.Equal(HttpStatusCode.OK, responseResetPassword.StatusCode); }
/// <summary> /// 重置密码 /// </summary> /// <param name="input"></param> /// <returns></returns> public ResetPasswordOutput ResetPassword(ResetPasswordInput input) { //重置密码 _userDomainService.ResetPassword(input.PhoneNumber, input.SmsVerificationCode, input.Password); return(new ResetPasswordOutput()); }
public async Task <ResetPasswordOutput> ResetPassword(ResetPasswordInput input) { var user = await UserManager.GetUserByIdAsync(input.UserId); if (user == null || user.PasswordResetCode.IsNullOrEmpty() || user.PasswordResetCode != input.ResetCode) { throw new UserFriendlyException(L("InvalidPasswordResetCode"), L("InvalidPasswordResetCode_Detail")); } user.Password = _passwordHasher.HashPassword(user, input.Password); user.PasswordResetCode = null; user.IsPhoneNumberConfirmed = true; user.ShouldChangePasswordOnNextLogin = false; await UserManager.UpdateAsync(user); var tokenResult = await CreateToken(user); return(new ResetPasswordOutput { AccessToken = tokenResult.AccessToken, ExpireInSeconds = tokenResult.ExpireInSeconds, UserId = tokenResult.UserId, PhoneNumber = tokenResult.Phone }); }
public async Task <bool> ResetPassword(ResetPasswordInput input) { var user = await _userRepository.GetAsync(input.Id); user.Password = "******"; return(true); }
public IActionResult ResetPassword(string code, string userEmail) { ResetPasswordInput model = new ResetPasswordInput { Token = code, Email = userEmail }; return(View(model)); }
/// <summary> /// 根据用户Id重置某人密码 /// </summary> /// <param name="input">输入参数</param> /// <returns></returns> public Task <bool> ResetPassword(ResetPasswordInput input) { const string sql = "UPDATE System_UserInfo SET Password=@password WHERE UserId=@userId"; return(SqlMapperUtil.InsertUpdateOrDeleteSqlBool <SystemUserInfo>(sql, new { userId = input.Id, password = input.EncryptPassword })); }
public async Task ResetAdminPassword(ResetPasswordInput input) { var user = await UserManager.FindByIdAsync(input.UserId); if (user == null) { throw new UserFriendlyException("用户不存在"); } UserManager.RemovePassword(user.Id); UserManager.AddPassword(user.Id, input.NewPassword); }
public async Task <string> ResetPassword(ResetPasswordInput input) { var userInfo = await _userRepository.SingleOrDefaultAsync(p => p.Id == input.Id); if (userInfo == null) { throw new BusinessException($"不存在Id为{input.Id}的账号信息"); } await _userDomainService.ResetPassword(userInfo, input.NewPassword); return("重置该员工密码成功"); }
public async Task ResetPassword(ResetPasswordInput input) { await ValidateCode(input.ValidateCode); var user = await UserManager.FindByIdAsync(AbpSession.UserId.Value); if (user == null) { throw new UserFriendlyException("用户不存在"); } UserManager.RemovePassword(user.Id); UserManager.AddPassword(user.Id, input.NewPassword); }
public async Task <JsonResult> ResetPasswordForm(ResetPasswordInput input) { var result = await _userManager.ResetPasswordAsync(input.UserId, input.Token, input.Password); if (result.Succeeded) { var url = Url.Action("Login", new { message = "PasswordChanged" }); return(Json(new AjaxResponse { TargetUrl = url })); } throw new UserFriendlyException(L("SessionExpired")); }
// Reset du password public IActionResult ResetPassword(string code = null) { if (code == null) { return(View("ResetPasswordFail")); } else { ResetPasswordInput test = new ResetPasswordInput { Code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code)) }; return(View("ResetPassword")); } }
/// <summary> /// 重置密码链接 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task ResetPassword(ResetPasswordInput input) { var customer = await _customerRepository.FirstOrDefaultAsync(c => c.Email.Equals(input.Email)); if (customer == null) { throw new UserFriendlyException("该邮箱绑定的账户不存在"); } var code = Guid.NewGuid().ToString().Split('-').Last(); customer.EmailCode = code; customer.CodeTime = DateTime.Now; var body = $@"<div>您的验证码:{code},请及时使用以防过期</div>"; await SendEmail(customer.Email, body); }
public async Task <ApiResult> ResetPassword(ResetPasswordInput input) { var user = await _userRepository.FirstOrDefaultAsync(input.UserId); if (user == null) { return(ApiResult.DataNotFound()); } string srtPassword = "******"; srtPassword = Encryptor.MD5Entry(srtPassword); user.Password = srtPassword; await _userRepository.UpdateAsync(user); return(new ApiResult().Success()); }
public ICommandResult Handle(ResetPasswordInput input) { var user = _repository.FirstOrDefault(p => p.Email.Address == input.Email); var password = StringHelper.GeneratePassword(); user.ResetPassword(password); var validator = new UserValidator().Validate(user); if (validator.IsValid) { _repository.Update(user); } _mailService.Send(user.Email.Address, "Senha resetada!", $"Sua nova senha é: {password}"); 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 <ActionResult> ResetPassword([FromBody] ResetPasswordInput input) { var user = await _authenticationAppService.FindUserByUserNameOrEmailAsync(input.UserNameOrEmail); if (user == null) { return(NotFound("User is not found!")); // TODO: Make these messages static object } var result = await _authenticationAppService.ResetPasswordAsync(user, input.Token, input.Password); if (!result.Succeeded) { return(BadRequest(string.Join(Environment.NewLine, result.Errors.Select(e => e.Description)))); } return(Ok()); }
public void ResetPassword(ResetPasswordInput input) { var user = _userRepository.Get(input.UserId); if (string.IsNullOrWhiteSpace(user.PasswordResetCode)) { throw new UserFriendlyException("You can not reset your password. You must first send a reset password link to your email."); } if (input.PasswordResetCode != user.PasswordResetCode) { throw new UserFriendlyException("Password reset code is invalid!"); } user.Password = input.Password; user.PasswordResetCode = null; }
public virtual async Task ResetPassword(ResetPasswordInput input) { unitOfWorkManager.Current.SetTenantId(input.TenantId); var user = await userManager.GetUserByIdAsync(input.UserId); if (user == null || user.PasswordResetCode.IsNullOrEmpty() || user.PasswordResetCode != input.ResetCode) { throw new UserFriendlyException("InvalidPasswordResetCode", "InvalidPasswordResetCode_Detail"); } user.Password = new PasswordHasher().HashPassword(input.Password); user.PasswordResetCode = null; user.IsEmailConfirmed = true; await userManager.UpdateAsync(user); }
public Task <IActionResult> UpdatePassword(string uuid, ResetPasswordInput input) { return(Task.Run <IActionResult>(() => { if (!ModelState.IsValid) { return BadRequest(); } if (!UserController.ValidatePassword(input.Password)) { return BadRequest(new { Message = "Password not valid" }); } var resetPassword = _db.Where <ResetPassword>(r => r.Uuid == uuid).First(); if (resetPassword == null) { return BadRequest(); } if (resetPassword.Used) { return BadRequest(); } _db.Update <ResetPassword>(resetPassword.Id, new Dictionary <string, object> { { "Used", true } }); var hashedNewPassword = BCrypt.Net.BCrypt.HashPassword(input.Password); _db.Update <User>(resetPassword.UserId, new Dictionary <string, object> { { "Password", hashedNewPassword } }); return Ok(new { }); })); }
public ResetPasswordOutput ResetPassword(ResetPasswordInput input) { try { RestHTTP http = new RestHTTP(); RestRequest req = new RestRequest("api/accounts/ResetPassword", RestSharp.Method.POST); req.AddHeader("Content-Type", "application/json"); req.AddJsonBody(input); ResetPasswordOutput response = http.HttpPost <ResetPasswordOutput>(req); return(response); } catch (Exception ex) { WriteLogFile.Append("ResetPassword : "); WriteLogFile.Append(ex.Message); WriteLogFile.Append(ex.StackTrace); } return(null); }
/// <summary> /// 用户名修改密码 /// </summary> public async Task <ResetPasswordOutput> UserResetPassword(ResetPasswordInput input) { var user = await UserManager.FindByNameAsync(input.UserName); //if (user == null || user.PasswordResetCode.IsNullOrEmpty() || user.PasswordResetCode != input.ResetCode) //{ // throw new UserFriendlyException(L("InvalidPasswordResetCode"), L("InvalidPasswordResetCode_Detail")); //} user.Password = _passwordHasher.HashPassword(user, input.Password); user.PasswordResetCode = null; user.IsEmailConfirmed = true; await UserManager.UpdateAsync(user); return(new ResetPasswordOutput { CanLogin = user.IsActive, UserName = user.UserName }); }
public async Task <ActionResult> ResetPassword(ResetPasswordInput input) { var output = await _accountAppService.ResetPassword(input); if (output.CanLogin) { var user = await _userManager.GetUserByIdAsync(input.UserId); await _signInManager.SignInAsync(user, false); if (!string.IsNullOrEmpty(input.SingleSignIn) && input.SingleSignIn.Equals("true", StringComparison.OrdinalIgnoreCase)) { user.SetSignInToken(); var returnUrl = AddSingleSignInParametersToReturnUrl(input.ReturnUrl, user.SignInToken, user.Id, user.TenantId); return(Redirect(returnUrl)); } } return(Redirect(NormalizeReturnUrl(input.ReturnUrl))); }
public async Task <bool> ResetPassword(ResetPasswordInput input) { var user = await UserManager.GetUserByIdAsync(input.UserId); if (user == null || user.PasswordResetCode.IsNullOrEmpty() || user.PasswordResetCode != input.ResetCode) { throw new UserFriendlyException("Invalid password reset code"); } await UserManager.InitializeOptionsAsync(AbpSession.TenantId); CheckErrors(await UserManager.ChangePasswordAsync(user, input.Password)); user.PasswordResetCode = null; user.IsEmailConfirmed = true; await UserManager.UpdateAsync(user); return(true); }
public async Task SendPasswordResetCode_Test(string phone) { var input = new SendPasswordResetCodeInput() { PhoneNumber = phone }; await _usersAppService.SendPasswordResetCode(input); var user = UsingDbContext(context => context.Users.FirstOrDefault(p => p.PhoneNumber == phone)); var reseInput = new ResetPasswordInput() { UserId = user.Id, ResetCode = user.PasswordResetCode, Password = "******" }; var reseUser = await _usersAppService.ResetPassword(reseInput); reseUser.ShouldNotBeNull(); }
public async Task <ResetPasswordOutput> ResetPassword(ResetPasswordInput input) { var user = await UserManager.GetUserByIdAsync(input.UserId); if (user == null || user.PasswordResetCode.IsNullOrEmpty() || user.PasswordResetCode != input.ResetCode) { throw new UserFriendlyException(L("InvalidPasswordResetCode"), L("InvalidPasswordResetCode_Detail")); } user.Password = _passwordHasher.HashPassword(user, input.Password); user.PasswordResetCode = null; user.ShouldChangePasswordOnNextLogin = false; await UserManager.UpdateAsync(user); return(new ResetPasswordOutput { CanLogin = user.IsActive, UserName = user.UserName }); }
public async Task <ActionResult> ResetPassword([FromBody] ResetPasswordInput input) { var user = await FindUserByUserNameOrEmail(input.UserNameOrEmail); if (user == null) { return(NotFound(new List <NameValueDto> { new NameValueDto("UserNotFound", "User is not found!") })); } var result = await _userManager.ResetPasswordAsync(user, input.Token, input.Password); if (!result.Succeeded) { return(BadRequest(result.Errors.Select(e => new NameValueDto(e.Code, e.Description)).ToList())); } return(Ok()); }
public async Task <IActionResult> ResetPassword(ResetPasswordInput input) { if (!ModelState.IsValid) { return(View(input)); } var user = await _userManager.FindByEmailAsync(input.Email); if (user == null) { return(RedirectToAction(nameof(ResetPasswordConfirm))); } bool tokenIsValid = await _userManager.VerifyUserTokenAsync(user, _userManager.Options.Tokens.PasswordResetTokenProvider, "ResetPassword", input.Token); if (!tokenIsValid) { return(RedirectToAction(nameof(ResetPasswordConfirm))); } bool inputtedPasswordIsSameAsCurrent = await _userManager.CheckPasswordAsync(user, input.Password); if (inputtedPasswordIsSameAsCurrent) { ModelState.AddModelError("Previous Password", "Cannot use the previous password"); return(View(input)); } var resetPassResult = await _userManager.ResetPasswordAsync(user, input.Token, input.Password); if (!resetPassResult.Succeeded) { foreach (var error in resetPassResult.Errors) { ModelState.TryAddModelError(error.Code, error.Description); } return(View(input)); } return(RedirectToAction(nameof(ResetPasswordConfirm))); }
public JsonResult ResetPassword(ResetPasswordInput input) { var recaptchaHelper = this.GetRecaptchaVerificationHelper(); if (String.IsNullOrEmpty(recaptchaHelper.Response)) { throw new UserFriendlyException("Captcha answer cannot be empty."); } var recaptchaResult = recaptchaHelper.VerifyRecaptchaResponse(); if (recaptchaResult != RecaptchaVerificationResult.Success) { throw new UserFriendlyException("Incorrect captcha answer."); } _userAppService.ResetPassword(input); return(Json(new AbpMvcAjaxResponse { TargetUrl = Url.Action("Login") })); }
/// <summary> /// 重置密码 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <ResetPasswordOutput> ResetPasswordAsync(ResetPasswordInput input) { var user = await UserManager.GetUserByIdAsync(input.UserId); if (user == null || user.PasswordResetCode.IsNullOrEmpty() || user.PasswordResetCode != input.ResetCode) { throw new UserFriendlyException(L("InvalidPasswordResetCode"), L("InvalidPasswordResetCode_Detail")); } user.Password = _passwordHasher.HashPassword(user, input.Password); user.PasswordResetCode = null; user.IsEmailConfirmed = true; user.NeedToChangeThePassword = false; await UserManager.UpdateAsync(user); return(new ResetPasswordOutput { CanLogin = user.IsActive && !await UseCaptchaOnLogin(), UserName = user.UserName }); }