fix exception in update endpoint
This commit is contained in:
parent
d8ba680d34
commit
13c6261915
1 changed files with 44 additions and 39 deletions
|
@ -66,7 +66,9 @@ public static class Routes
|
|||
}, Utilities.JsonSerializerOptions);
|
||||
}
|
||||
// Validate new username
|
||||
if (!string.IsNullOrWhiteSpace(payload.username) && !Utilities.ValidateUsername(payload.username))
|
||||
if (!string.IsNullOrWhiteSpace(payload.username))
|
||||
{
|
||||
if (!Utilities.ValidateUsername(payload.username))
|
||||
{
|
||||
return Results.Json(new UpdateResponse
|
||||
{
|
||||
|
@ -74,24 +76,6 @@ public static class Routes
|
|||
error = "Usernames can contain only numbers, letters, spaces, dashes, underscores, and dots, and must be between 3 and 20 characters."
|
||||
}, Utilities.JsonSerializerOptions);
|
||||
}
|
||||
// Validate new E-Mail
|
||||
if (!string.IsNullOrWhiteSpace(payload.email) && !new EmailAddressAttribute().IsValid(payload.email))
|
||||
{
|
||||
return Results.Json(new UpdateResponse
|
||||
{
|
||||
success = false,
|
||||
error = "Malformed E-Mail address."
|
||||
}, Utilities.JsonSerializerOptions);
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(payload.email) && Program.Config.Registration.EmailDomainWhitelist &&
|
||||
!Program.Config.Registration.AllowedEmailDomains.Contains(payload.email.Split("@")[1]))
|
||||
{
|
||||
return Results.Json(new UpdateResponse
|
||||
{
|
||||
success = false,
|
||||
error = "That E-Mail domain is not allowed."
|
||||
}, Utilities.JsonSerializerOptions);
|
||||
}
|
||||
// Make sure username isn't taken
|
||||
var _user = await Program.Database.GetUser(payload.username);
|
||||
if (_user != null)
|
||||
|
@ -103,8 +87,28 @@ public static class Routes
|
|||
error = "That username is taken."
|
||||
}, Utilities.JsonSerializerOptions);
|
||||
}
|
||||
}
|
||||
// Validate new E-Mail
|
||||
if (!string.IsNullOrWhiteSpace(payload.email))
|
||||
{
|
||||
if (!new EmailAddressAttribute().IsValid(payload.email))
|
||||
{
|
||||
return Results.Json(new UpdateResponse
|
||||
{
|
||||
success = false,
|
||||
error = "Malformed E-Mail address."
|
||||
}, Utilities.JsonSerializerOptions);
|
||||
}
|
||||
if (Program.Config.Registration.EmailDomainWhitelist && !Program.Config.Registration.AllowedEmailDomains.Contains(payload.email.Split("@")[1]))
|
||||
{
|
||||
return Results.Json(new UpdateResponse
|
||||
{
|
||||
success = false,
|
||||
error = "That E-Mail domain is not allowed."
|
||||
}, Utilities.JsonSerializerOptions);
|
||||
}
|
||||
// Check if E-Mail is in use
|
||||
_user = await Program.Database.GetUser(email: payload.email);
|
||||
var _user = await Program.Database.GetUser(email: payload.email);
|
||||
if (_user != null)
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
|
@ -114,6 +118,7 @@ public static class Routes
|
|||
error = "That E-Mail is already in use."
|
||||
}, Utilities.JsonSerializerOptions);
|
||||
}
|
||||
}
|
||||
// Validate new password
|
||||
if (!string.IsNullOrWhiteSpace(payload.newPassword))
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue