public async Task ResetUsername(AdminUserResetUsernameModel model) { var adminUser = await GetItem(new Guid(model.Id)); if (adminUser == null) { throw new UserNotFoundException(); } if (string.Compare(_hashingService.DecryptString(adminUser.Password), model.ConfirmPassword, false) != 0) { throw new PasswordsDoNotMatchException(); } if (await UsernameAlreadyExists(model.ResetUsername)) { throw new UsernameAlreadyExistsException(model.ResetUsername); } // TODO: All or nothing! // NoSQL databases do not support updating the partition key value of an existing item. Need to delete entire document and create new. // Transactions using the same partition key (but this process uses 2 different partition keys) ~ https://devblogs.microsoft.com/cosmosdb/introducing-transactionalbatch-in-the-net-sdk/ await _adminUsersManager.DeleteItemAsync(adminUser); adminUser.Username = model.ResetUsername; var adminAuthenticateUser = new AdminAuthenticateUserModel(adminUser); await CreateItem(adminAuthenticateUser); }
public async Task <IActionResult> ResetUsername(AdminUserResetUsernameModel model) { try { await _adminUserService.ResetUsername(model); response = new ApiResponse(HttpStatusCode.OK, string.Format("Admin user with username '{0}' updated successfully.", model.ResetUsername), null); return(Ok(new { response })); } catch (UserNotFoundException exception) { response = new ApiResponse(HttpStatusCode.NotFound, exception.Message, null); return(Ok(new { response })); } catch (PasswordsDoNotMatchException exception) { response = new ApiResponse(HttpStatusCode.Conflict, exception.Message, null); return(Ok(new { response })); } catch (UsernameAlreadyExistsException exception) { response = new ApiResponse(HttpStatusCode.Conflict, string.Format("Username '{0}' already exists in the admin database.", model.ResetUsername), null); return(Ok(new { response })); } catch (Exception exception) { return(BadRequest("Admin user update failed. Error: " + exception.Message)); } }
public AdminUserResetUsername(AdminUserResetUsernameModel entity) { ResetUsername = entity.ResetUsername; ConfirmPassword = entity.ConfirmPassword; }