mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-06 02:32:28 +00:00
Move servers to LBPU.PL.Servers
This commit is contained in:
parent
545b5a0709
commit
b2ec7eae57
116 changed files with 173 additions and 162 deletions
|
@ -1,65 +0,0 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.Types;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Website.Controllers.ExternalAuth;
|
||||
|
||||
[ApiController]
|
||||
[Route("/authentication")]
|
||||
public class AutoApprovalController : ControllerBase
|
||||
{
|
||||
private readonly Database database;
|
||||
|
||||
public AutoApprovalController(Database database)
|
||||
{
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
[HttpGet("autoApprove/{id:int}")]
|
||||
public async Task<IActionResult> AutoApprove([FromRoute] 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.BadRequest();
|
||||
if (authAttempt.GameToken.UserId != user.UserId) return this.Redirect("/login");
|
||||
|
||||
authAttempt.GameToken.Approved = true;
|
||||
|
||||
UserApprovedIpAddress approvedIpAddress = new()
|
||||
{
|
||||
UserId = user.UserId,
|
||||
User = user,
|
||||
IpAddress = authAttempt.IPAddress,
|
||||
};
|
||||
|
||||
this.database.UserApprovedIpAddresses.Add(approvedIpAddress);
|
||||
this.database.AuthenticationAttempts.Remove(authAttempt);
|
||||
|
||||
await this.database.SaveChangesAsync();
|
||||
|
||||
return this.Redirect("/authentication");
|
||||
}
|
||||
|
||||
[HttpGet("revokeAutoApproval/{id:int}")]
|
||||
public async Task<IActionResult> RevokeAutoApproval([FromRoute] int id)
|
||||
{
|
||||
User? user = this.database.UserFromWebRequest(this.Request);
|
||||
if (user == null) return this.Redirect("/login");
|
||||
|
||||
UserApprovedIpAddress? approvedIpAddress = await this.database.UserApprovedIpAddresses.FirstOrDefaultAsync(a => a.UserApprovedIpAddressId == id);
|
||||
if (approvedIpAddress == null) return this.BadRequest();
|
||||
if (approvedIpAddress.UserId != user.UserId) return this.Redirect("/login");
|
||||
|
||||
this.database.UserApprovedIpAddresses.Remove(approvedIpAddress);
|
||||
|
||||
await this.database.SaveChangesAsync();
|
||||
|
||||
return this.Redirect("/authentication/autoApprovals");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue