fix the FCC email login process
This commit is contained in:
6
app.js
6
app.js
@ -135,8 +135,10 @@ app.get('/forgot', userController.getForgot);
|
|||||||
app.post('/forgot', userController.postForgot);
|
app.post('/forgot', userController.postForgot);
|
||||||
app.get('/reset/:token', userController.getReset);
|
app.get('/reset/:token', userController.getReset);
|
||||||
app.post('/reset/:token', userController.postReset);
|
app.post('/reset/:token', userController.postReset);
|
||||||
app.get('/signup', userController.getSignup);
|
app.get('/email-signup', userController.getEmailSignup);
|
||||||
app.post('/signup', userController.postSignup);
|
app.get('/email-signin', userController.getEmailSignin);
|
||||||
|
app.post('/email-signup', userController.postEmailSignup);
|
||||||
|
app.post('/email-signin', userController.postLogin);
|
||||||
app.get('/nonprofits', contactController.getContact);
|
app.get('/nonprofits', contactController.getContact);
|
||||||
app.post('/nonprofits', contactController.postContact);
|
app.post('/nonprofits', contactController.postContact);
|
||||||
|
|
||||||
|
@ -61,25 +61,37 @@ exports.logout = function(req, res) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GET /signup
|
* GET /email-signup
|
||||||
* Signup page.
|
* Signup page.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.getSignup = function(req, res) {
|
exports.getEmailSignin = function(req, res) {
|
||||||
if (req.user) return res.redirect('/');
|
if (req.user) return res.redirect('/');
|
||||||
res.render('account/signup', {
|
res.render('account/email-signup', {
|
||||||
title: 'Create Your Free Code Camp Account'
|
title: 'Create Your Free Code Camp Account'
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* POST /signup
|
* GET /email-signin
|
||||||
|
* Signup page.
|
||||||
|
*/
|
||||||
|
|
||||||
|
exports.getEmailSignup = function(req, res) {
|
||||||
|
if (req.user) return res.redirect('/');
|
||||||
|
res.render('account/email-signin', {
|
||||||
|
title: 'Create Your Free Code Camp Account'
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST /email-signup
|
||||||
* Create a new local account.
|
* Create a new local account.
|
||||||
* @param email
|
* @param email
|
||||||
* @param password
|
* @param password
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.postSignup = function(req, res, next) {
|
exports.postEmailSignup = function(req, res, next) {
|
||||||
req.assert('email', 'Email is not valid').isEmail();
|
req.assert('email', 'Email is not valid').isEmail();
|
||||||
req.assert('password', 'Password must be at least 4 characters long').len(4);
|
req.assert('password', 'Password must be at least 4 characters long').len(4);
|
||||||
req.assert('confirmPassword', 'Passwords do not match').equals(req.body.password);
|
req.assert('confirmPassword', 'Passwords do not match').equals(req.body.password);
|
||||||
@ -88,7 +100,7 @@ exports.postSignup = function(req, res, next) {
|
|||||||
|
|
||||||
if (errors) {
|
if (errors) {
|
||||||
req.flash('errors', errors);
|
req.flash('errors', errors);
|
||||||
return res.redirect('/signup');
|
return res.redirect('/email-signup');
|
||||||
}
|
}
|
||||||
|
|
||||||
var user = new User({
|
var user = new User({
|
||||||
@ -99,13 +111,13 @@ exports.postSignup = function(req, res, next) {
|
|||||||
User.findOne({ email: req.body.email }, function(err, existingUser) {
|
User.findOne({ email: req.body.email }, function(err, existingUser) {
|
||||||
if (existingUser) {
|
if (existingUser) {
|
||||||
req.flash('errors', { msg: 'Account with that email address already exists.' });
|
req.flash('errors', { msg: 'Account with that email address already exists.' });
|
||||||
return res.redirect('/signup');
|
return res.redirect('/email-signup');
|
||||||
}
|
}
|
||||||
user.save(function(err) {
|
user.save(function(err) {
|
||||||
if (err) return next(err);
|
if (err) return next(err);
|
||||||
req.logIn(user, function(err) {
|
req.logIn(user, function(err) {
|
||||||
if (err) return next(err);
|
if (err) return next(err);
|
||||||
res.redirect('/');
|
res.redirect('/email-signup');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -2,7 +2,7 @@ extends ../layout
|
|||||||
block content
|
block content
|
||||||
.jumbotron.text-center
|
.jumbotron.text-center
|
||||||
h2 Sign up with an email address here:
|
h2 Sign up with an email address here:
|
||||||
form.form-horizontal(id='signup-form', method='POST')
|
form.form-horizontal(method='POST')
|
||||||
input(type='hidden', name='_csrf', value=_csrf)
|
input(type='hidden', name='_csrf', value=_csrf)
|
||||||
.form-group
|
.form-group
|
||||||
.col-sm-6.col-sm-offset-3
|
.col-sm-6.col-sm-offset-3
|
||||||
@ -18,23 +18,6 @@ block content
|
|||||||
button.btn.btn-success(type='submit')
|
button.btn.btn-success(type='submit')
|
||||||
span.ion-person-add
|
span.ion-person-add
|
||||||
| Signup
|
| Signup
|
||||||
hr
|
|
||||||
h2 Sign in with an email address here:
|
|
||||||
form(method='POST')
|
|
||||||
input(type='hidden', name='_csrf', value=_csrf)
|
|
||||||
.col-sm-6.col-sm-offset-3
|
|
||||||
.form-group
|
|
||||||
//label.control-label(for='email') Email
|
|
||||||
input.form-control(type='email', name='email', id='email', placeholder='Email', autofocus=true)
|
|
||||||
.form-group
|
|
||||||
//label.control-label(for='password') Password
|
|
||||||
input.form-control(type='password', name='password', id='password', placeholder='Password')
|
|
||||||
.form-group
|
|
||||||
button.btn.btn-primary(type='submit')
|
|
||||||
span.ion-android-hand
|
|
||||||
| Login
|
|
||||||
span
|
|
||||||
a.btn.btn-info(href='/forgot') Forgot your password?
|
|
||||||
br
|
br
|
||||||
br
|
br
|
||||||
br
|
br
|
26
views/account/email-signup.jade
Normal file
26
views/account/email-signup.jade
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
extends ../layout
|
||||||
|
block content
|
||||||
|
.jumbotron.text-center
|
||||||
|
h2 Sign in with an email address here:
|
||||||
|
form(method='POST')
|
||||||
|
input(type='hidden', name='_csrf', value=_csrf)
|
||||||
|
.col-sm-6.col-sm-offset-3
|
||||||
|
.form-group
|
||||||
|
input.form-control(type='email', name='email', id='email', placeholder='Email', autofocus=true)
|
||||||
|
.form-group
|
||||||
|
input.form-control(type='password', name='password', id='password', placeholder='Password')
|
||||||
|
.form-group
|
||||||
|
button.btn.btn-primary(type='submit')
|
||||||
|
span.ion-android-hand
|
||||||
|
| Login
|
||||||
|
span
|
||||||
|
a.btn.btn-info(href='/forgot') Forgot your password?
|
||||||
|
br
|
||||||
|
br
|
||||||
|
br
|
||||||
|
br
|
||||||
|
br
|
||||||
|
br
|
||||||
|
br
|
||||||
|
br
|
||||||
|
br
|
@ -19,5 +19,6 @@ block content
|
|||||||
| Sign in with Twitter
|
| Sign in with Twitter
|
||||||
br
|
br
|
||||||
p
|
p
|
||||||
a(href="/signup") Or sign in using your email address here.
|
a(href="/email-signup") Or sign up using your email address here.
|
||||||
|
p
|
||||||
|
a(href="/email-signin") Sign in to your existing account with your email address here.
|
||||||
|
Reference in New Issue
Block a user