From 26c42e500fecbe0e0d21dffe5cbcbe846c84925c Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Thu, 5 Feb 2015 10:45:03 +0000 Subject: [PATCH] Allow user.default to be an api function --- red/api/auth/users.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/red/api/auth/users.js b/red/api/auth/users.js index f6ae3c3d9..fbab6d2d8 100644 --- a/red/api/auth/users.js +++ b/red/api/auth/users.js @@ -23,17 +23,19 @@ var util = require("util"); users: [{ username: "nol", password: "5f4dcc3b5aa765d61d8327deb882cf99" // password + permissions: "* read write" }], - default: {} + default: { + permissions: "* read write" + } }, adminAuth: { type: "credentials", - api: { - get: function(username) {} - authenticate: function(username,password) {} - default: function() {} - } + users: function(username) {return when.resolve(user)}, + authenticate: function(username,password) { return when.resolve(user);} + default: function() { return when.resolve(defaultUser) } + } */ //{username:"nick",password:crypto.createHash('md5').update("foo",'utf8').digest('hex')} @@ -95,11 +97,15 @@ function init(config) { } } if (config.default) { - api.default = function() { - return when.resolve({ - "anonymous": true, - "permissions":config.default.permissions - }); + if (typeof config.default === "function") { + api.default = config.default; + } else { + api.default = function() { + return when.resolve({ + "anonymous": true, + "permissions":config.default.permissions + }); + } } } else { api.default = getDefaultUser;