Ejemplo n.º 1
0
        public IActionResult LoginEmployee(LoginRequestDto request)
        {
            if (!_dbService.CheckCredentials(request))
            {
                return(Unauthorized());
            }

            var claims = new[]
            {
                new Claim(ClaimTypes.Name, request.Login),
                new Claim(ClaimTypes.Role, "employee")
            };

            var key   = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["SecretKey"]));
            var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);

            var token = new JwtSecurityToken
                        (
                issuer: "s18660",
                audience: "Students",
                claims: claims,
                expires: DateTime.Now.AddMinutes(5),
                signingCredentials: creds
                        );

            return(Ok(new
            {
                token = new JwtSecurityTokenHandler().WriteToken(token),
                refreshToken = Guid.NewGuid()
            }));
        }
Ejemplo n.º 2
0
        public IActionResult LoginStudent(LoginRequestDto request)
        {
            if (!_dbService.CheckCredentials(request))
            {
                return(Unauthorized());
            }

            return(Ok(GenerateToken(request.Login)));
        }