Ejemplo n.º 1
0
        public async Task <LoginResponseDto> Login(string email, string password, string totpCode)
        {
            var user = await _userRepository.GetUser(email);

            if (user == null)
            {
                throw new Exception("User does not exist");
            }

            var hash = _encrypter.GetHash(password, user.Salt);


            if (user.PasswordHash == hash && _totpService.VerifyTotpCode(user, totpCode))
            {
                var jwtToken = _tokenService.GenerateJwtToken(user);

                var token        = _encrypter.GetSecureSalt(32);
                var refreshToken = new RefreshToken(token, DateTime.UtcNow.AddDays(1).Ticks.ToString());

                return(new LoginResponseDto
                {
                    JwtToken = jwtToken,
                    RefreshToken = _mapper.Map <RefreshToken, RefreshTokenDto>(refreshToken),
                    UserDto = _mapper.Map <User, UserDto>(user)
                });
            }

            throw new Exception("Invalid credentials");
        }
Ejemplo n.º 2
0
 public string GenerateRefreshToken()
 {
     return(_encrypter.GetSecureSalt(32));
 }