Move sign in methods to Controller base
This commit is contained in:
@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Auth.Entities;
|
||||
using Auth.Services.DatabaseService;
|
||||
using System.Security.Claims;
|
||||
using Auth.Services;
|
||||
|
||||
namespace Auth.Controllers {
|
||||
|
||||
@@ -13,6 +14,29 @@ namespace Auth.Controllers {
|
||||
_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() {
|
||||
if (User.Identity != null && User.Identity.IsAuthenticated) {
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user