refs #5472 fix sync
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Alex Moreno 2023-06-02 15:07:02 +02:00
parent df21ca2d9f
commit 86cd5f5237
3 changed files with 20 additions and 19 deletions

View File

@ -1,7 +1,6 @@
const vnModel = require('vn-loopback/common/models/vn-model');
const LoopBackContext = require('loopback-context');
const {Email} = require('vn-print');
const UserError = require('vn-loopback/util/user-error');
module.exports = function(Self) {
vnModel(Self);
@ -109,10 +108,12 @@ module.exports = function(Self) {
return email.send();
});
const _setPassword = Self.setPassword;
Self.setPassword = async function(id, newPassword, options) {
if (typeof options === 'function')
const _setPassword = Self.prototype.setPassword;
Self.prototype.setPassword = async function(newPassword, options, cb) {
if (cb === undefined && typeof options === 'function') {
cb = options;
options = undefined;
}
const myOptions = {};
let tx;
@ -127,15 +128,15 @@ module.exports = function(Self) {
options = myOptions;
try {
await Self.rawSql(`CALL account.user_setPassword(?, ?)`, [id, newPassword], options);
await _setPassword.call(this, id, newPassword, options);
const user = await Self.findById(id, {fields: ['id', 'name']}, options);
await user.updateAttribute('passExpired', null, options);
await models.Account.sync(user.name, newPassword);
if (tx) await tx.commit();
await Self.rawSql(`CALL account.user_checkPassword(?)`, [newPassword], options);
await _setPassword.call(this, newPassword, options);
await this.updateAttribute('passExpired', null, options);
await Self.app.models.Account.sync(this.name, newPassword, null, options);
tx && await tx.commit();
cb && cb();
} catch (err) {
if (tx) await tx.rollback();
throw err;
tx && await tx.rollback();
if (cb) cb(err); else throw err;
}
};

View File

@ -24,8 +24,8 @@ module.exports = Self => {
}
});
Self.syncById = async function(id, password, force) {
let user = await Self.app.models.VnUser.findById(id, {fields: ['name']});
await Self.sync(user.name, password, force);
Self.syncById = async function(id, password, force, options) {
let user = await Self.app.models.VnUser.findById(id, {fields: ['name']}, options);
await Self.sync(user.name, password, force, options);
};
};

View File

@ -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 user = await models.VnUser.findOne({
fields: ['id'],
where: {name: userName}
});
const isSync = !await models.UserSync.exists(userName);
}, options);
const isSync = !await models.UserSync.exists(userName, options);
if (!force && isSync && user) return;
await models.AccountConfig.syncUser(userName, password);
await models.UserSync.destroyById(userName);
await models.UserSync.destroyById(userName, options);
};
};