private void ThenMustHaveChangedPasswordForUserRefsOnce( string newPassword, IEnumerable <UserReference> expectedUserRefs ) { A.CallTo( () => passwordService.ChangePasswordAsync( A <IEnumerable <UserReference> > .That.IsSameSequenceAs(expectedUserRefs), newPassword ) ) .MustHaveHappened(1, Times.Exactly); }
public async Task <IActionResult> Index(ChangePasswordFormData formData, DlsSubApplication dlsSubApplication) { var adminId = User.GetAdminId(); var delegateId = User.GetCandidateId(); var verifiedLinkedUsersAccounts = string.IsNullOrEmpty(formData.CurrentPassword) ? new UserAccountSet() : userService.GetVerifiedLinkedUsersAccounts(adminId, delegateId, formData.CurrentPassword !); if (!verifiedLinkedUsersAccounts.Any()) { ModelState.AddModelError( nameof(ChangePasswordFormData.CurrentPassword), CommonValidationErrorMessages.IncorrectPassword ); } if (!ModelState.IsValid) { var model = new ChangePasswordViewModel(formData, dlsSubApplication); return(View(model)); } var newPassword = formData.Password !; await passwordService.ChangePasswordAsync(verifiedLinkedUsersAccounts.GetUserRefs(), newPassword); return(View("Success", dlsSubApplication)); }
public async Task <IActionResult> Index(ConfirmPasswordViewModel viewModel) { var resetPasswordData = TempData.Peek <ResetPasswordData>() !; var hashIsValid = await passwordResetService.EmailAndResetPasswordHashAreValidAsync( resetPasswordData.Email, resetPasswordData.ResetPasswordHash, ResetPasswordHelpers.ResetPasswordHashExpiryTime ); if (!hashIsValid) { TempData.Clear(); return(RedirectToAction("Error")); } if (!ModelState.IsValid) { return(View(viewModel)); } await passwordResetService.InvalidateResetPasswordForEmailAsync(resetPasswordData.Email); await passwordService.ChangePasswordAsync(resetPasswordData.Email, viewModel.Password !); TempData.Clear(); return(View("Success")); }
public async Task <ResponseMessage> RunAsync(ChangePasswordModel model) { var changePasswordResult = await _passwordService.ChangePasswordAsync(model); if (!changePasswordResult.IsValid) { if (changePasswordResult.ContainsKey(USERID_PROPERTY)) { return(NotFoundResponse(model.UserId)); } return(BadRequestResponse(changePasswordResult)); } return(OkResponse("Password has been changed.")); }
public async Task <HttpResponseMessage> Put(ChangePasswordModel value) { bool passwordMatch = false; try { passwordMatch = await _passwordService.ChangePasswordAsync(UserId, value.NewPassword, value.OldPassword); } catch (BadRequestException) { if (!passwordMatch) { ModelState.AddModelError("OldPassword", ResponseMessages.AccountsInvalidOldPassword); } return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } return(Request.CreateResponse(HttpStatusCode.OK)); }
public async Task IndexAsync_with_valid_model_calls_password_service_and_returns_confirmation_view_async() { // Given var delegateUser = UserTestHelper.GetDefaultDelegateUser(); var model = new SetDelegatePasswordViewModel { Password = Password }; A.CallTo(() => userDataService.GetDelegateUserById(DelegateId)) .Returns(delegateUser); A.CallTo(() => passwordService.ChangePasswordAsync(A <string> ._, A <string> ._)).Returns(Task.CompletedTask); // When var result = await setDelegatePasswordController.IndexAsync(model, DelegateId, true); // Then A.CallTo(() => passwordService.ChangePasswordAsync(delegateUser.EmailAddress !, Password)) .MustHaveHappened(); result.Should().BeViewResult().WithViewName("Confirmation"); }
public async Task <HttpResponseMessage> Post(RegisterUserModel model) { // Add profile var user = new DomainUser { ApplicationName = AppName, Name = model.UserName, Email = model.Email, Roles = new List <string> { DomainRoles.User }, UserAgent = _productIdExtractor.Get(UserAgent) }; user = await _userService.AddAsync(user); // Set user password await _passwordService.ChangePasswordAsync(user.Id, model.Password); try { await _emailNotificationService.SendRegistrationEmailAsync(user); } catch (Exception e) { Trace.TraceError("Failed to send registration e-mail to {0}: {1}", model.Email, e); } Profile profile = _mapper.Map <DomainUser, Profile>(user); profile.AvatarUrl = _avatarProvider.GetAvatar(user); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, profile); response.SetLastModifiedDate(user.Modified); await _authenticationService.SetUserAsync(user, new TokenData { IdentityProvider = ProviderType.Email }, true); return(response); }
public async Task Post_to_index_should_update_password_if_model_and_hash_valid() { // Given unauthenticatedController.TempData.Set(new ResetPasswordData("email", "hash")); A.CallTo( () => passwordResetService.EmailAndResetPasswordHashAreValidAsync( "email", "hash", ResetPasswordHelpers.ResetPasswordHashExpiryTime ) ) .Returns(true); // When await unauthenticatedController.Index( new ConfirmPasswordViewModel { Password = "******", ConfirmPassword = "******" } ); // Then A.CallTo(() => passwordService.ChangePasswordAsync("email", "testPass-9")) .MustHaveHappenedOnceExactly(); }
public async Task ChangePassword(RecoveryLink recoveryLink, string newPassword) { PasswordRecoveryEntity entity = await _passwordRecoverRepository.SingleOrDefaultAsync(e => e.LinkData == recoveryLink.Id); if (entity == null || entity.IsConfirmed) { throw new NotFoundException(); } entity.Modified = DateTime.UtcNow; entity.IsConfirmed = true; entity = await _passwordRecoverRepository.UpdateAsync(entity); UserEntity user = await _userRepository.FindByEmailAsync(entity.Email); if (user == null) { throw new NotFoundException(); } await _passwordService.ChangePasswordAsync(user.Id, newPassword); }
public Task SetUserPasswordAsync(string userId, string password) { return(_passwordService.ChangePasswordAsync(userId, password)); }
private async Task InitializeSuperAdmin() { // Get admin configuration string dataString = _settings.DefaultAdministrator; if (string.IsNullOrEmpty(dataString)) { return; } // Get default administrator data List <string> userData = dataString.Split(FieldDelimiter).ToList(); if (userData.Count != 2) { Trace.TraceError("Failed to parse default administrator data"); return; } // Check user existence UserEntity user = null; try { user = await _userRepository.FindByEmailAsync(userData[0]); } catch (NotFoundException) { } catch (Exception e) { Trace.TraceError("Failed to get administrator: {0}", e); return; } if (user == null) { // Try to create a new super administrator try { // Add user user = await _userRepository.AddAsync(new UserEntity { AppName = new Uri(_settings.PortalUri).Host, Name = DomainRoles.SuperAdministrator, NameSort = DomainRoles.SuperAdministrator.ToLowerInvariant(), Email = userData[0], Created = DateTime.UtcNow, Modified = DateTime.UtcNow, Roles = new List <string> { DomainRoles.SuperAdministrator } }); // Set adminstrator password await _passwordService.ChangePasswordAsync(user.Id, userData[1]); } catch (Exception e) { Trace.TraceError("Failed to add administrator profile: {0}", e); } } }