9aea9e1c02
initialization should be better asynced clean up publish folder after publish added chevron hover icon for loading more penalties added T6M maps to config
69 lines
2.3 KiB
C#
69 lines
2.3 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Security.Claims;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Filters;
|
|
|
|
using SharedLibraryCore.Database;
|
|
using SharedLibraryCore.Database.Models;
|
|
using SharedLibraryCore.Interfaces;
|
|
using SharedLibraryCore.Objects;
|
|
|
|
namespace WebfrontCore.Controllers
|
|
{
|
|
public class BaseController : Controller
|
|
{
|
|
protected IManager Manager;
|
|
protected readonly DatabaseContext Context;
|
|
protected bool Authorized { get; private set; }
|
|
protected EFClient User { get; private set; }
|
|
|
|
public override void OnActionExecuting(ActionExecutingContext context)
|
|
{
|
|
Manager = Program.Manager;
|
|
|
|
User = User ?? new EFClient()
|
|
{
|
|
ClientId = -1
|
|
};
|
|
|
|
if (HttpContext.Connection.RemoteIpAddress.ToString() != "127.0.0.1")
|
|
{
|
|
try
|
|
{
|
|
User.ClientId = Convert.ToInt32(base.User.Claims.First(c => c.Type == ClaimTypes.Sid).Value);
|
|
User.Level = (Player.Permission)Enum.Parse(typeof(Player.Permission), base.User.Claims.First(c => c.Type == ClaimTypes.Role).Value);
|
|
User.CurrentAlias = new EFAlias() { Name = base.User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value };
|
|
}
|
|
|
|
catch (InvalidOperationException)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
else
|
|
{
|
|
User.ClientId = 1;
|
|
User.Level = Player.Permission.Console;
|
|
User.CurrentAlias = new EFAlias() { Name = "IW4MAdmin" };
|
|
}
|
|
|
|
Authorized = User.ClientId >= 0;
|
|
ViewBag.Authorized = Authorized;
|
|
ViewBag.Url = Startup.Configuration["Web:Address"];
|
|
ViewBag.User = User;
|
|
|
|
if (Manager.GetApplicationSettings().Configuration().EnableDiscordLink)
|
|
{
|
|
string inviteLink = Manager.GetApplicationSettings().Configuration().DiscordInviteCode;
|
|
if (inviteLink != null)
|
|
ViewBag.DiscordLink = inviteLink.Contains("https") ? inviteLink : $"https://discordapp.com/invite/{inviteLink}";
|
|
else
|
|
ViewBag.DiscordLink = "";
|
|
}
|
|
base.OnActionExecuting(context);
|
|
}
|
|
}
|
|
}
|