mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
feature(auth) add config
This commit is contained in:
parent
af97f8e669
commit
c7b8efa4dc
2 changed files with 22 additions and 24 deletions
|
|
@ -22,7 +22,7 @@
|
|||
webconsole,
|
||||
|
||||
emptyFunc = function(req, res, next) {
|
||||
Util.exec(next);
|
||||
next();
|
||||
};
|
||||
|
||||
emptyFunc.middle = function() {
|
||||
|
|
@ -34,7 +34,6 @@
|
|||
Util.log(error.message);
|
||||
}) || emptyFunc;
|
||||
|
||||
|
||||
module.exports = function(params) {
|
||||
var keys,
|
||||
p = params || {},
|
||||
|
|
@ -68,21 +67,19 @@
|
|||
var isOption = function(name) {
|
||||
return config(name);
|
||||
},
|
||||
|
||||
|
||||
isMinify = isOption.bind(null, 'minify'),
|
||||
isOnline = isOption.bind(null, 'online'),
|
||||
isCache = isOption.bind(null, 'cache'),
|
||||
|
||||
authFunc = config('auth') ? auth() : emptyFunc,
|
||||
|
||||
ponseStatic = ponse.static(DIR_ROOT, {
|
||||
cache: isCache
|
||||
}),
|
||||
|
||||
funcs = [
|
||||
auth({
|
||||
auth: config('auth'),
|
||||
username: config('username'),
|
||||
password: config('password')
|
||||
}),
|
||||
authFunc,
|
||||
rest,
|
||||
route,
|
||||
|
||||
|
|
|
|||
|
|
@ -1,31 +1,32 @@
|
|||
(function() {
|
||||
'use strict';
|
||||
|
||||
var crypto = require('crypto'),
|
||||
var DIR = './',
|
||||
DIR_LIB = DIR + '../',
|
||||
crypto = require('crypto'),
|
||||
|
||||
tryRequire = require(DIR + 'tryRequire'),
|
||||
config = require(DIR + 'config'),
|
||||
Util = require(DIR_LIB + 'util'),
|
||||
|
||||
tryRequire = require('./tryRequire'),
|
||||
oldPass,
|
||||
oldName;
|
||||
|
||||
module.exports = function(config) {
|
||||
module.exports = function() {
|
||||
var type, httpAuth,
|
||||
|
||||
middle = function(req, res, next) {
|
||||
next();
|
||||
};
|
||||
|
||||
if (!config)
|
||||
config = {
|
||||
auth: false
|
||||
};
|
||||
httpAuth = tryRequire('http-auth', function(error) {
|
||||
if (error)
|
||||
Util.log(error.message);
|
||||
});
|
||||
|
||||
if (config.auth) {
|
||||
httpAuth = tryRequire('http-auth');
|
||||
|
||||
if (httpAuth) {
|
||||
type = init(httpAuth, config);
|
||||
middle = httpAuth.connect(type);
|
||||
}
|
||||
if (httpAuth) {
|
||||
type = init(httpAuth, config);
|
||||
middle = httpAuth.connect(type);
|
||||
}
|
||||
|
||||
return middle;
|
||||
|
|
@ -36,8 +37,8 @@
|
|||
realm: 'Cloud Commander'
|
||||
}, function (username, password, callback) { // Custom authentication method.
|
||||
var hash,
|
||||
name = config.username,
|
||||
passwd = config.password,
|
||||
name = config('username'),
|
||||
passwd = config('password'),
|
||||
equal = username === name,
|
||||
sha = crypto.createHash('sha1');
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue