Passwords do not match validation on signup page
This commit is contained in:
20
app.js
20
app.js
@ -7,7 +7,8 @@ var express = require('express'),
|
||||
passport = require('passport');
|
||||
|
||||
// TODO: Add node-opencv!!
|
||||
|
||||
// TODO: "Lego-like" modules, e.g. swap one login view for another
|
||||
// TODO: Let users plug any components of the website
|
||||
// App Configuration (API Keys, Database URI)
|
||||
var config = require('./config/config.json');
|
||||
var passportConf = require('./config/passport');
|
||||
@ -43,38 +44,25 @@ app.use(flash());
|
||||
app.use(express.static(path.join(__dirname, 'public')));
|
||||
app.use(app.router);
|
||||
|
||||
// Routes (url path, corresponding controller)
|
||||
app.get('/', home.index);
|
||||
|
||||
app.get('/', home.index);
|
||||
app.get('/login', user.getLogin);
|
||||
app.post('/login', user.postLogin);
|
||||
|
||||
app.get('/logout', user.logout);
|
||||
|
||||
app.get('/signup', user.getSignup);
|
||||
app.post('/signup', user.postSignup);
|
||||
|
||||
app.get('/account', passportConf.ensureAuthenticated, user.account);
|
||||
|
||||
app.get('/admin', passportConf.ensureAuthenticated, passportConf.ensureAdmin(), user.admin);
|
||||
app.get('/admin', passportConf.ensureAuthenticated, passportConf.ensureAdmin(), user.getAdmin);
|
||||
app.get('/partials/:name', home.partials);
|
||||
|
||||
app.get('/api', api.apiBrowser);
|
||||
app.get('/api/foursquare', passportConf.ensureAuthenticated, api.foursquare);
|
||||
|
||||
app.get('/contact', contact.getContact);
|
||||
app.post('/contact', contact.postContact);
|
||||
|
||||
|
||||
/**
|
||||
* Authentication Routes
|
||||
*/
|
||||
app.get('/auth/facebook', passport.authenticate('facebook'));
|
||||
app.get('/auth/facebook/callback', passport.authenticate('facebook', { successRedirect: '/', failureRedirect: '/login' }));
|
||||
app.get('/auth/foursquare', api.foursquareAuth);
|
||||
app.get('/auth/foursquare/callback', api.foursquareCallback);
|
||||
|
||||
|
||||
app.get('*', home.index);
|
||||
|
||||
|
||||
|
@ -59,23 +59,31 @@ exports.getSignup = function(req, res) {
|
||||
* POST /signup
|
||||
*/
|
||||
exports.postSignup = function(req, res) {
|
||||
|
||||
var user = new User({
|
||||
firstName: req.body.firstName,
|
||||
lastName: req.body.lastName,
|
||||
email: req.body.email,
|
||||
password: req.body.password
|
||||
password: req.body.password,
|
||||
confirmPassword: req.body.confirmPassword
|
||||
});
|
||||
|
||||
if (req.body.password !== req.body.confirmPassword) {
|
||||
req.flash('messages', 'Passwords do not match');
|
||||
return res.redirect('/signup');
|
||||
}
|
||||
|
||||
user.save(function(err) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
if (err.name === 'ValidationError') {
|
||||
req.flash('messages', _.map(err.errors, function(value, key) { return value.message; }));
|
||||
|
||||
}
|
||||
if (err.code === 11000) {
|
||||
req.flash('messages', 'User already exists');
|
||||
return res.redirect('/signup');
|
||||
} else if (err.name === 'ValidationError') {
|
||||
req.flash('messages', _.pluck(_.toArray(err.errors), 'message'));
|
||||
return res.redirect('/signup');
|
||||
}
|
||||
|
||||
return res.redirect('/signup');
|
||||
}
|
||||
req.logIn(user, function(err) {
|
||||
if (err) throw err;
|
||||
@ -87,7 +95,7 @@ exports.postSignup = function(req, res) {
|
||||
/**
|
||||
* GET /admin
|
||||
*/
|
||||
exports.admin = function(req, res) {
|
||||
exports.getAdmin = function(req, res) {
|
||||
res.send('access granted admin!');
|
||||
};
|
||||
|
||||
|
@ -20,7 +20,7 @@ block content
|
||||
input.form-control(type='password', name='password', id='password', placeholder='Password')
|
||||
.form-group
|
||||
label.control-label(for='confirmPassword') Confirm Password
|
||||
input.form-control(type='password', id='confirmPassword', placeholder='Confirm Password')
|
||||
input.form-control(type='password', name='confirmPassword', id='confirmPassword', placeholder='Confirm Password')
|
||||
.form-group
|
||||
button.btn.btn.btn-primary(type='submit') Signup
|
||||
|
||||
|
Reference in New Issue
Block a user