Don't hash user password once again on update
authorChocobozzz <florian.bigard@gmail.com>
Sat, 4 Nov 2017 17:09:23 +0000 (18:09 +0100)
committerChocobozzz <florian.bigard@gmail.com>
Sat, 4 Nov 2017 17:09:23 +0000 (18:09 +0100)
server/models/user/user.ts

index c1e7abea6cafcb19533a0ce157e1c71b95ed2aab..b974418d4ba61a8f96190984cb3cb31599141a5d 100644 (file)
@@ -136,10 +136,13 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
 }
 
 function beforeCreateOrUpdate (user: UserInstance) {
-  return cryptPassword(user.password).then(hash => {
-    user.password = hash
-    return undefined
-  })
+  if (user.changed('password')) {
+    return cryptPassword(user.password)
+      .then(hash => {
+        user.password = hash
+        return undefined
+      })
+  }
 }
 
 // ------------------------------ METHODS ------------------------------