Beispiel #1
0
        public IActionResult Authenticate([FromBody] LoginModel userDto)
        {
            var user = _userService.Authenticate(userDto.Username, userDto.Password);

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

            var claims = new[]
            {
                new Claim(ClaimTypes.Name, user.Id.ToString())
            };
            var expires     = DateTime.Now.Add(new TimeSpan(00, 30, 0)).ToString();
            var tokenString = _jwtTokenHelper.EncodeJwt("test.dvsmarttech.co.uk", expires, null, claims);

            return(Ok(new
            {
                user.Id,
                Username = user.UserName,
                Token = tokenString,
                Expires = expires
            }));
        }