mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-09-22 17:29:10 +00:00
Add WipeTokensForUserCommand and DeleteAllTokensMaintenanceJob
This commit is contained in:
parent
c0c42dc06c
commit
f8d6c90e62
3 changed files with 68 additions and 4 deletions
|
@ -0,0 +1,46 @@
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace LBPUnion.ProjectLighthouse.Maintenance.Commands
|
||||||
|
{
|
||||||
|
public class WipeTokensForUserCommand : ICommand
|
||||||
|
{
|
||||||
|
private readonly Database database = new();
|
||||||
|
|
||||||
|
public string Name() => "Wipe tokens for user";
|
||||||
|
public string[] Aliases()
|
||||||
|
=> new[]
|
||||||
|
{
|
||||||
|
"wipeTokens", "wipeToken", "deleteTokens", "deleteToken", "removeTokens", "removeToken",
|
||||||
|
};
|
||||||
|
public string Arguments() => "<username/userId>";
|
||||||
|
public int RequiredArgs() => 1;
|
||||||
|
public async Task Run(string[] args)
|
||||||
|
{
|
||||||
|
User? user = await this.database.Users.FirstOrDefaultAsync(u => u.Username == args[0]);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
user = await this.database.Users.FirstOrDefaultAsync(u => u.UserId == Convert.ToInt32(args[0]));
|
||||||
|
if (user == null) throw new Exception();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Could not find user by parameter '{args[0]}'");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.database.GameTokens.RemoveRange(this.database.GameTokens.Where(t => t.UserId == user.UserId));
|
||||||
|
this.database.WebTokens.RemoveRange(this.database.WebTokens.Where(t => t.UserId == user.UserId));
|
||||||
|
|
||||||
|
await this.database.SaveChangesAsync();
|
||||||
|
|
||||||
|
Console.WriteLine($"Deleted all tokens for {user.Username} (id: {user.UserId}).");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LBPUnion.ProjectLighthouse.Maintenance.MaintenanceJobs
|
||||||
|
{
|
||||||
|
public class DeleteAllTokensMaintenanceJob : IMaintenanceJob
|
||||||
|
{
|
||||||
|
private readonly Database database = new();
|
||||||
|
|
||||||
|
public string Name() => "Delete ALL Tokens";
|
||||||
|
public string Description() => "Deletes ALL game tokens and web tokens.";
|
||||||
|
public async Task Run()
|
||||||
|
{
|
||||||
|
this.database.GameTokens.RemoveRange(this.database.GameTokens);
|
||||||
|
this.database.WebTokens.RemoveRange(this.database.WebTokens);
|
||||||
|
|
||||||
|
await this.database.SaveChangesAsync();
|
||||||
|
|
||||||
|
Console.WriteLine("Deleted ALL tokens.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -33,10 +33,6 @@
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="CommandLine"/>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
|
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
|
||||||
<Exec Command="git describe --long --always --dirty --exclude=\* --abbrev=8 > "$(ProjectDir)/gitVersion.txt""/>
|
<Exec Command="git describe --long --always --dirty --exclude=\* --abbrev=8 > "$(ProjectDir)/gitVersion.txt""/>
|
||||||
<Exec Command="git branch --show-current > "$(ProjectDir)/gitBranch.txt""/>
|
<Exec Command="git branch --show-current > "$(ProjectDir)/gitBranch.txt""/>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue