2018-04-08 14:48:40 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Security.Claims;
|
2018-03-06 02:22:19 -05:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.Filters;
|
2018-04-08 14:48:40 -04:00
|
|
|
|
|
2018-04-08 02:44:42 -04:00
|
|
|
|
using SharedLibraryCore.Database;
|
|
|
|
|
using SharedLibraryCore.Database.Models;
|
2018-04-08 14:48:40 -04:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
2018-04-08 02:44:42 -04:00
|
|
|
|
using SharedLibraryCore.Objects;
|
2018-03-06 02:22:19 -05:00
|
|
|
|
|
|
|
|
|
namespace WebfrontCore.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class BaseController : Controller
|
|
|
|
|
{
|
2018-04-08 14:48:40 -04:00
|
|
|
|
protected IManager Manager;
|
2018-04-08 02:44:42 -04:00
|
|
|
|
protected readonly DatabaseContext Context;
|
2018-03-06 02:22:19 -05:00
|
|
|
|
protected bool Authorized { get; private set; }
|
2018-03-27 00:54:20 -04:00
|
|
|
|
protected EFClient User { get; private set; }
|
2018-03-06 02:22:19 -05:00
|
|
|
|
|
|
|
|
|
public override void OnActionExecuting(ActionExecutingContext context)
|
|
|
|
|
{
|
2018-04-08 14:48:40 -04:00
|
|
|
|
Manager = Program.Manager;
|
2018-03-27 00:54:20 -04:00
|
|
|
|
|
2018-04-16 16:31:14 -04:00
|
|
|
|
User = User ?? new EFClient()
|
2018-03-27 00:54:20 -04:00
|
|
|
|
{
|
|
|
|
|
ClientId = -1
|
|
|
|
|
};
|
|
|
|
|
|
2018-04-09 23:33:42 -04:00
|
|
|
|
if (HttpContext.Connection.RemoteIpAddress.ToString() != "127.0.0.1")
|
2018-03-27 00:54:20 -04:00
|
|
|
|
{
|
2018-04-09 23:33:42 -04:00
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2018-03-27 00:54:20 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-09 23:33:42 -04:00
|
|
|
|
else
|
2018-03-27 00:54:20 -04:00
|
|
|
|
{
|
2018-04-09 23:33:42 -04:00
|
|
|
|
User.ClientId = 1;
|
|
|
|
|
User.Level = Player.Permission.Console;
|
|
|
|
|
User.CurrentAlias = new EFAlias() { Name = "IW4MAdmin" };
|
2018-03-27 00:54:20 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-04 15:38:34 -04:00
|
|
|
|
Authorized = User.ClientId >= 0;
|
2018-03-09 03:01:12 -05:00
|
|
|
|
ViewBag.Authorized = Authorized;
|
2018-03-13 17:30:22 -04:00
|
|
|
|
ViewBag.Url = Startup.Configuration["Web:Address"];
|
2018-04-02 01:25:06 -04:00
|
|
|
|
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 = "";
|
|
|
|
|
}
|
2018-03-06 02:22:19 -05:00
|
|
|
|
base.OnActionExecuting(context);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|