Ejemplo n.º 1
0
        /// <summary>
        /// Attempts to change the user's password.
        /// </summary>
        public async Task ChangePasswordAsync(ChangePasswordRequestVM request, UserContext userCtx)
        {
            if (request.NewPassword != request.NewPasswordRepeat)
            {
                throw new OperationException("Passwords do not match!");
            }

            if (request.NewPassword?.Length < 6)
            {
                throw new OperationException("Password must contain at least 6 characters!");
            }

            var oldCheck = await _userMgr.CheckPasswordAsync(userCtx.User, request.OldPassword);

            if (!oldCheck)
            {
                throw new OperationException("Old password is invalid!");
            }

            var result = await _userMgr.ChangePasswordAsync(userCtx.User, request.OldPassword, request.NewPassword);

            if (!result.Succeeded)
            {
                throw new OperationException("Failed to change password!");
            }
        }
Ejemplo n.º 2
0
 public async Task ChangePassword([FromBody] ChangePasswordRequestVM request)
 {
     await _auth.ChangePasswordAsync(request, await GetUserContextAsync());
 }