2018-04-08 13:48:40 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Security.Claims;
|
2018-03-06 01:22:19 -06:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.Filters;
|
2018-04-08 13:48:40 -05:00
|
|
|
|
|
2018-04-08 01:44:42 -05:00
|
|
|
|
using SharedLibraryCore.Database;
|
|
|
|
|
using SharedLibraryCore.Database.Models;
|
2018-04-08 13:48:40 -05:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
2018-04-08 01:44:42 -05:00
|
|
|
|
using SharedLibraryCore.Objects;
|
2018-03-06 01:22:19 -06:00
|
|
|
|
|
|
|
|
|
namespace WebfrontCore.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class BaseController : Controller
|
|
|
|
|
{
|
2018-04-08 13:48:40 -05:00
|
|
|
|
protected IManager Manager;
|
2018-04-08 01:44:42 -05:00
|
|
|
|
protected readonly DatabaseContext Context;
|
2018-03-06 01:22:19 -06:00
|
|
|
|
protected bool Authorized { get; private set; }
|
2018-03-26 23:54:20 -05:00
|
|
|
|
protected EFClient User { get; private set; }
|
2018-03-06 01:22:19 -06:00
|
|
|
|
|
2018-04-08 01:44:42 -05:00
|
|
|
|
/* public BaseController(DatabaseContext ctx)
|
|
|
|
|
{
|
|
|
|
|
Context = ctx;
|
|
|
|
|
}*/
|
|
|
|
|
|
2018-03-06 01:22:19 -06:00
|
|
|
|
public override void OnActionExecuting(ActionExecutingContext context)
|
|
|
|
|
{
|
2018-04-08 13:48:40 -05:00
|
|
|
|
Manager = Program.Manager;
|
2018-03-26 23:54:20 -05:00
|
|
|
|
|
|
|
|
|
User = new EFClient()
|
|
|
|
|
{
|
|
|
|
|
ClientId = -1
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2018-04-04 14:38:34 -05:00
|
|
|
|
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 };
|
2018-03-26 23:54:20 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-04 14:38:34 -05:00
|
|
|
|
catch (InvalidOperationException)
|
2018-03-26 23:54:20 -05:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-04 14:38:34 -05:00
|
|
|
|
Authorized = User.ClientId >= 0;
|
2018-03-09 02:01:12 -06:00
|
|
|
|
ViewBag.Authorized = Authorized;
|
2018-03-13 16:30:22 -05:00
|
|
|
|
ViewBag.Url = Startup.Configuration["Web:Address"];
|
2018-04-02 00:25:06 -05: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 01:22:19 -06:00
|
|
|
|
base.OnActionExecuting(context);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|