feature(auth) add config

This commit is contained in:
coderaiser 2014-09-22 02:44:36 -04:00
parent af97f8e669
commit c7b8efa4dc
2 changed files with 22 additions and 24 deletions

View file

@ -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,

View file

@ -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');