actually purge users on deletion

This commit is contained in:
Stanley Dimant
2022-08-02 22:47:31 +02:00
parent 915152bae9
commit f794d62122
2 changed files with 47 additions and 43 deletions

View File

@@ -78,9 +78,10 @@ namespace MareSynchronosServer.Discord
var discordAuthedUser = await db.LodeStoneAuth.Include(u => u.User).FirstOrDefaultAsync(u => u.DiscordId == id); var discordAuthedUser = await db.LodeStoneAuth.Include(u => u.User).FirstOrDefaultAsync(u => u.DiscordId == id);
if (discordAuthedUser != null && discordAuthedUser.User != null) if (discordAuthedUser != null && discordAuthedUser.User != null)
{ {
logger.LogInformation("User will be purged on next round of deletions: " + discordAuthedUser.User); logger.LogInformation("Purging user: " + discordAuthedUser.User.UID);
discordAuthedUser.User.LastLoggedIn = new DateTime(1900, 1, 1).ToUniversalTime();
db.Remove(discordAuthedUser); FileCleanupService.PurgeUser(discordAuthedUser.User, db, configuration);
await db.SaveChangesAsync(); await db.SaveChangesAsync();
} }
} }
@@ -180,8 +181,6 @@ namespace MareSynchronosServer.Discord
{ {
embedBuilder.WithTitle("Failed to verify your character"); embedBuilder.WithTitle("Failed to verify your character");
embedBuilder.WithDescription("Did not find requested authentication key on your profile. Make sure you have saved *twice*, then do **/verify** again."); embedBuilder.WithDescription("Did not find requested authentication key on your profile. Make sure you have saved *twice*, then do **/verify** again.");
DiscordLodestoneMapping.TryRemove(id, out _);
db.Remove(lodestoneAuth);
} }
} }
else else

View File

@@ -113,6 +113,21 @@ namespace MareSynchronosServer
} }
foreach (var user in usersToRemove) foreach (var user in usersToRemove)
{
PurgeUser(user);
}
}
_logger.LogInformation($"Cleanup complete");
dbContext.SaveChanges();
}
catch
{
}
}
public static void PurgeUser(User user, MareDbContext dbContext, IConfiguration _configuration)
{ {
var lodestone = dbContext.LodeStoneAuth.SingleOrDefault(a => a.User.UID == user.UID); var lodestone = dbContext.LodeStoneAuth.SingleOrDefault(a => a.User.UID == user.UID);
@@ -153,16 +168,6 @@ namespace MareSynchronosServer
dbContext.Remove(auth); dbContext.Remove(auth);
dbContext.Remove(user); dbContext.Remove(user);
} }
}
_logger.LogInformation($"Cleanup complete");
dbContext.SaveChanges();
}
catch
{
}
}
public Task StopAsync(CancellationToken cancellationToken) public Task StopAsync(CancellationToken cancellationToken)
{ {