예제 #1
0
 private void ValidateUpdatedData(ChangeUserCommand command, User userFromRepo)
 {
     if (!_passwordValidator.Equals(command.CurrentPassword, userFromRepo.PasswordHash, userFromRepo.PasswordSalt))
     {
         throw new Exception("Podane hasło jest nieprawidłowe.");
     }
     else if (!string.IsNullOrEmpty(command.NewPassword) && command.NewPassword.Length < 6)
     {
         throw new Exception("Nowe hasło musi zawierać co najmniej 6 znaków.");
     }
     else if (!string.IsNullOrEmpty(command.ConfirmPassword) && command.ConfirmPassword.Length < 6)
     {
         throw new Exception("Powtórz hasło musi zawierać co najmniej 6 znaków.");
     }
 }
예제 #2
0
        public async Task <ResponseToken> Handle(LoginCommand request, CancellationToken cancellationToken)
        {
            var user = await _userRepository.GetAsync(request.Email);

            if (user == null || user.IsRemoved)
            {
                throw new UnauthorizedAccessException("Konto nie istnieje");
            }

            if (!_passwordValidator.Equals(request.Password, user.PasswordHash, user.PasswordSalt))
            {
                throw new UnauthorizedAccessException($"Niepoprawne dane logowania");
            }

            return(new ResponseToken()
            {
                Token = _jwtHandler.CreateToken(user.Id, user.Email, user.Role),
                PhotoUrl = user.PhotoUrl
            });
        }