Merge branch 'dev' into 5652-fixtures-fix
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
commit
d246b5f9a8
|
@ -1,3 +1,7 @@
|
|||
CREATE ROLE 'salix';
|
||||
GRANT 'salix' TO 'root'@'%';
|
||||
SET DEFAULT ROLE 'salix' FOR 'root'@'%';
|
||||
|
||||
CREATE SCHEMA IF NOT EXISTS `vn2008`;
|
||||
CREATE SCHEMA IF NOT EXISTS `tmp`;
|
||||
|
||||
|
|
|
@ -26,24 +26,46 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
Self.sync = async function(userName, password, force, options) {
|
||||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
|
||||
let tx;
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
const models = Self.app.models;
|
||||
const user = await models.VnUser.findOne({
|
||||
fields: ['id', 'password'],
|
||||
where: {name: userName}
|
||||
}, myOptions);
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
};
|
||||
|
||||
if (user && password && !await user.hasPassword(password))
|
||||
throw new ForbiddenError('Wrong password');
|
||||
try {
|
||||
const user = await models.VnUser.findOne({
|
||||
fields: ['id', 'password'],
|
||||
where: {name: userName}
|
||||
}, myOptions);
|
||||
|
||||
const isSync = !await models.UserSync.exists(userName, myOptions);
|
||||
if (user && password && !await user.hasPassword(password))
|
||||
throw new ForbiddenError('Wrong password');
|
||||
|
||||
if (!force && isSync && user) return;
|
||||
await models.AccountConfig.syncUser(userName, password);
|
||||
await models.UserSync.destroyById(userName, myOptions);
|
||||
const isSync = !await models.UserSync.exists(userName, myOptions);
|
||||
|
||||
if (!force && isSync && user) {
|
||||
if (tx) await tx.rollback();
|
||||
return;
|
||||
}
|
||||
|
||||
await Self.rawSql(`
|
||||
SELECT id
|
||||
FROM account.user
|
||||
WHERE id = ?
|
||||
FOR UPDATE`, [user.id], myOptions);
|
||||
|
||||
await models.AccountConfig.syncUser(userName, password);
|
||||
await models.UserSync.destroyById(userName, myOptions);
|
||||
if (tx) await tx.commit();
|
||||
} catch (err) {
|
||||
if (tx) await tx.rollback();
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue