Beispiel #1
0
        public void RegisterNewUser(RegisterUserRequest request)
        {
            VerifyEmailAvailability(request.Email);
            PasswordHashHandler.CreatePasswordHash(request.Password, out var passwordHash, out var passwordSalt);
            var user = MapRequestToEntity(request, passwordHash, passwordSalt);

            Register(user);
        }
Beispiel #2
0
        public LoginUserResponse LoginUser(LoginUserRequest request)
        {
            var user = GetUserByEmail(request.Email);

            if (PasswordHashHandler.VerifyPasswordHash(request.Password, user.PasswordHash, user.PasswordSalt))
            {
                var token = _tokenGenerator.GenerateJwtToken(user.UserId, user.Role.Name);
                return(new LoginUserResponse(token, user.UserId));
            }

            throw new Exception("Wrong credentials");
        }