debug auth in production

pull/13/head
Michael Q Larson 2015-01-09 14:02:21 -08:00
parent 503d6ada8a
commit d533e07edd
3 changed files with 27 additions and 29 deletions

View File

@ -12,20 +12,13 @@ var _ = require('lodash'),
nodemailer = require('nodemailer'), nodemailer = require('nodemailer'),
secrets = require('./secrets'); secrets = require('./secrets');
// Login Required middleware.
module.exports = {
isAuthenticated: isAuthenticated,
isAuthorized: isAuthorized
};
passport.serializeUser(function(user, done) { passport.serializeUser(function(user, done) {
done(null, user.id); done(null, user.id);
}); });
passport.deserializeUser(function(id, done) { passport.deserializeUser(function(id, done) {
User.findOne({ User.findById(id, function(err, user) {
_id: id
}, '-password', function(err, user) {
done(err, user); done(err, user);
}); });
}); });
@ -381,12 +374,16 @@ passport.use(new LinkedInStrategy(secrets.linkedin, function(req, accessToken, r
} }
})); }));
function isAuthenticated(req, res, next) { // Login Required middleware.
exports.isAuthenticated = function(req, res, next) {
if (req.isAuthenticated()) return next(); if (req.isAuthenticated()) return next();
res.redirect('/login'); res.redirect('/login');
} };
function isAuthorized(req, res, next) { // Authorization Required middleware.
exports.isAuthorized = function(req, res, next) {
var provider = req.path.split('/').slice(-1)[0]; var provider = req.path.split('/').slice(-1)[0];
if (_.find(req.user.tokens, { kind: provider })) { if (_.find(req.user.tokens, { kind: provider })) {
@ -394,4 +391,4 @@ function isAuthorized(req, res, next) {
} else { } else {
res.redirect('/auth/' + provider); res.redirect('/auth/' + provider);
} }
} };

View File

@ -1,15 +1,16 @@
extends ../layout extends ../layout
block content block content
.col-sm-8.col-sm-offset-2 .jumbotron
form(method='POST') .col-sm-8.col-sm-offset-2
legend Forgot Password form(method='POST')
input(type='hidden', name='_csrf', value=_csrf) h1 Forgot Password
.form-group input(type='hidden', name='_csrf', value=_csrf)
p Enter your email address below and we will send you password reset instructions. .form-group
label.control-label(for='email') Email p Enter your email address below and we will send you password reset instructions.
input.form-control(type='email', name='email', id='email', placeholder='Email', autofocus=true) label.control-label(for='email') Email
.form-group input.form-control(type='email', name='email', id='email', placeholder='Email', autofocus=true)
button.btn.btn-primary(type='submit') .form-group
i.fa.fa-key button.btn.btn-primary(type='submit')
| Reset Password i.fa.fa-key
| Reset Password

View File

@ -243,11 +243,11 @@ block content
a.btn.btn-lg.btn-block.btn-facebook.btn-link-social(href='/auth/facebook') a.btn.btn-lg.btn-block.btn-facebook.btn-link-social(href='/auth/facebook')
i.fa.fa-facebook i.fa.fa-facebook
| Link Facebook with your account | Link Facebook with your account
//- if (!user.github) - if (!user.github)
// .col-xs-12 .col-xs-12
// a.btn.btn-lg.btn-block.btn-github.btn-link-social(href='/auth/github') a.btn.btn-lg.btn-block.btn-github.btn-link-social(href='/auth/github')
// i.fa.fa-github i.fa.fa-github
// | Link GitHub with your account | Link GitHub with your account
- if (!user.linkedin) - if (!user.linkedin)
.col-xs-12 .col-xs-12
a.btn.btn-lg.btn-block.btn-linkedin.btn-link-social(href='/auth/linkedin') a.btn.btn-lg.btn-block.btn-linkedin.btn-link-social(href='/auth/linkedin')