fix login issue
strip colors for logging feature implementation for issue #76
This commit is contained in:
parent
75378400e7
commit
08d250156c
@ -60,6 +60,7 @@ namespace IW4MAdmin.Application
|
||||
await OnLogWriting.WaitAsync();
|
||||
|
||||
string stringType = type.ToString();
|
||||
msg = msg.StripColors();
|
||||
|
||||
try
|
||||
{
|
||||
@ -73,13 +74,13 @@ namespace IW4MAdmin.Application
|
||||
{
|
||||
#if DEBUG
|
||||
// lets keep it simple and dispose of everything quickly as logging wont be that much (relatively)
|
||||
Console.WriteLine(LogLine.StripColors());
|
||||
Console.WriteLine(LogLine);
|
||||
await File.AppendAllTextAsync(FileName, $"{LogLine}{Environment.NewLine}");
|
||||
//Debug.WriteLine(msg);
|
||||
#else
|
||||
if (type == LogType.Error || type == LogType.Verbose)
|
||||
{
|
||||
Console.WriteLine(LogLine.StripColors());
|
||||
Console.WriteLine(LogLine);
|
||||
}
|
||||
await File.AppendAllTextAsync(FileName, $"{LogLine}{Environment.NewLine}");
|
||||
#endif
|
||||
|
@ -156,6 +156,14 @@ namespace SharedLibraryCore
|
||||
/// <returns></returns>
|
||||
public static string FixIW4ForwardSlash(this string str) => str.Replace("/", " /");
|
||||
|
||||
private static readonly IList<string> _zmGameTypes = new[] { "zclassic", "zstandard", "zcleansed", "zgrief" };
|
||||
/// <summary>
|
||||
/// indicates if the given server is running a zombie game mode
|
||||
/// </summary>
|
||||
/// <param name="server"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsZombieServer(this Server server) => server.GameName == Game.T6 && _zmGameTypes.Contains(server.Gametype.ToLower());
|
||||
|
||||
/// <summary>
|
||||
/// Get the IW Engine color code corresponding to an admin level
|
||||
/// </summary>
|
||||
|
@ -1,5 +1,6 @@
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SharedLibraryCore;
|
||||
using System;
|
||||
@ -10,13 +11,9 @@ namespace WebfrontCore.Controllers
|
||||
{
|
||||
public class AccountController : BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// life span in months
|
||||
/// </summary>
|
||||
private const int COOKIE_LIFESPAN = 3;
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> LoginAsync(int clientId, string password, Microsoft.AspNetCore.Http.HttpContext ctx = null)
|
||||
public async Task<IActionResult> LoginAsync(int clientId, string password)
|
||||
{
|
||||
if (clientId == 0 || string.IsNullOrEmpty(password))
|
||||
{
|
||||
@ -48,13 +45,7 @@ namespace WebfrontCore.Controllers
|
||||
|
||||
var claimsIdentity = new ClaimsIdentity(claims, "login");
|
||||
var claimsPrinciple = new ClaimsPrincipal(claimsIdentity);
|
||||
await (ctx ?? HttpContext).SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, claimsPrinciple, new AuthenticationProperties()
|
||||
{
|
||||
AllowRefresh = true,
|
||||
ExpiresUtc = DateTime.UtcNow.AddMonths(COOKIE_LIFESPAN),
|
||||
IsPersistent = true,
|
||||
IssuedUtc = DateTime.UtcNow
|
||||
});
|
||||
await SignInAsync(claimsPrinciple);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
@ -238,6 +238,15 @@ namespace WebfrontCore.Controllers
|
||||
{
|
||||
var server = Manager.GetServers().First(_server => _server.EndPoint == id);
|
||||
|
||||
server.ChatHistory.Add(new SharedLibraryCore.Dtos.ChatInfo()
|
||||
{
|
||||
ClientId = Client.ClientId,
|
||||
Message = message,
|
||||
Name = Client.Name,
|
||||
ServerGame = server.GameName,
|
||||
Time = DateTime.Now
|
||||
});
|
||||
|
||||
return await Task.FromResult(RedirectToAction("ExecuteAsync", "Console", new
|
||||
{
|
||||
serverId = server.EndPoint,
|
||||
|
@ -1,4 +1,6 @@
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using SharedLibraryCore;
|
||||
@ -9,12 +11,18 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using WebfrontCore.ViewModels;
|
||||
|
||||
namespace WebfrontCore.Controllers
|
||||
{
|
||||
public class BaseController : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// life span in months
|
||||
/// </summary>
|
||||
private const int COOKIE_LIFESPAN = 3;
|
||||
|
||||
protected IManager Manager;
|
||||
protected readonly DatabaseContext Context;
|
||||
protected bool Authorized { get; set; }
|
||||
@ -55,6 +63,17 @@ namespace WebfrontCore.Controllers
|
||||
ViewBag.EnableColorCodes = Manager.GetApplicationSettings().Configuration().EnableColorCodes;
|
||||
}
|
||||
|
||||
protected async Task SignInAsync(ClaimsPrincipal claimsPrinciple)
|
||||
{
|
||||
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, claimsPrinciple, new AuthenticationProperties()
|
||||
{
|
||||
AllowRefresh = true,
|
||||
ExpiresUtc = DateTime.UtcNow.AddMonths(COOKIE_LIFESPAN),
|
||||
IsPersistent = true,
|
||||
IssuedUtc = DateTime.UtcNow
|
||||
});
|
||||
}
|
||||
|
||||
public override void OnActionExecuting(ActionExecutingContext context)
|
||||
{
|
||||
Client = Client ?? new EFClient()
|
||||
@ -99,11 +118,15 @@ namespace WebfrontCore.Controllers
|
||||
Client.Level = EFClient.Permission.Console;
|
||||
Client.CurrentAlias = new EFAlias() { Name = "IW4MAdmin" };
|
||||
Authorized = true;
|
||||
using (var controller = new AccountController())
|
||||
var claims = new[]
|
||||
{
|
||||
_ = controller.LoginAsync(1, "password", HttpContext).Result;
|
||||
}
|
||||
|
||||
new Claim(ClaimTypes.NameIdentifier, Client.CurrentAlias.Name),
|
||||
new Claim(ClaimTypes.Role, Client.Level.ToString()),
|
||||
new Claim(ClaimTypes.Sid, Client.ClientId.ToString()),
|
||||
new Claim(ClaimTypes.PrimarySid, Client.NetworkId.ToString("X"))
|
||||
};
|
||||
var claimsIdentity = new ClaimsIdentity(claims, "login");
|
||||
SignInAsync(new ClaimsPrincipal(claimsIdentity)).Wait();
|
||||
}
|
||||
|
||||
ViewBag.Authorized = Authorized;
|
||||
|
@ -73,6 +73,8 @@ namespace WebfrontCore
|
||||
mvcBuilder.AddApplicationPart(asm);
|
||||
}
|
||||
|
||||
services.AddHttpContextAccessor();
|
||||
|
||||
services.AddEntityFrameworkSqlite()
|
||||
.AddDbContext<DatabaseContext>();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user