public async Task <UserResponse> ExecuteAsync(ChangePasswordUserRequest request)
        {
            var foundUser = await _userManager.GetUserAsync(_httpContextAccessor.HttpContext.User);

            IdentityResult result =
                await _userManager.ChangePasswordAsync(foundUser, request.OldPassword, request.NewPassword);

            if (!result.Succeeded)
            {
                throw new CannotChangePasswordExeption(result.Errors);
            }
            return(_mapper.Map <User, UserResponse>(foundUser));
        }
Esempio n. 2
0
        public async Task <IActionResult> ChangeUserPassword(ChangePasswordUserRequest user, [FromServices] IChangeUserPasswordCommand command)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                UserResponse response = await command.ExecuteAsync(user);

                return(CreatedAtRoute("GetSingleUser", new { userId = response.Id }, response));
            }
            catch (CannotChangePasswordExeption exception)
            {
                foreach (var error in exception.Errors)
                {
                    ModelState.AddModelError(exception.Message, error.Description);
                }
                return(BadRequest(ModelState));
            }
        }
Esempio n. 3
0
        // [Authorize]
        public async Task <ActionResult <UserResponse> > ChangeUserPassword(ChangePasswordUserRequest request, [FromServices] Command <ChangePasswordUserRequest, UserResponse> command)
        {
            var response = await command.ExecuteAsync(request);

            return(CreatedAtRoute("GetSingleUser", new { userId = response.Id }, response));
        }