Added autodelete for users after one year inactivity

This commit is contained in:
Sarah Faey 2022-12-08 17:37:00 +01:00
parent c886c6475e
commit 929ca9c0a7
7 changed files with 730 additions and 2 deletions

View file

@ -318,5 +318,20 @@ namespace Lieb.Data
return usableAccounts.First().GuildWars2AccountId;
}
}
public async Task DeleteInactiveUsers()
{
using var context = _contextFactory.CreateDbContext();
List<LiebUser> users = context.LiebUsers.ToList();
foreach(LiebUser user in users)
{
if((user.LastSignUpAt == null && user.CreatedAt < DateTime.UtcNow.AddYears(-1))
|| (user.LastSignUpAt != null && user.LastSignUpAt < DateTime.UtcNow.AddYears(-1)))
{
await DeleteUser(user.Id);
}
}
}
}
}