27 lines
1014 B
JavaScript
27 lines
1014 B
JavaScript
const crypto = require('crypto');
|
|
|
|
async function collectLocalControlUsers(pool) {
|
|
const [rows] = await pool.query(
|
|
`SELECT DISTINCT u.username, u.password_hash, u.password_salt
|
|
FROM a_users u
|
|
JOIN a_user_roles ur ON ur.user_id = u.id
|
|
JOIN a_role_permissions rp ON rp.role_id = ur.role_id
|
|
JOIN a_permissions p ON p.id = rp.permission_id
|
|
WHERE u.account_locked = 0
|
|
AND u.must_change_password = 0
|
|
AND p.permission_key = 'clients.allow'
|
|
ORDER BY u.username ASC`
|
|
);
|
|
return (rows || []).map(function (user) {
|
|
return {
|
|
username_hash: crypto.createHash('sha256').update(String(user && user.username || '').trim()).digest('hex'),
|
|
password_hash: String(user && user.password_hash || '').trim(),
|
|
password_salt: String(user && user.password_salt || '').trim()
|
|
};
|
|
}).filter(function (user) {
|
|
return Boolean(user.username_hash && user.password_hash && user.password_salt);
|
|
});
|
|
}
|
|
|
|
module.exports = { collectLocalControlUsers };
|