Beispiel #1
0
        public IActionResult Authenticate([FromBody] LoginForm login)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!_jWTService.CheckAccount(new LoginForm(login.email, _userService.EncodePassword(login.password))))
            {
                return(NotFound(new Response("404", "Email or password is not correct!")));
            }

            var id           = _userService.GetIdByEmail(login.email);
            var AccessToken  = _jWTService.GenerateToken(id, login.email);
            var RefreshToken = _jWTService.GenerateRefreshToken();

            _userService.UpdateRefreshToken(_userService.GetIdByEmail(login.email), RefreshToken);

            return(Ok(new LoginRespone(AccessToken, RefreshToken)));
        }