This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Security.Claims;
|
||||
using MistoxWebsite.Server.Entities;
|
||||
using MistoxWebsite.Server.Services.DatabaseService;
|
||||
|
||||
@@ -12,6 +13,19 @@ namespace MistoxWebsite.Server.Controllers {
|
||||
_databaseService = databaseService;
|
||||
}
|
||||
|
||||
public void signIn(string JWT) {
|
||||
Response.Cookies.Append("mistox_session", JWT, new CookieOptions {
|
||||
Secure = true,
|
||||
HttpOnly = true,
|
||||
SameSite = SameSiteMode.Strict,
|
||||
Expires = DateTime.UtcNow.AddDays(7)
|
||||
});
|
||||
}
|
||||
|
||||
public void signOut() {
|
||||
Response.Cookies.Delete("mistox_session");
|
||||
}
|
||||
|
||||
public bool isLoggedIn() {
|
||||
if (User.Identity != null && User.Identity.IsAuthenticated) {
|
||||
return true;
|
||||
@@ -20,16 +34,19 @@ namespace MistoxWebsite.Server.Controllers {
|
||||
}
|
||||
|
||||
public int getLoggedInUserID() {
|
||||
return Convert.ToInt32(User.FindFirst("ID")?.Value);
|
||||
return Convert.ToInt32(User.FindFirstValue(ClaimTypes.NameIdentifier));
|
||||
}
|
||||
|
||||
public async Task<Account> getLoggedInUser() {
|
||||
public Account getLoggedInUser() {
|
||||
try {
|
||||
Account? test = await _databaseService.GetAccount(getLoggedInUserID());
|
||||
if (test != null) {
|
||||
return test;
|
||||
}
|
||||
return new Account();
|
||||
Account building = new Account {
|
||||
ID = Convert.ToInt32(User.FindFirstValue(ClaimTypes.NameIdentifier)),
|
||||
UserName = User.FindFirstValue(ClaimTypes.Name)!.ToString(),
|
||||
Email = User.FindFirstValue(ClaimTypes.Email)!.ToString(),
|
||||
Role = User.FindFirstValue(ClaimTypes.Role)!.ToString(),
|
||||
DataServer = User.FindFirstValue(ClaimTypes.UserData)!.ToString()
|
||||
};
|
||||
return building;
|
||||
} catch {
|
||||
return new Account();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user