mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 11:37:08 +00:00
Refactor JWT credentials check to use class User
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
const crypto = require('crypto');
|
||||
const JWT = require('jsonwebtoken');
|
||||
const cfg = require('./config');
|
||||
const ServerUser = require('./db/user/User');
|
||||
|
||||
|
||||
function checkValidCredentials ({user, password, jwt}) {
|
||||
async function checkValidCredentials ({user, password, jwt}) {
|
||||
if (jwt) {
|
||||
try {
|
||||
const decoded = JWT.verify(jwt, cfg.jwt.secret, {maxAge: "1d"});
|
||||
@@ -16,16 +16,7 @@ function checkValidCredentials ({user, password, jwt}) {
|
||||
return; // Invalid JWT
|
||||
}
|
||||
} else if (user && password) {
|
||||
const hash = crypto
|
||||
.pbkdf2Sync(password, 'Dougal'+user, 10712, 48, 'sha512')
|
||||
.toString('base64');
|
||||
for (const credentials of cfg._("global.users.login.user") || []) {
|
||||
if (credentials.name == user && credentials.hash == hash) {
|
||||
const payload = {...credentials};
|
||||
delete payload.hash;
|
||||
return payload;
|
||||
}
|
||||
}
|
||||
return (await ServerUser.authenticateSQL(user, password))?.toJSON();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user