From 7edf211b189734bffb81157bc8b76417f3670bc5 Mon Sep 17 00:00:00 2001 From: Brian Warner <warner@lothar.com> Date: Fri, 13 Jul 2012 10:58:44 -0700 Subject: [PATCH] rename superSessionToken to lastPasswordReset, easier to understand --- lib/db.js | 2 +- lib/db/json.js | 14 +++++++------- lib/db/mysql.js | 18 +++++++++--------- lib/wsapi.js | 14 +++++++------- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/db.js b/lib/db.js index c43261dec..a3bcb33e7 100644 --- a/lib/db.js +++ b/lib/db.js @@ -81,7 +81,7 @@ exports.onReady = function(f) { 'emailType', 'emailIsVerified', 'emailsBelongToSameAccount', - 'superSessionToken', + 'lastPasswordReset', 'haveVerificationSecret', 'isStaged', 'lastStaged', diff --git a/lib/db/json.js b/lib/db/json.js index 5ab60788a..946f74366 100644 --- a/lib/db/json.js +++ b/lib/db/json.js @@ -33,7 +33,7 @@ var dbPath = path.join(configuration.get('var_path'), "authdb.json"); * { * id: <numerical user id> * password: "somepass", - * superSessionToken: 123456, (ms-since-epoch, integer) + * lastPasswordReset: 123456, (ms-since-epoch, integer) * emails: { * "lloyd@hilaiel.com": { * type: 'secondary' @@ -235,7 +235,7 @@ exports.createUserWithPrimaryEmail = function(email, cb) { db.users.push({ id: uid, password: null, - superSessionToken: now(), + lastPasswordReset: now(), emails: emailVal }); flush(); @@ -339,7 +339,7 @@ exports.completeCreateUser = function(secret, cb) { db.users.push({ id: uid, password: hash, - superSessionToken: now(), + lastPasswordReset: now(), emails: emailVal }); flush(); @@ -426,11 +426,11 @@ exports.checkAuth = function(userID, cb) { process.nextTick(function() { cb(null, m) }); }; -exports.superSessionToken = function(userID, cb) { +exports.lastPasswordReset = function(userID, cb) { sync(); var m = undefined; if (userID) { - m = jsel.match(":root > object:has(:root > .id:expr(x=" + ESC(userID) + ")) > .superSessionToken", db.users); + m = jsel.match(":root > object:has(:root > .id:expr(x=" + ESC(userID) + ")) > .lastPasswordReset", db.users); if (m.length === 0) m = undefined; else m = m[0]; } @@ -453,7 +453,7 @@ exports.updatePassword = function(userID, hash, invalidateSessions, cb) { else { m[0].password = hash; if (invalidateSessions) - m[0].superSessionToken = now(); + m[0].lastPasswordReset = now(); } flush(); process.nextTick(function() { cb(err) }); @@ -518,7 +518,7 @@ exports.addTestUser = function(email, hash, cb) { db.users.push({ id: getNextUserID(), password: hash, - superSessionToken: now(), + lastPasswordReset: now(), emails: emailVal }); flush(); diff --git a/lib/db/mysql.js b/lib/db/mysql.js index 34fcb1efc..26d0c143c 100644 --- a/lib/db/mysql.js +++ b/lib/db/mysql.js @@ -13,7 +13,7 @@ * +--- user -----------------+ |*int id | * |*int id |<-----|*int user | * | string passwd | |*string address | - * | string superSessionToken | | enum type | + * | string lastPasswordReset | | enum type | * +--------------------------+ | bool verified | * +-----------------+ * @@ -65,7 +65,7 @@ const schemas = [ "CREATE TABLE IF NOT EXISTS user (" + "id BIGINT AUTO_INCREMENT PRIMARY KEY," + "passwd CHAR(64)," + - "superSessionToken BIGINT" + + "lastPasswordReset BIGINT" + ") ENGINE=InnoDB;", "CREATE TABLE IF NOT EXISTS email (" + @@ -371,7 +371,7 @@ exports.completeCreateUser = function(secret, cb) { // we're creating a new account, add appropriate entries into user and email tables. client.query( - "INSERT INTO user(passwd, superSessionToken) VALUES(?,?)", + "INSERT INTO user(passwd, lastPasswordReset) VALUES(?,?)", [ o.passwd, now() ], function(err, info) { if (err) return cb(err); @@ -451,7 +451,7 @@ exports.addPrimaryEmailToAccount = function(uid, emailToAdd, cb) { exports.createUserWithPrimaryEmail = function(email, cb) { // create a new user acct with no password client.query( - "INSERT INTO user(superSessionToken) VALUES(?)", + "INSERT INTO user(lastPasswordReset) VALUES(?)", [ now() ], function(err, info) { if (err) return cb(err); @@ -513,18 +513,18 @@ exports.checkAuth = function(uid, cb) { }); } -exports.superSessionToken = function(uid, cb) { +exports.lastPasswordReset = function(uid, cb) { client.query( - 'SELECT superSessionToken FROM user WHERE id = ?', + 'SELECT lastPasswordReset FROM user WHERE id = ?', [ uid ], function (err, rows) { - cb(err, (rows && rows.length == 1) ? rows[0].superSessionToken : undefined); + cb(err, (rows && rows.length == 1) ? rows[0].lastPasswordReset : undefined); }); } exports.updatePassword = function(uid, hash, invalidateSessions, cb) { var query = invalidateSessions ? - 'UPDATE user SET passwd = ?, superSessionToken = ? WHERE id = ?' : + 'UPDATE user SET passwd = ?, lastPasswordReset = ? WHERE id = ?' : 'UPDATE user SET passwd = ? WHERE id = ?'; var args = invalidateSessions ? [ hash, now(), uid ] : [ hash, uid ]; client.query(query, args, @@ -591,7 +591,7 @@ exports.cancelAccount = function(uid, cb) { exports.addTestUser = function(email, hash, cb) { client.query( - "INSERT INTO user(passwd, superSessionToken) VALUES(?)", + "INSERT INTO user(passwd, lastPasswordReset) VALUES(?)", [ hash, now() ], function(err, info) { if (err) return cb(err); diff --git a/lib/wsapi.js b/lib/wsapi.js index 5070f86b1..6eceb532e 100644 --- a/lib/wsapi.js +++ b/lib/wsapi.js @@ -88,11 +88,11 @@ function authenticateSession(options, cb) { if (['assertion', 'password'].indexOf(level) === -1) cb(new Error("invalid authentication level: " + level)); - db.superSessionToken(uid, function(err, superSessionToken) { + db.lastPasswordReset(uid, function(err, lastPasswordReset) { if (err) return cb(err); - if (superSessionToken === undefined) - return cb(new Error("authenticateSession called with undefined superSessionToken")); + if (lastPasswordReset === undefined) + return cb(new Error("authenticateSession called with undefined lastPasswordReset")); // if the user is *already* authenticated as this uid with an equal or // better level of auth, let's not lower them. Issue #1049 if (session.userid === uid && session.auth_level === 'password' && @@ -104,7 +104,7 @@ function authenticateSession(options, cb) { } session.userid = uid; session.auth_level = level; - session.superSessionToken = superSessionToken; + session.lastPasswordReset = lastPasswordReset; } cb(null); }); @@ -140,13 +140,13 @@ function checkExpiredSession(req, resp, next) { logger.warn("calls to /wsapi require a cookie to be sent, this user may have cookies disabled"); return httputils.forbidden(resp, "no cookie"); } - db.superSessionToken(req.session.userid, function(err, token) { + db.lastPasswordReset(req.session.userid, function(err, token) { if (err) return databaseDown(resp, err); // if token is 0 (or undefined), they haven't changed their password - // since the server was updated to use superSessionTokens. Allow the + // since the server was updated to use lastPasswordResets. Allow the // session to pass, otherwise the server upgrade would gratuitously // expire innocent sessions. - if (token != req.session.superSessionToken) { + if (token != req.session.lastPasswordReset) { logger.warn("expired cookie (password changed since issued)"); req.session.reset(); } -- GitLab