-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create login controller, template and 401 error page
- Loading branch information
lmarkus
committed
Dec 31, 2013
1 parent
bb0ee06
commit 984c064
Showing
4 changed files
with
72 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,47 @@ | ||
'use strict'; | ||
|
||
|
||
var LoginModel = require('../models/login'); | ||
var LoginModel = require('../models/login'), | ||
passport = require('passport'); | ||
|
||
|
||
module.exports = function (app) { | ||
|
||
var model = new LoginModel(); | ||
|
||
|
||
/** | ||
* Display the login page. We also want to display any error messages that result from a failed login attempt. | ||
*/ | ||
app.get('/login', function (req, res) { | ||
|
||
|
||
//Include any error messages that come from the login process. | ||
model.messages = req.flash('error'); | ||
res.render('login', model); | ||
|
||
}); | ||
|
||
/** | ||
* Receive the login credentials and authenticate. | ||
* Successful authentications will go to /profile or if the user was trying to access a secured resource, the URL | ||
* that was originally requested. | ||
* | ||
* Failed authentications will go back to the login page with a helpful error message to be displayed. | ||
*/ | ||
app.post('/login', function (req, res) { | ||
|
||
passport.authenticate('local', { | ||
successRedirect: req.session.goingTo || '/profile', | ||
failureRedirect: "/login", | ||
failureFlash: true | ||
})(req, res); | ||
|
||
}); | ||
|
||
/** | ||
* Allow the users to log out | ||
*/ | ||
app.get('/logout', function (req, res) { | ||
req.logout(); | ||
res.redirect('/'); | ||
}); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{>"layouts/master" /} | ||
|
||
{<body} | ||
<h1>{@pre type="content" key="header"/}</h1> | ||
<p>{@pre type="content" key="description"/}</p> | ||
{/body} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,37 @@ | ||
{>"layouts/master" /} | ||
|
||
{<body} | ||
<h1>{@pre type="content" key="greeting"/}</h1> | ||
<div> | ||
<form id="loginForm" method="post"> | ||
<fieldset> | ||
<h2>Login</h2> | ||
{?messages} | ||
<ul> | ||
{#messages} | ||
<li>{.}</li> | ||
{/messages} | ||
|
||
</ul> | ||
{/messages} | ||
<table> | ||
<tr> | ||
<td><label for="username">Login: </label></td> | ||
<td><input id="username" name="username" type="text"/></td> | ||
</tr> | ||
<tr> | ||
<td><label for="password">Password: </label></td> | ||
<td><input id="password" name="password" type="password"/></td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<input type="submit" value="Login"/> | ||
<input type="hidden" name="_csrf" value="{_csrf}"/> | ||
</td> | ||
<td></td> | ||
</tr> | ||
</table> | ||
|
||
</fieldset> | ||
</form> | ||
</div> | ||
{/body} |