Move sign in methods to Controller base

This commit is contained in:
2025-07-26 08:59:07 -07:00
parent b5435a6b48
commit d1b53ee62e
@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc;
using Auth.Entities; using Auth.Entities;
using Auth.Services.DatabaseService; using Auth.Services.DatabaseService;
using System.Security.Claims; using System.Security.Claims;
using Auth.Services;
namespace Auth.Controllers { namespace Auth.Controllers {
@@ -13,6 +14,29 @@ namespace Auth.Controllers {
_databaseService = databaseService; _databaseService = databaseService;
} }
public static void SignIn(HttpResponse Response, bool StayLoggedIn, string jwt) {
if (StayLoggedIn) {
// Stay logged in cookie
Response.Cookies.Append(AuthJWT.TokenName, jwt, new CookieOptions {
Secure = true,
HttpOnly = true,
SameSite = SameSiteMode.Strict,
Expires = DateTime.UtcNow.AddDays(7)
});
} else {
// Session cookie
Response.Cookies.Append(AuthJWT.TokenName, jwt, new CookieOptions {
Secure = true,
HttpOnly = true,
SameSite = SameSiteMode.Strict,
});
}
}
public static void SignOut(HttpResponse Response) {
Response.Cookies.Delete(AuthJWT.TokenName);
}
public bool isLoggedIn() { public bool isLoggedIn() {
if (User.Identity != null && User.Identity.IsAuthenticated) { if (User.Identity != null && User.Identity.IsAuthenticated) {
return true; return true;