修改政府端前端,银行端小程序和后端接口
This commit is contained in:
@@ -16,6 +16,9 @@ class User extends BaseModel {
|
||||
*/
|
||||
async validPassword(password) {
|
||||
try {
|
||||
if (!password || !this.password) {
|
||||
return false;
|
||||
}
|
||||
const bcrypt = require('bcryptjs');
|
||||
return await bcrypt.compare(password, this.password);
|
||||
} catch (error) {
|
||||
@@ -178,12 +181,12 @@ User.init({
|
||||
updatedAt: 'updated_at',
|
||||
hooks: {
|
||||
beforeCreate: async (user) => {
|
||||
if (user.password) {
|
||||
if (user.password && !user.password.startsWith('$2a$')) {
|
||||
user.password = await bcrypt.hash(user.password, 10);
|
||||
}
|
||||
},
|
||||
beforeUpdate: async (user) => {
|
||||
if (user.changed('password')) {
|
||||
if (user.changed('password') && user.password && !user.password.startsWith('$2a$')) {
|
||||
user.password = await bcrypt.hash(user.password, 10);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user