mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-10 05:48:39 +00:00
Add ability to approve & deny authentication attempts
This commit is contained in:
parent
70cf34dd7e
commit
d33670060b
4 changed files with 65 additions and 11 deletions
|
@ -0,0 +1,62 @@
|
|||
#nullable enable
|
||||
using System.Threading.Tasks;
|
||||
using LBPUnion.ProjectLighthouse.Types;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Controllers.ExternalAuth
|
||||
{
|
||||
[ApiController]
|
||||
[Route("/authentication")]
|
||||
public class AuthenticationController : ControllerBase
|
||||
{
|
||||
private readonly Database database;
|
||||
|
||||
public AuthenticationController(Database database)
|
||||
{
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
[HttpGet("approve/{id:int}")]
|
||||
public async Task<IActionResult> Approve(int id)
|
||||
{
|
||||
User? user = this.database.UserFromWebRequest(this.Request);
|
||||
if (user == null) return this.Redirect("/login");
|
||||
|
||||
AuthenticationAttempt? authAttempt = await this.database.AuthenticationAttempts.Include
|
||||
(a => a.GameToken)
|
||||
.FirstOrDefaultAsync(a => a.AuthenticationAttemptId == id);
|
||||
if (authAttempt == null) return this.NotFound();
|
||||
|
||||
if (authAttempt.GameToken.UserId != user.UserId) return this.StatusCode(403, "");
|
||||
|
||||
authAttempt.GameToken.Approved = true;
|
||||
this.database.AuthenticationAttempts.Remove(authAttempt);
|
||||
|
||||
await this.database.SaveChangesAsync();
|
||||
|
||||
return this.Redirect("~/authentication");
|
||||
}
|
||||
|
||||
[HttpGet("deny/{id:int}")]
|
||||
public async Task<IActionResult> Deny(int id)
|
||||
{
|
||||
User? user = this.database.UserFromWebRequest(this.Request);
|
||||
if (user == null) return this.Redirect("/login");
|
||||
|
||||
AuthenticationAttempt? authAttempt = await this.database.AuthenticationAttempts.Include
|
||||
(a => a.GameToken)
|
||||
.FirstOrDefaultAsync(a => a.AuthenticationAttemptId == id);
|
||||
if (authAttempt == null) return this.NotFound();
|
||||
|
||||
if (authAttempt.GameToken.UserId != user.UserId) return this.StatusCode(403, "");
|
||||
|
||||
this.database.GameTokens.Remove(authAttempt.GameToken);
|
||||
this.database.AuthenticationAttempts.Remove(authAttempt);
|
||||
|
||||
await this.database.SaveChangesAsync();
|
||||
|
||||
return this.Redirect("~/authentication");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,10 +22,10 @@ else
|
|||
<div class="ui red segment">
|
||||
<p>A <b>@authAttempt.Platform</b> authentication request was logged at <b>@timestamp.ToString("MM/dd/yyyy @ h:mm tt") UTC</b> from the IP address <b>@authAttempt.IPAddress</b>.</p>
|
||||
<div>
|
||||
<a href="/authentication/approve/@authAttempt.GameTokenId">
|
||||
<a href="/authentication/approve/@authAttempt.AuthenticationAttemptId">
|
||||
<button class="ui tiny green button">Approve</button>
|
||||
</a>
|
||||
<a href="/authentication/deny/@authAttempt.GameTokenId">
|
||||
<a href="/authentication/deny/@authAttempt.AuthenticationAttemptId">
|
||||
<button class="ui tiny red button">Deny</button>
|
||||
</a>
|
||||
</div>
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
<link rel="stylesheet" type="text/css" href="~/css/styles.css">
|
||||
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/fomantic-ui@2.8.8/dist/semantic.min.css">
|
||||
</head>
|
||||
<header>
|
||||
<header class="lighthouse-header">
|
||||
<div class="ui attached menu">
|
||||
<div class="ui container">
|
||||
@foreach (PageNavigationItem navigationItem in Model!.NavigationItems)
|
||||
|
|
|
@ -3,11 +3,3 @@ footer.lighthouse-footer {
|
|||
bottom: 0;
|
||||
position: fixed;
|
||||
}
|
||||
|
||||
div.authentication-attempt {
|
||||
background-color: lightgray;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
vertical-align: center;
|
||||
padding: 3px;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue