mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-10 15:20:48 -05:00
RCon error handling is clearer
Show chat on mobile view of server overview basic authentication switched to extreme-ip-lookup for ip lookups (SSL)
This commit is contained in:
40
WebfrontCore/Controllers/AccountController.cs
Normal file
40
WebfrontCore/Controllers/AccountController.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace WebfrontCore.Controllers
|
||||
{
|
||||
public class AccountController : BaseController
|
||||
{
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Login(int userId, string password)
|
||||
{
|
||||
if (userId == 0 || string.IsNullOrEmpty(password))
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
var client = IW4MAdmin.Program.ServerManager.PrivilegedClients[userId];
|
||||
string[] hashedPassword = await Task.FromResult(SharedLibrary.Helpers.Hashing.Hash(password, client.PasswordSalt));
|
||||
|
||||
if (hashedPassword[0] == client.Password)
|
||||
{
|
||||
var claims = new[]
|
||||
{
|
||||
new Claim(ClaimTypes.NameIdentifier, client.Name),
|
||||
new Claim(ClaimTypes.Role, client.Level.ToString()),
|
||||
new Claim(ClaimTypes.Sid, client.ClientId.ToString())
|
||||
};
|
||||
|
||||
var claimsIdentity = new ClaimsIdentity(claims, "login");
|
||||
var claimsPrinciple = new ClaimsPrincipal(claimsIdentity);
|
||||
await HttpContext.Authentication.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, claimsPrinciple);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
return Unauthorized();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user