Skip to content

Commit

Permalink
Included express flash messages for initial login auth work on #7
Browse files Browse the repository at this point in the history
  • Loading branch information
victorkane committed Jul 19, 2011
1 parent 1cda8f2 commit c8ad753
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
11 changes: 3 additions & 8 deletions routes/user.js
Expand Up @@ -70,12 +70,7 @@ module.exports = function(app){
});

app.get('/login', function(req, res) {
if (req.session.user) {
req.session.success = 'Authenticated as ' + req.session.user.name
+ ' click to <a href="/logout">logout</a>. '
+ ' You may now access <a href="/restricted">/restricted</a>.';
}
res.render('login');
res.render('login');
});

app.post('/login', function(req, res) {
Expand All @@ -90,11 +85,11 @@ module.exports = function(app){
// or in this case the entire user object
req.session.user = user;
//res.redirect('back');
req.flash('info', 'Welcome _%s_', req.session.user.name);
res.redirect('/textview');
});
} else {
req.session.error = 'Authentication failed, please check your '
+ ' username and password.' + ' (use "tj" and "foobar")';
req.flash('error', 'Authentication failed, please check your username and password. (Use "th" and "foobar")');
res.redirect('back');
}
});
Expand Down
2 changes: 0 additions & 2 deletions views/index.jade
@@ -1,6 +1,4 @@
h1 lit

!= messages()

p Welcome!
a(href='/textview', title='View texts') Come for the texts, stay for the community!
2 changes: 2 additions & 0 deletions views/login.jade
@@ -1,3 +1,5 @@
!= messages()

form#login(action=base + '/login', method='post')
p
label(for='user[username]') Username:
Expand Down
6 changes: 5 additions & 1 deletion views/textview.jade
Expand Up @@ -18,4 +18,8 @@ h1 lit
p
| Click
a(href=base + '/text/add') here
| to create a text.
| to create a text.
p
| Click
a(href=base + '/logout') here
| to logout.

0 comments on commit c8ad753

Please sign in to comment.