mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
chore(auth) es2015-ify
This commit is contained in:
parent
c6cdd7c66a
commit
8e3e40d790
1 changed files with 38 additions and 43 deletions
|
|
@ -1,47 +1,42 @@
|
|||
(function() {
|
||||
'use strict';
|
||||
'use strict';
|
||||
|
||||
const httpAuth = require('http-auth');
|
||||
const criton = require('criton');
|
||||
|
||||
const config = require('./config');
|
||||
|
||||
module.exports = () => {
|
||||
const auth = httpAuth.basic({
|
||||
realm: 'Cloud Commander'
|
||||
}, check);
|
||||
|
||||
var DIR = './',
|
||||
return middle(auth);
|
||||
};
|
||||
|
||||
function middle(authentication) {
|
||||
return (req, res, next) => {
|
||||
const is = config('auth');
|
||||
|
||||
httpAuth = require('http-auth'),
|
||||
criton = require('criton'),
|
||||
config = require(DIR + 'config');
|
||||
|
||||
module.exports = function() {
|
||||
var auth = httpAuth.basic({
|
||||
realm: 'Cloud Commander'
|
||||
}, check);
|
||||
|
||||
return middle(auth);
|
||||
};
|
||||
|
||||
function middle(authentication) {
|
||||
return function(req, res, next) {
|
||||
var is = config('auth');
|
||||
if (!is)
|
||||
return next();
|
||||
|
||||
if (!is)
|
||||
next();
|
||||
else
|
||||
authentication.check(req, res, function(/* success */) {
|
||||
next();
|
||||
});
|
||||
};
|
||||
}
|
||||
const success = () => next(/* success */);
|
||||
authentication.check(req, res, success);
|
||||
};
|
||||
}
|
||||
|
||||
function check(username, password, callback) {
|
||||
const BAD_CREDENTIALS = false;
|
||||
const name = config('username');
|
||||
const pass = config('password');
|
||||
const algo = config('algo');
|
||||
|
||||
function check(username, password, callback) {
|
||||
var BAD_CREDENTIALS = false,
|
||||
sameName,
|
||||
samePass,
|
||||
name = config('username'),
|
||||
pass = config('password'),
|
||||
algo = config('algo');
|
||||
|
||||
if (!password)
|
||||
return callback(BAD_CREDENTIALS);
|
||||
|
||||
sameName = username === name;
|
||||
samePass = pass === criton(password, algo);
|
||||
|
||||
callback(sameName && samePass);
|
||||
}
|
||||
})();
|
||||
if (!password)
|
||||
return callback(BAD_CREDENTIALS);
|
||||
|
||||
const sameName = username === name;
|
||||
const samePass = pass === criton(password, algo);
|
||||
|
||||
callback(sameName && samePass);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue