You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.5 KiB

const passwdStrength = require('passwd-strength');
module.exports = (shepherd) => {
/*
* type: GET
*
*/
7 years ago
shepherd.get('/auth/status', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
let successObj;
let _status = false;
7 years ago
if (Object.keys(shepherd.coindInstanceRegistry).length) {
if (Object.keys(shepherd.electrumCoins).length > 1 &&
shepherd.electrumCoins.auth) {
_status = true;
} else if (
Object.keys(shepherd.electrumCoins).length === 1 &&
!shepherd.electrumCoins.auth
) {
7 years ago
_status = true;
}
} else if (
Object.keys(shepherd.electrumCoins).length > 1 &&
shepherd.electrumCoins.auth
) {
_status = true;
} else if (
Object.keys(shepherd.electrumCoins).length === 1 &&
!Object.keys(shepherd.coindInstanceRegistry).length
) {
_status = true;
}
7 years ago
successObj = {
status: _status ? 'unlocked' : 'locked',
};
res.end(JSON.stringify(successObj));
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
7 years ago
res.end(JSON.stringify(errorObj));
}
});
7 years ago
shepherd.checkToken = (token) => {
if (token === shepherd.appSessionHash ||
process.argv.indexOf('devmode') > -1) {
return true;
}
};
shepherd.checkStringEntropy = (str) => {
// https://tools.ietf.org/html/rfc4086#page-35
return passwdStrength(str) < 29 ? false : true;
};
return shepherd;
};