IW4M-Admin/WebfrontCore/Controllers/BaseController.cs

48 lines
1.5 KiB
C#
Raw Normal View History

2018-03-06 02:22:19 -05:00
using IW4MAdmin;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using SharedLibrary;
using SharedLibrary.Database.Models;
2018-03-06 02:22:19 -05:00
using System.Collections.Generic;
namespace WebfrontCore.Controllers
{
public class BaseController : Controller
{
protected ApplicationManager Manager;
protected bool Authorized { get; private set; }
protected EFClient User { get; private set; }
2018-03-06 02:22:19 -05:00
public override void OnActionExecuting(ActionExecutingContext context)
{
Manager = IW4MAdmin.Program.ServerManager;
User = new EFClient()
{
ClientId = -1
};
try
{
User.ClientId = Manager.PrivilegedClients[context.HttpContext.Connection.RemoteIpAddress.ToString().ConvertToIP()];
}
catch (KeyNotFoundException)
{
}
Authorized = context.HttpContext.Connection.RemoteIpAddress.ToString() == "127.0.0.1" ||
User.ClientId >= 0;
2018-03-09 03:01:12 -05:00
ViewBag.Authorized = Authorized;
ViewBag.Url = Startup.Configuration["Web:Address"];
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);
}
}
}