Skip to content
Browse files

Final commit before talk.

  • Loading branch information...
1 parent 4ab3c91 commit 895bdc7e7ce5ed9bd262d8561c0a2a3341ed9957 @bnoguchi committed Apr 5, 2011
Showing with 50 additions and 7 deletions.
  1. +50 −7 lib/password.js
View
57 lib/password.js
@@ -2,7 +2,7 @@ var everyModule = require('./everymodule');
var password = module.exports =
everyModule.submodule('password')
- .configurable('loginName passwordName loginView redirectPath')
+ .configurable('loginName passwordName loginView registerView redirectPath User')
.loginName('login')
.passwordName('password')
.get('getLoginPath')
@@ -15,9 +15,6 @@ everyModule.submodule('password')
.promises('login password')
.step('authenticate')
.accepts('login password')
- .promises('didSucceed')
- .step('findUser')
- .accepts('didSucceed login')
.promises('user')
.step('getSession')
.accepts('req')
@@ -26,7 +23,7 @@ everyModule.submodule('password')
.accepts('session user')
.promises(null)
.step('sendResponse')
- .accepts('res didSucceed')
+ .accepts('res user')
.promises(null)
.displayLogin( function (req, res) {
if (res.render) {
@@ -44,10 +41,56 @@ everyModule.submodule('password')
})
.addToSession( function (sess, user) {
var _auth = sess.auth || (sess.auth = {});
- _auth.userId = user.id;
+ if (user)
+ _auth.userId = user.id;
_auth.loggedIn = !!user;
})
- .sendResponse( function (res, didSucceed) {
+ .sendResponse( function (res, user) {
+ res.writeHead(303, {'Location': this.redirectPath()});
+ res.end();
+ })
+ .get('getRegisterPath')
+ .step('displayRegister')
+ .accepts('req res')
+ .promises(null)
+ .displayRegister( function (req, res) {
+ if (res.render) {
+ res.render(this.registerView());
+ } else {
+ res.writeHead(200, {'Content-Type': 'text/html'});
+ res.end(this.registerView());
+ }
+ })
+ .post('postRegisterPath')
+ .step('extractRegistrationParams')
+ .accepts('req res')
+ .promises('login password')
+ .step('registerUser')
+ .accepts('login password')
+ .promises('user')
+ .step('retrieveSession')
+ .accepts('req')
+ .promises('session')
+ .step('registerSession')
+ .accepts('session user')
+ .promises(null)
+ .step('ackRegistration')
+ .accepts('res user')
+ .promises(null)
+ // TODO Allow ability to re-use steps across different
+ // sequences (i.e., across different routes)
+ .extractRegistrationParams( function (req, res) {
+ return [req.body[this.loginName()], req.body[this.passwordName()]];
+ })
+ .retrieveSession( function (req) {
+ return req.session;
+ })
+ .registerSession( function (sess, user) {
+ var auth = sess.auth || (sess.auth = {});
+ auth.userId = user.id;
+ auth.loggedIn = true;
+ })
+ .ackRegistration( function (res, user) {
res.writeHead(303, {'Location': this.redirectPath()});
res.end();
});

0 comments on commit 895bdc7

Please sign in to comment.
Something went wrong with that request. Please try again.