diff --git a/app.js b/app.js index 190ecf6a76..76723149d1 100644 --- a/app.js +++ b/app.js @@ -135,8 +135,10 @@ app.get('/forgot', userController.getForgot); app.post('/forgot', userController.postForgot); app.get('/reset/:token', userController.getReset); app.post('/reset/:token', userController.postReset); -app.get('/signup', userController.getSignup); -app.post('/signup', userController.postSignup); +app.get('/email-signup', userController.getEmailSignup); +app.get('/email-signin', userController.getEmailSignin); +app.post('/email-signup', userController.postEmailSignup); +app.post('/email-signin', userController.postLogin); app.get('/nonprofits', contactController.getContact); app.post('/nonprofits', contactController.postContact); diff --git a/controllers/user.js b/controllers/user.js index 356f804c2a..ad116b97a8 100644 --- a/controllers/user.js +++ b/controllers/user.js @@ -61,25 +61,37 @@ exports.logout = function(req, res) { }; /** - * GET /signup + * GET /email-signup * Signup page. */ -exports.getSignup = function(req, res) { +exports.getEmailSignin = function(req, res) { if (req.user) return res.redirect('/'); - res.render('account/signup', { + res.render('account/email-signup', { 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. * @param email * @param password */ -exports.postSignup = function(req, res, next) { +exports.postEmailSignup = function(req, res, next) { req.assert('email', 'Email is not valid').isEmail(); req.assert('password', 'Password must be at least 4 characters long').len(4); req.assert('confirmPassword', 'Passwords do not match').equals(req.body.password); @@ -88,7 +100,7 @@ exports.postSignup = function(req, res, next) { if (errors) { req.flash('errors', errors); - return res.redirect('/signup'); + return res.redirect('/email-signup'); } var user = new User({ @@ -99,13 +111,13 @@ exports.postSignup = function(req, res, next) { User.findOne({ email: req.body.email }, function(err, existingUser) { if (existingUser) { req.flash('errors', { msg: 'Account with that email address already exists.' }); - return res.redirect('/signup'); + return res.redirect('/email-signup'); } user.save(function(err) { if (err) return next(err); req.logIn(user, function(err) { if (err) return next(err); - res.redirect('/'); + res.redirect('/email-signup'); }); }); }); diff --git a/views/account/signup.jade b/views/account/email-signin.jade similarity index 52% rename from views/account/signup.jade rename to views/account/email-signin.jade index 8886c2e36d..ebc38961cc 100644 --- a/views/account/signup.jade +++ b/views/account/email-signin.jade @@ -2,7 +2,7 @@ extends ../layout block content .jumbotron.text-center 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) .form-group .col-sm-6.col-sm-offset-3 @@ -18,23 +18,6 @@ block content button.btn.btn-success(type='submit') span.ion-person-add | 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 diff --git a/views/account/email-signup.jade b/views/account/email-signup.jade new file mode 100644 index 0000000000..0764a2ee18 --- /dev/null +++ b/views/account/email-signup.jade @@ -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 \ No newline at end of file diff --git a/views/account/login.jade b/views/account/login.jade index 3a490fe483..84f205c3f2 100644 --- a/views/account/login.jade +++ b/views/account/login.jade @@ -19,5 +19,6 @@ block content | Sign in with Twitter br 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.