Example #1
0
        public async Task <IActionResult> Login([FromBody] UserLoginDto userLogin)
        {
            var user = await _userService.Authenticate(userLogin.Email, userLogin.UserPassword);

            if (user == null)
            {
                return(BadRequest("Username or Password is incorrect"));
            }

            var requestAccessToken  = _jwtAuthentication.CreateAccessToken(user);
            var requestRefreshToken = _jwtAuthentication.CreateRefreshToken(user.AppUserId);

            return(Ok(new { accessToken = requestAccessToken }));
        }
Example #2
0
        public HttpResponseMessage Login(string username, string password)
        {
            if (username == null || password == null)
            {
                throw new HttpResponseException(HttpStatusCode.Unauthorized);
            }

            AppUser currentUser = _appUserService.Authenticate(username, password);

            if (currentUser == null)
            {
                throw new HttpResponseException(HttpStatusCode.Unauthorized);
            }
            var tokenString = Helper.GetToken(currentUser);

            //TODO:
            //_appUserService.RecordLastLoginDateTime(currentUser.Id);

            return(new HttpResponseMessage {
                Content = new StringContent(tokenString)
            });
        }