Skip to content

Changed Views to accept CSRF token #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,18 @@ app.use(express.urlencoded());
app.use(expressValidator());
app.use(express.methodOverride());
app.use(express.session({
secret: 'your secret code',
secret: secrets.sessionSecret,
store: new MongoStore({
db: mongoose.connection.db,
auto_reconnect: true
})
}));
app.use(express.csrf());
app.use(passport.initialize());
app.use(passport.session());
app.use(function(req, res, next) {
res.locals.user = req.user;
res.locals.token = req.csrfToken();
next();
});
app.use(flash());
Expand All @@ -89,6 +91,13 @@ app.use(function(req, res) {
});
app.use(express.errorHandler());

/*Helper function for CSRF
app.dynamicHelpers({
token: function(req, res) {
return req.session._csrf;
}
});*/

/**
* Application routes.
*/
Expand Down
2 changes: 2 additions & 0 deletions config/secrets.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module.exports = {
db: 'localhost',

sessionSecret: "Your Session Secret goes here",

sendgrid: {
user: 'Your SendGrid Username',
password: 'Your SendGrid Password'
Expand Down
2 changes: 2 additions & 0 deletions views/account/login.jade
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ block content
.form-group
label.control-label(for='username') Password
input.form-control(type='password', name='password', id='password', placeholder='Password')
.form-group
input.form-control(type='hidden', name='_csrf', value=token)
.form-group
button.btn.btn-primary(type='submit')
i.fa.fa-unlock-alt
Expand Down
7 changes: 6 additions & 1 deletion views/account/profile.jade
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ block content
label.col-xs-2.control-label(for='website') Website
.col-xs-4
input.form-control(type='text', name='website', id='website', value='#{user.profile.website}')
.form-group
input.form-control(type='hidden', name='_csrf', value=token)
.form-group
.col-xs-offset-2.col-xs-4
button.btn.btn.btn-primary(type='submit') Update Profile




.page-header
h3 Change Password

Expand All @@ -48,6 +51,8 @@ block content
label.col-xs-3.control-label(for='confirmPassword') Confirm Password
.col-xs-4
input.form-control(type='password', name='confirmPassword', id='confirmPassword')
.form-group
input.form-control(type='hidden', name='_csrf', value=token)
.form-group
.col-xs-offset-3.col-xs-4
button.btn.btn.btn-primary(type='submit') Change Password
Expand Down Expand Up @@ -80,4 +85,4 @@ block content
if user.github
p: a.text-danger(href='/account/unlink/github') Unlink your GitHub account
else
p: a(href='/auth/github') Link your GitHub account
p: a(href='/auth/github') Link your GitHub account
2 changes: 2 additions & 0 deletions views/account/signup.jade
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ block content
label.col-sm-3.control-label(for='username') Confirm Password
.col-sm-7
input.form-control(type='password', name='confirmPassword', id='confirmPassword', placeholder='Confirm Password')
.form-group
input.form-control(type='hidden', name='_csrf', value=token)
.form-group
.col-sm-offset-3.col-sm-7
button.btn.btn-success(type='submit')
Expand Down
2 changes: 2 additions & 0 deletions views/contact.jade
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ block content
label(class='col-sm-2 control-label', for='contactBody') Body
.col-sm-8
textarea.form-control(type='text', name='message', id='message', rows='7')
.form-group
input.form-control(type='hidden', name='_csrf', value=token)
.form-group
.col-sm-offset-2.col-sm-8
button.btn.btn-default(type='submit')
Expand Down