ban/unban buttons added to profile

several css tweaks
changed administratorIPs to PrivilegedClients
added time step references to profile page
This commit is contained in:
RaidMax
2018-03-26 23:54:20 -05:00
parent 979b1f2310
commit a07ce112b0
18 changed files with 349 additions and 57 deletions

View File

@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using SharedLibrary;
using WebfrontCore.ViewModels;
namespace WebfrontCore.Controllers
{
public class ActionController : BaseController
{
public IActionResult BanForm()
{
var info = new ActionInfo()
{
ActionButtonLabel = "Ban",
Name = "Ban",
Inputs = new List<InputInfo>()
{
new InputInfo()
{
Name = "Reason",
Placeholder = ""
}
},
Action = "BanAsync"
};
return View("_ActionForm", info);
}
public async Task<IActionResult> BanAsync(int targetId, string Reason)
{
var server = Manager.GetServers().First();
return await Task.FromResult(RedirectToAction("ExecuteAsync", "Console", new
{
serverId = server.GetHashCode(),
command = $"!ban @{targetId} {Reason}"
}));
}
public IActionResult UnbanForm()
{
var info = new ActionInfo()
{
ActionButtonLabel = "Unban",
Name = "Unban",
Inputs = new List<InputInfo>()
{
new InputInfo()
{
Name = "Reason",
Placeholder = ""
}
},
Action = "UnbanAsync"
};
return View("_ActionForm", info);
}
public async Task<IActionResult> UnbanAsync(int targetId, string Reason)
{
var server = Manager.GetServers().First();
return await Task.FromResult(RedirectToAction("ExecuteAsync", "Console", new
{
serverId = server.GetHashCode(),
command = $"!unban @{targetId} {Reason}"
}));
}
}
}

View File

@ -2,11 +2,8 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using SharedLibrary;
using SharedLibrary.Interfaces;
using System;
using SharedLibrary.Database.Models;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace WebfrontCore.Controllers
{
@ -14,19 +11,36 @@ namespace WebfrontCore.Controllers
{
protected ApplicationManager Manager;
protected bool Authorized { get; private set; }
protected EFClient User { get; private set; }
public override void OnActionExecuting(ActionExecutingContext context)
{
Manager = IW4MAdmin.Program.ServerManager;
Authorized = context.HttpContext.Connection.RemoteIpAddress.ToString() == "127.0.0.1" ||
Manager.AdministratorIPs.Contains(context.HttpContext.Connection.RemoteIpAddress.ToString().ConvertToIP());
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;
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.DiscorLink = "";
ViewBag.DiscordLink = "";
base.OnActionExecuting(context);
}
}

View File

@ -41,7 +41,7 @@ namespace WebfrontCore.Controllers
IPAddress = intIP
};
#else
var origin = (await Manager.GetClientService().GetUnique(0)).AsPlayer();
var origin = (await Manager.GetClientService().GetUnique(0)).AsPlayer();
#endif
var server = Manager.Servers.First(s => s.GetHashCode() == serverId);