public static UserLoggedIn ToApiLogin(this d.UserEntity user)
 {
     return(new UserLoggedIn()
     {
         Id = user.Id,
         Login = user.Login,
         Email = user.Email,
         IsAdmin = user.IsAdmin,
     });
 }
 public static UserEntity ToApi(this d.UserEntity user)
 {
     return(new UserEntity()
     {
         Id = user.Id,
         Login = user.Login,
         Email = user.Email,
         Password = null,
         FirstName = user.FirstName,
         LastName = user.LastName,
         BirthDate = user.BirthDate,
         IsAdmin = user.IsAdmin
     });
 }
        public IActionResult Login(UserLogin userLogin)
        {
            if (userLogin is null || !ModelState.IsValid)
            {
                return(BadRequest());
            }

            d.UserEntity userApp = _repo.Login(userLogin.Login, userLogin.Password);

            if (userApp is null)
            {
                return(new ForbidResult());
            }
            if (userApp.Disable_Until > DateTime.Now)
            {
                return(new ForbidResult($"Utilisateur bani jusqu'au {userApp.Disable_Until} : {userApp.Reason}"));
            }
            // Generate Token
            UserLoggedIn usrLogin = userApp.ToApiLogin();

            usrLogin.Usertoken = _tokenManager.GenerateJWT(userApp);

            return(Ok(usrLogin));
        }