add login/logout events to change tracker

default guest profile to minimum permissions
This commit is contained in:
RaidMax 2021-06-30 21:13:25 -05:00
parent 0019ed8dde
commit 0256fc35d2
5 changed files with 65 additions and 2 deletions

View File

@ -61,7 +61,7 @@ namespace SharedLibraryCore
Client ??= new EFClient() Client ??= new EFClient()
{ {
ClientId = -1, ClientId = -1,
Level = EFClient.Permission.User, Level = EFClient.Permission.Banned,
CurrentAlias = new EFAlias() { Name = "Webfront Guest" } CurrentAlias = new EFAlias() { Name = "Webfront Guest" }
}; };
} }

View File

@ -151,6 +151,14 @@ namespace SharedLibraryCore
/// a client's permission was changed /// a client's permission was changed
/// </summary> /// </summary>
ChangePermission = 111, ChangePermission = 111,
/// <summary>
/// client logged in to webfront
/// </summary>
Login = 112,
/// <summary>
/// client logged out of webfront
/// </summary>
Logout = 113,
// events "generated" by IW4MAdmin // events "generated" by IW4MAdmin
/// <summary> /// <summary>

View File

@ -66,7 +66,23 @@ namespace SharedLibraryCore.Services
CurrentValue = ((EFClient.Permission)e.Extra).ToString() CurrentValue = ((EFClient.Permission)e.Extra).ToString()
}; };
break; break;
default: case GameEvent.EventType.Login:
change = new EFChangeHistory()
{
OriginEntityId = e.Origin.ClientId,
Comment = "Logged In To Webfront",
TypeOfChange = EFChangeHistory.ChangeType.Command,
CurrentValue = e.Data
};
break;
case GameEvent.EventType.Logout:
change = new EFChangeHistory()
{
OriginEntityId = e.Origin.ClientId,
Comment = "Logged Out of Webfront",
TypeOfChange = EFChangeHistory.ChangeType.Command,
CurrentValue = e.Data
};
break; break;
} }

View File

@ -120,6 +120,14 @@ namespace WebfrontCore.Controllers.API
var claimsPrinciple = new ClaimsPrincipal(claimsIdentity); var claimsPrinciple = new ClaimsPrincipal(claimsIdentity);
await SignInAsync(claimsPrinciple); await SignInAsync(claimsPrinciple);
Manager.AddEvent(new GameEvent()
{
Origin = privilegedClient,
Type = GameEvent.EventType.Login,
Owner = Manager.GetServers().First(),
Data = HttpContext.Connection.RemoteIpAddress.ToString()
});
return Ok(); return Ok();
} }
} }
@ -137,6 +145,17 @@ namespace WebfrontCore.Controllers.API
[ProducesResponseType(StatusCodes.Status500InternalServerError)] [ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> LogoutAsync() public async Task<IActionResult> LogoutAsync()
{ {
if (Authorized)
{
Manager.AddEvent(new GameEvent()
{
Origin = Client,
Type = GameEvent.EventType.Logout,
Owner = Manager.GetServers().First(),
Data = HttpContext.Connection.RemoteIpAddress.ToString()
});
}
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
return Ok(); return Ok();

View File

@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Mvc;
using SharedLibraryCore; using SharedLibraryCore;
using SharedLibraryCore.Interfaces; using SharedLibraryCore.Interfaces;
using System; using System;
using System.Linq;
using System.Security.Claims; using System.Security.Claims;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -51,6 +52,14 @@ namespace WebfrontCore.Controllers
var claimsPrinciple = new ClaimsPrincipal(claimsIdentity); var claimsPrinciple = new ClaimsPrincipal(claimsIdentity);
await SignInAsync(claimsPrinciple); await SignInAsync(claimsPrinciple);
Manager.AddEvent(new GameEvent()
{
Origin = privilegedClient,
Type = GameEvent.EventType.Login,
Owner = Manager.GetServers().First(),
Data = HttpContext.Connection.RemoteIpAddress.ToString()
});
return Ok(); return Ok();
} }
} }
@ -66,6 +75,17 @@ namespace WebfrontCore.Controllers
[HttpGet] [HttpGet]
public async Task<IActionResult> LogoutAsync() public async Task<IActionResult> LogoutAsync()
{ {
if (Authorized)
{
Manager.AddEvent(new GameEvent()
{
Origin = Client,
Type = GameEvent.EventType.Logout,
Owner = Manager.GetServers().First(),
Data = HttpContext.Connection.RemoteIpAddress.ToString()
});
}
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
return RedirectToAction("Index", "Home"); return RedirectToAction("Index", "Home");
} }