This commit is contained in:
parent
df21ca2d9f
commit
86cd5f5237
|
@ -1,7 +1,6 @@
|
||||||
const vnModel = require('vn-loopback/common/models/vn-model');
|
const vnModel = require('vn-loopback/common/models/vn-model');
|
||||||
const LoopBackContext = require('loopback-context');
|
const LoopBackContext = require('loopback-context');
|
||||||
const {Email} = require('vn-print');
|
const {Email} = require('vn-print');
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
|
||||||
|
|
||||||
module.exports = function(Self) {
|
module.exports = function(Self) {
|
||||||
vnModel(Self);
|
vnModel(Self);
|
||||||
|
@ -109,10 +108,12 @@ module.exports = function(Self) {
|
||||||
return email.send();
|
return email.send();
|
||||||
});
|
});
|
||||||
|
|
||||||
const _setPassword = Self.setPassword;
|
const _setPassword = Self.prototype.setPassword;
|
||||||
Self.setPassword = async function(id, newPassword, options) {
|
Self.prototype.setPassword = async function(newPassword, options, cb) {
|
||||||
if (typeof options === 'function')
|
if (cb === undefined && typeof options === 'function') {
|
||||||
|
cb = options;
|
||||||
options = undefined;
|
options = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
let tx;
|
let tx;
|
||||||
|
@ -127,15 +128,15 @@ module.exports = function(Self) {
|
||||||
options = myOptions;
|
options = myOptions;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await Self.rawSql(`CALL account.user_setPassword(?, ?)`, [id, newPassword], options);
|
await Self.rawSql(`CALL account.user_checkPassword(?)`, [newPassword], options);
|
||||||
await _setPassword.call(this, id, newPassword, options);
|
await _setPassword.call(this, newPassword, options);
|
||||||
const user = await Self.findById(id, {fields: ['id', 'name']}, options);
|
await this.updateAttribute('passExpired', null, options);
|
||||||
await user.updateAttribute('passExpired', null, options);
|
await Self.app.models.Account.sync(this.name, newPassword, null, options);
|
||||||
await models.Account.sync(user.name, newPassword);
|
tx && await tx.commit();
|
||||||
if (tx) await tx.commit();
|
cb && cb();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (tx) await tx.rollback();
|
tx && await tx.rollback();
|
||||||
throw err;
|
if (cb) cb(err); else throw err;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,8 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.syncById = async function(id, password, force) {
|
Self.syncById = async function(id, password, force, options) {
|
||||||
let user = await Self.app.models.VnUser.findById(id, {fields: ['name']});
|
let user = await Self.app.models.VnUser.findById(id, {fields: ['name']}, options);
|
||||||
await Self.sync(user.name, password, force);
|
await Self.sync(user.name, password, force, options);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -24,17 +24,17 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.sync = async function(userName, password, force) {
|
Self.sync = async function(userName, password, force, options) {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const user = await models.VnUser.findOne({
|
const user = await models.VnUser.findOne({
|
||||||
fields: ['id'],
|
fields: ['id'],
|
||||||
where: {name: userName}
|
where: {name: userName}
|
||||||
});
|
}, options);
|
||||||
const isSync = !await models.UserSync.exists(userName);
|
const isSync = !await models.UserSync.exists(userName, options);
|
||||||
|
|
||||||
if (!force && isSync && user) return;
|
if (!force && isSync && user) return;
|
||||||
await models.AccountConfig.syncUser(userName, password);
|
await models.AccountConfig.syncUser(userName, password);
|
||||||
await models.UserSync.destroyById(userName);
|
await models.UserSync.destroyById(userName, options);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue