X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fuser%2Fuser.ts;h=c5c8a1b30d815a08ac57e789e04d40e7a15e4625;hb=e364e31e25bd1d4b8d801c845a96d6be708f0a18;hp=0932a367a3c0ea76f998284c136fcb8341c6de1c;hpb=bc48e33b80f357767b98c1d310b04bdda24c6d46;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/user/user.ts b/server/models/user/user.ts index 0932a367a..c5c8a1b30 100644 --- a/server/models/user/user.ts +++ b/server/models/user/user.ts @@ -441,16 +441,17 @@ export class UserModel extends Model>> { }) OAuthTokens: OAuthTokenModel[] + // Used if we already set an encrypted password in user model + skipPasswordEncryption = false + @BeforeCreate @BeforeUpdate - static cryptPasswordIfNeeded (instance: UserModel) { - if (instance.changed('password') && instance.password) { - return cryptPassword(instance.password) - .then(hash => { - instance.password = hash - return undefined - }) - } + static async cryptPasswordIfNeeded (instance: UserModel) { + if (instance.skipPasswordEncryption) return + if (!instance.changed('password')) return + if (!instance.password) return + + instance.password = await cryptPassword(instance.password) } @AfterUpdate