IW4M-Admin/WebfrontCore/Controllers/BaseController.cs

65 lines
2.1 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;
2018-04-08 02:44:42 -04:00
using SharedLibraryCore;
using SharedLibraryCore.Database;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Objects;
using System;
2018-03-06 02:22:19 -05:00
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
2018-03-06 02:22:19 -05:00
namespace WebfrontCore.Controllers
{
public class BaseController : Controller
{
protected ApplicationManager 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; }
protected EFClient User { get; private set; }
2018-03-06 02:22:19 -05:00
2018-04-08 02:44:42 -04:00
/* public BaseController(DatabaseContext ctx)
{
Context = ctx;
}*/
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 = 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)
{
}
Authorized = User.ClientId >= 0;
2018-03-09 03:01:12 -05:00
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 = "";
}
2018-03-06 02:22:19 -05:00
base.OnActionExecuting(context);
}
}
}