Esempio n. 1
0
        public IActionResult Login(AuthDTO authDto)
        {
            try
            {
                authDto = _userManagerService.CheckAuthData(authDto);
                if (authDto == null)
                {
                    return(StatusCode(401, "There is no user with such email and password"));
                }

                return(Ok(new {
                    token = Tools.CreateToken(authDto.Email, authDto.Id, authDto.Role),
                    role = authDto.Role,
                    id = authDto.Id,
                    expirationTime = DateTime.Now.AddHours(AuthOptions.LIFETIME)
                }));
            }
            catch (Exception e)
            {
                return(StatusCode(500, new { Message = "Server ERROR occured." }));
            }
        }