Permalink
Browse files

currentUser is a session variable that shouldn't be stored on a globa…

…l object
  • Loading branch information...
1 parent 2532477 commit 519d39e87a3f227b7ea8a9df7aa06f2df0684b6d @james-emerton james-emerton committed Apr 2, 2012
View
@@ -32,6 +32,7 @@ function jsDAV_Auth_Plugin(handler) {
* @var jsDAV_Auth_Backend_Abstract
*/
this.authBackend = null;
+ this.currentUser = null;
/**
* The authentication realm.
@@ -52,8 +53,7 @@ function jsDAV_Auth_Plugin(handler) {
* @return string|null
*/
this.getCurrentUser = function() {
- if (this.authBackend)
- return this.authBackend.getCurrentUser();
+ return this.currentUser;
};
/**
@@ -66,11 +66,13 @@ function jsDAV_Auth_Plugin(handler) {
this.beforeMethod = function(e, method) {
if (!this.authBackend)
return e.next();
+ var self = this;
this.authBackend.authenticate(this.handler, this.realm, function(err, res) {
if (err || !res) {
// Auth backend should have generated a response
return e.stop();
}
+ self.currentUser = res;
e.next();
});
};
@@ -20,13 +20,6 @@ function jsDAV_Auth_Backend_AbstractBasic() { }
(function() {
/**
- * This variable holds the currently logged in username.
- *
- * @var string|null
- */
- this.currentUser = null;
-
- /**
* Validates a username and password
*
* This method should return true or false depending on if login
@@ -37,17 +30,6 @@ function jsDAV_Auth_Backend_AbstractBasic() { }
this.validateUserPass = function(username, password, cbvalidpass) {};
/**
- * Returns information about the currently logged in username.
- *
- * If nobody is currently logged in, this method should return null.
- *
- * @return string|null
- */
- this.getCurrentUser = function() {
- return this.currentUser;
- };
-
- /**
* Returns an HTTP 401 header, forcing login
*
* This should be called when username and password are incorrect, or not supplied at all
@@ -87,8 +69,7 @@ function jsDAV_Auth_Backend_AbstractBasic() { }
if (!valid)
return self.requireAuth(res, realm, "Username or password does not match", cbauth);
- self.currentUser = userpass[0];
- cbauth(null, true);
+ cbauth(null, userpass[0]);
});
};
}).call(jsDAV_Auth_Backend_AbstractBasic.prototype = new jsDAV_Auth_iBackend());
@@ -25,13 +25,6 @@ function jsDAV_Auth_Backend_AbstractDigest() {
(function() {
/**
- * This variable holds the currently logged in username.
- *
- * @var array|null
- */
- this.currentUser = null;
-
- /**
* These constants are used in setQOP();
*/
var QOP_AUTH = 1,
@@ -267,20 +260,10 @@ function jsDAV_Auth_Backend_AbstractDigest() {
if (!isValid)
return self.requireAuth(res, realm, "Incorrect username", cbauth);
- self.currentUser = username;
- cbauth(null, true);
+ cbauth(null, username);
});
});
};
-
- /**
- * Returns the currently logged in username.
- *
- * @return string|null
- */
- this.getCurrentUser = function() {
- return this.currentUser;
- };
}).call(jsDAV_Auth_Backend_AbstractDigest.prototype = new jsDAV_Auth_iBackend());
module.exports = jsDAV_Auth_Backend_AbstractDigest;
@@ -18,21 +18,13 @@ function jsDAV_Auth_iBackend() {
/**
* Authenticates the user based on the current request.
*
- * If authentication is succesful, true must be returned.
- * If authentication fails, an exception must be thrown.
+ * If authentication is succesful, the current user must be passed
+ * to the callback.
+ * If authentication fails, null should be passed to the callback.
*
* @return {bool}
*/
this.authenticate = function(server, realm, cbauth) {};
-
- /**
- * Returns information about the currently logged in username.
- *
- * If nobody is currently logged in, this method should return null.
- *
- * @return {string|null}
- */
- this.getCurrentUser = function() {};
}
exports.jsDAV_Auth_iBackend = jsDAV_Auth_iBackend;

0 comments on commit 519d39e

Please sign in to comment.