/// <summary> /// Changes the password for the logged in user with the new password. /// </summary> /// <param name="oldPassword">Old password for the account.</param> /// <param name="newPassword">New password for the account.</param> /// <param name="options">Request specific api options. These will override the global settings for the app for this request.</param> public static async Task ChangePasswordAsync(string oldPassword, string newPassword, ApiOptions options = null) { if (InternalApp.Current.CurrentUser.IsLoggedIn == false) throw new AppacitiveRuntimeException("Cannot change password for current user as no user is logged in."); var request = new ChangePasswordRequest { UserId = "me", OldPassword = oldPassword, NewPassword = newPassword, IdType = "token" }; ApiOptions.Apply(request, options); var response = await request.ExecuteAsync(); if (response.Status.IsSuccessful == false) throw response.Status.ToFault(); }
public async Task ChangePasswordWithTokenTest() { // Create user var newUser = await UserHelper.CreateNewUserAsync(); // Authenticate with existing password await AppContext.LoginAsync(new UsernamePasswordCredentials(newUser.Username, newUser.Password)); // Change password var newPassword = "******"; var token = AppContext.UserContext.SessionToken; var request = new ChangePasswordRequest() { UserId = token, IdType = "token", OldPassword = newUser.Password, NewPassword = newPassword }; var response = await request.ExecuteAsync(); ApiHelper.EnsureValidResponse(response); // Authenticate with new password await AppContext.LoginAsync(new UsernamePasswordCredentials(newUser.Username, newPassword)); Assert.IsTrue(string.IsNullOrWhiteSpace(AppContext.UserContext.SessionToken) == false, "Authentication failed for username {0} and password {1}.", newUser.Username, newPassword); }
/// <summary> /// Changes the password for the given user with the new password. /// </summary> /// <param name="userId">Id for the user account.</param> /// <param name="oldPassword">Old password for the account.</param> /// <param name="newPassword">New password for the account.</param> /// <param name="options">Request specific api options. These will override the global settings for the app for this request.</param> public static async Task ChangePasswordByIdAsync(string userId, string oldPassword, string newPassword, ApiOptions options = null) { var request = new ChangePasswordRequest { UserId = userId, OldPassword = oldPassword, NewPassword = newPassword, }; ApiOptions.Apply(request, options); var response = await request.ExecuteAsync(); if (response.Status.IsSuccessful == false) throw response.Status.ToFault(); }
public async Task ChangePasswordWithUsernameAsyncTest() { // Create user var newUser = await UserHelper.CreateNewUserAsync(); // Authenticate with existing password var token = await UserHelper.AuthenticateAsync(newUser.Username, newUser.Password); App.UserToken = token; // Change password var newPassword = "******"; var request = new ChangePasswordRequest() { UserId = newUser.Username, IdType="username", OldPassword = newUser.Password, NewPassword = newPassword }; var response = await request.ExecuteAsync(); ApiHelper.EnsureValidResponse(response); // Authenticate with new password token = await UserHelper.AuthenticateAsync(newUser.Username, newPassword); Assert.IsTrue(string.IsNullOrWhiteSpace(token) == false, "Authentication failed for username {0} and password {1}.", newUser.Username, newPassword); }