Fix user validator preventing update
This commit is contained in:
parent
ff28c95f2a
commit
add54e6b68
@ -197,8 +197,14 @@ export class User extends BaseClass {
|
|||||||
extended_settings: string;
|
extended_settings: string;
|
||||||
|
|
||||||
@BeforeUpdate()
|
@BeforeUpdate()
|
||||||
|
_update_validator() { this.validate(true); }
|
||||||
|
|
||||||
@BeforeInsert()
|
@BeforeInsert()
|
||||||
validate() {
|
_insert_validator() { this.validate(false); }
|
||||||
|
|
||||||
|
validate(update: boolean = false) {
|
||||||
|
// inserting or email provided in update
|
||||||
|
if (!update || this.email) {
|
||||||
this.email = adjustEmail(this.email);
|
this.email = adjustEmail(this.email);
|
||||||
if (!this.email)
|
if (!this.email)
|
||||||
throw FieldErrors({
|
throw FieldErrors({
|
||||||
@ -208,7 +214,10 @@ export class User extends BaseClass {
|
|||||||
throw FieldErrors({
|
throw FieldErrors({
|
||||||
email: { message: "Invalid email", code: "EMAIL_INVALID" },
|
email: { message: "Invalid email", code: "EMAIL_INVALID" },
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// inserting or discrim provided
|
||||||
|
if (!update || this.discriminator) {
|
||||||
const discrim = Number(this.discriminator);
|
const discrim = Number(this.discriminator);
|
||||||
if (this.discriminator.length > 4)
|
if (this.discriminator.length > 4)
|
||||||
throw FieldErrors({
|
throw FieldErrors({
|
||||||
@ -232,7 +241,9 @@ export class User extends BaseClass {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
this.discriminator = discrim.toString().padStart(4, "0");
|
this.discriminator = discrim.toString().padStart(4, "0");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!update || this.username)
|
||||||
if (BannedWords.find(this.username))
|
if (BannedWords.find(this.username))
|
||||||
throw FieldErrors({
|
throw FieldErrors({
|
||||||
username: { message: "Bad username", code: "INVALID_USERNAME" },
|
username: { message: "Bad username", code: "INVALID_USERNAME" },
|
||||||
@ -436,7 +447,7 @@ export interface UserSettings {
|
|||||||
disable_games_tab: boolean;
|
disable_games_tab: boolean;
|
||||||
enable_tts_command: boolean;
|
enable_tts_command: boolean;
|
||||||
explicit_content_filter: number;
|
explicit_content_filter: number;
|
||||||
friend_source_flags: { all: boolean };
|
friend_source_flags: { all: boolean; };
|
||||||
gateway_connected: boolean;
|
gateway_connected: boolean;
|
||||||
gif_auto_play: boolean;
|
gif_auto_play: boolean;
|
||||||
// every top guild is displayed as a "folder"
|
// every top guild is displayed as a "folder"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user