public async Task<ChangePasswordResponse> ChangePasswordAsync(ChangePasswordRequest request)
 {
     byte[] bytes = null;
     bytes = await HttpOperation
         .WithUrl(Urls.For.ChangePassword(request.UserId, request.IdType, request.CurrentLocation, request.DebugEnabled, request.Verbosity, request.Fields))
         .WithAppacitiveSession(request.SessionToken)
         .WithEnvironment(request.Environment)
         .WithUserToken(request.UserToken)
         .PostAsyc(request.ToBytes());
     var response = ChangePasswordResponse.Parse(bytes);
     return response;
 }
Esempio n. 2
0
 /// <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();
 }
Esempio n. 3
0
 /// <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 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);
        }
        public async Task ChangePasswordWithTokenTest()
        {
            // Create user
            var newUser = await UserHelper.CreateNewUserAsync();

            // Authenticate with existing password
            var token = await UserHelper.AuthenticateAsync(newUser.Username, newUser.Password);
            App.SetLoggedInUser(token);

            // Change password
            var newPassword = "******";
            var request = new ChangePasswordRequest() { UserId = token, IdType = "token", OldPassword = newUser.Password, NewPassword = newPassword };
            IUserService userService = new UserService();
            var response = await userService.ChangePasswordAsync(request);
            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);
        }
        public async Task ChangePasswordAsyncTest()
        {
            // 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.Id, 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);
        }