public async Task <bool> UpdateUserLoginInfo(UpdateLoginInfo newLoginInfo) { //validate that the current password is correct if (!newLoginInfo.NewPassword.IsNullOrEmpty()) { var oldCredentialsValid = await _authorizationService.AuthenticateUser(newLoginInfo.OldUsername, newLoginInfo.OldPassword); if (!oldCredentialsValid) { throw new UpdateLoginInfoException("Current Password is incorrect"); } var newPasswordHashBytes = _authorizationService.EncryptPassword(newLoginInfo.NewPassword); var passwordUpdateSuccess = await UpdatePassword(newPasswordHashBytes, newLoginInfo.OldUsername); if (!passwordUpdateSuccess) { throw new UpdateLoginInfoException(); } } //Validate that the new username is available if (!newLoginInfo.NewUsername.IsNullOrEmpty()) { var usernameAvailable = await GetUsernameAvailability(newLoginInfo.NewUsername); if (!usernameAvailable) { throw new UpdateLoginInfoException("New username is not available"); } var usernameUpdateSuccess = await UpdateUsername(newLoginInfo.NewUsername, newLoginInfo.OldUsername); if (!usernameUpdateSuccess) { throw new UpdateLoginInfoException(); } } return(true); }
public async Task <ActionResult> UpdateLoginInfo([FromBody] UpdateLoginInfo request) { request.OldPassword = ""; return(Ok(await _userService.UpdateUserLoginInfo(request))); }