Don't issue registration tokens for names that already exist

This commit is contained in:
Slendy 2022-11-13 22:17:41 -06:00
parent 75de1d0faa
commit e67abe0164
No known key found for this signature in database
GPG key ID: 7288D68361B91428
2 changed files with 21 additions and 5 deletions

View file

@ -83,6 +83,12 @@ public class UserEndpoints : ApiEndpointController
APIKey? apiKey = await this.database.APIKeys.FirstOrDefaultAsync(k => k.Key == authToken);
if (apiKey == null) return this.StatusCode(403, null);
if (!string.IsNullOrWhiteSpace(username))
{
bool userExists = await this.database.Users.AnyAsync(u => u.Username == username);
if (userExists) return this.BadRequest();
}
RegistrationToken token = new()
{
Created = DateTime.Now,