Example #1
0
        public TokenResponseDto LogIn(LogInRequestDto logInRequestDto)
        {
            var client = _advertDbContext.Clients.FirstOrDefault(c => c.Login.Equals(logInRequestDto.Login));

            if (client == null)
            {
                throw new BadLoginOrPasswordException("Bad Login or Password");
            }

            var salt           = client.Salt;
            var storedPassword = client.Password;

            if (!_passwordService.ValidatePassword(logInRequestDto.Password, storedPassword, salt))
            {
                throw new BadLoginOrPasswordException("Bad Login or Password");
            }

            var accessToken  = CreateJwtToken(logInRequestDto.Login);
            var refreshToken = Convert.ToBase64String(Guid.NewGuid().ToByteArray());

            client.RefreshToken = refreshToken;

            _advertDbContext.SaveChanges();

            return(new TokenResponseDto
            {
                AccessToken = accessToken,
                RefreshToken = refreshToken
            });
        }
Example #2
0
 public IActionResult LogIn(LogInRequestDto logInRequestDto)
 {
     return(Ok(_jwtTokenService.LogIn(logInRequestDto)));
 }