mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
fix(auth) always show auth dialog
This commit is contained in:
parent
90cc76e6c7
commit
f33cb44306
1 changed files with 42 additions and 41 deletions
|
|
@ -11,49 +11,50 @@
|
|||
oldName;
|
||||
|
||||
module.exports = function() {
|
||||
var middle, type;
|
||||
|
||||
type = init(config);
|
||||
middle = httpAuth.connect(type);
|
||||
|
||||
return middle;
|
||||
};
|
||||
|
||||
function init(config) {
|
||||
var auth = httpAuth.basic({
|
||||
realm: 'Cloud Commander'
|
||||
}, function (username, password, callback) {
|
||||
var hash,
|
||||
is = config('auth'),
|
||||
name = config('username'),
|
||||
pass = config('password'),
|
||||
equal = username === name,
|
||||
algo = config('algo');
|
||||
|
||||
if (!is) {
|
||||
equal = true;
|
||||
} else {
|
||||
if (!oldPass)
|
||||
oldPass = pass;
|
||||
|
||||
if (!oldName)
|
||||
oldName = name;
|
||||
|
||||
if (!equal)
|
||||
username === oldName;
|
||||
|
||||
hash = cryptPassword(algo, password);
|
||||
equal = pass === hash && equal;
|
||||
|
||||
if (!equal) {
|
||||
hash = cryptPassword(algo, oldPass);
|
||||
equal = pass === hash && equal;
|
||||
}
|
||||
}
|
||||
|
||||
callback(equal);
|
||||
});
|
||||
}, check);
|
||||
|
||||
return auth;
|
||||
return middle(auth);
|
||||
};
|
||||
|
||||
function middle(authentication) {
|
||||
return function(req, res, next) {
|
||||
var is = config('auth');
|
||||
|
||||
if (!is)
|
||||
next();
|
||||
else
|
||||
authentication.check(req, res, function(/* success */) {
|
||||
next();
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function check(username, password, callback) {
|
||||
var hash,
|
||||
name = config('username'),
|
||||
pass = config('password'),
|
||||
equal = username === name,
|
||||
algo = config('algo');
|
||||
|
||||
if (!oldPass)
|
||||
oldPass = pass;
|
||||
|
||||
if (!oldName)
|
||||
oldName = name;
|
||||
|
||||
if (!equal)
|
||||
username === oldName;
|
||||
|
||||
hash = cryptPassword(algo, password);
|
||||
equal = pass === hash && equal;
|
||||
|
||||
if (!equal) {
|
||||
hash = cryptPassword(algo, oldPass);
|
||||
equal = pass === hash && equal;
|
||||
}
|
||||
|
||||
callback(equal);
|
||||
}
|
||||
})();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue