diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-10-27 23:12:48 +1100 |
---|---|---|
committer | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-10-27 23:12:48 +1100 |
commit | c00c70985c4674ccf18708b5631222b5d7dbae6e (patch) | |
tree | 5d0cd53f756150ce6b336e06ae149ca4ce2bd023 | |
parent | Try to fix loginRedirect (diff) | |
download | server-c00c70985c4674ccf18708b5631222b5d7dbae6e.tar.xz |
fix bad user validation
-rw-r--r-- | src/api/routes/users/@me/index.ts | 1 | ||||
-rw-r--r-- | src/util/entities/User.ts | 17 |
2 files changed, 10 insertions, 8 deletions
diff --git a/src/api/routes/users/@me/index.ts b/src/api/routes/users/@me/index.ts index 5eba4665..abfb333a 100644 --- a/src/api/routes/users/@me/index.ts +++ b/src/api/routes/users/@me/index.ts @@ -130,6 +130,7 @@ router.patch( } user.assign(body); + user.validate(); await user.save(); // @ts-ignore diff --git a/src/util/entities/User.ts b/src/util/entities/User.ts index 409b4f74..7f37391a 100644 --- a/src/util/entities/User.ts +++ b/src/util/entities/User.ts @@ -196,15 +196,15 @@ export class User extends BaseClass { @Column({ type: "simple-json", select: false }) extended_settings: string; - @BeforeUpdate() - _update_validator() { this.validate(true); } + // @BeforeUpdate() + // _update_validator() { this.validate(true); } - @BeforeInsert() - _insert_validator() { this.validate(false); } + // @BeforeInsert() + // _insert_validator() { this.validate(false); } - validate(update: boolean = false) { + validate(/*update: boolean = false*/) { // inserting or email provided in update - if (!update || this.email) { + if (/*!update || */this.email) { this.email = adjustEmail(this.email); if (!this.email) throw FieldErrors({ @@ -217,7 +217,7 @@ export class User extends BaseClass { } // inserting or discrim provided - if (!update || this.discriminator) { + if (/*!update ||*/ this.discriminator) { const discrim = Number(this.discriminator); if (this.discriminator.length > 4) throw FieldErrors({ @@ -243,7 +243,7 @@ export class User extends BaseClass { this.discriminator = discrim.toString().padStart(4, "0"); } - if (!update || this.username) + if (/*!update ||*/ this.username) if (BannedWords.find(this.username)) throw FieldErrors({ username: { message: "Bad username", code: "INVALID_USERNAME" }, @@ -375,6 +375,7 @@ export class User extends BaseClass { fingerprints: [], }); + user.validate(); await user.save(); setImmediate(async () => { |