Exemple #1
0
        public async Task <IActionResult> UpdatePassword([FromBody] UserPasswordChangeDto dto)
        {
            if (ModelState.IsValid)
            {
                _service.InjectHttpContext(HttpContext);
                var result = await _service.UpdatePassword(dto);

                if (result.Succeeded)
                {
                    return(Ok(MessageGenerator.Generate(UserResponses.PasswordUpdated)));
                }
                else
                {
                    return(BadRequest(MessageGenerator.GenerateErrors(result)));
                }
            }

            return(BadRequest(ModelState));
        }
Exemple #2
0
        public async Task <IdentityResult> UpdatePassword(UserPasswordChangeDto dto)
        {
            var user = await GetCurrentUser();

            if (user != null)
            {
                var result = await _usrManager.ChangePasswordAsync(user, dto.CurrentPassword, dto.NewPassword);

                if (result.Succeeded)
                {
                    await _signInManager.RefreshSignInAsync(user);

                    return(IdentityResult.Success);
                }
                else
                {
                    return(IdentityResult.Failed());
                }
            }

            return(IdentityResult.Failed());
        }