Ejemplo n.º 1
0
        public IActionResult GenerateToken(Login objLogin)
        {
            IActionResult response = Unauthorized();
            var           objUser  = _iLoginRepo.GetUser(objLogin);

            if (objUser == null)
            {
                return(this.StatusCode(StatusCodes.Status401Unauthorized, "Unauthorized user."));
            }
            string key      = _configuration["Jwt:Key"];
            string issuer   = _configuration["Jwt:Issuer"];
            string strToken = _iLoginRepo.CreateToken(objUser, key, issuer);

            response = Ok(new { token = strToken });
            return(response);
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Login([FromBody] LoginRequest loginRequest)
        {
            if (ModelState.IsValid)
            {
                var userExists = await _context.Authenticate(loginRequest);

                if (userExists)
                {
                    var token    = _context.CreateToken(loginRequest);
                    var response = await _context.CreateResponse(loginRequest, token);


                    return(Ok(JsonConvert.SerializeObject(response)));
                }
            }
            return(Unauthorized());
        }