Cleaned up code + simplified
This commit is contained in:
		
							
								
								
									
										2
									
								
								app.js
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								app.js
									
									
									
									
									
								
							| @@ -105,5 +105,3 @@ app.get('/auth/tumblr/callback', passport.authorize('tumblr', { failureRedirect: | ||||
| app.listen(app.get('port'), function() { | ||||
|   console.log('Express server listening on port ' + app.get('port')); | ||||
| }); | ||||
|  | ||||
| module.exports = app; | ||||
| @@ -34,6 +34,7 @@ passport.use(new LocalStrategy(function(username, password, done) { | ||||
| })); | ||||
|  | ||||
| passport.use(new FacebookStrategy(secrets.facebook, function (req, accessToken, refreshToken, profile, done) { | ||||
|   // TODO: remove duplication | ||||
|   if (req.user) { | ||||
|     User.findById(req.user.id, function(err, user) { | ||||
|       user.facebook = profile.id; | ||||
|   | ||||
| @@ -44,9 +44,9 @@ exports.postAccountProfileTab = function(req, res, next) { | ||||
|  * POST /account#settings | ||||
|  * Update user's current password | ||||
|  */ | ||||
| exports.postAccountSettingsTab = function(req, res) { | ||||
| exports.postAccountSettingsTab = function(req, res, next) { | ||||
|  | ||||
|   // TODO: Virtual mongodb | ||||
|   // TODO: Use Virtuals (mongoose) | ||||
|   if (!req.body.password || !req.body.confirm.password) { | ||||
|     req.flash('error', 'Passwords cannot be blank'); | ||||
|     return res.redirect('/account'); | ||||
| @@ -58,16 +58,10 @@ exports.postAccountSettingsTab = function(req, res) { | ||||
|   } | ||||
|  | ||||
|   User.findById(req.user.id, function(err, user) { | ||||
|     if (err) { | ||||
|       req.flash('error', err.message); | ||||
|       return res.redirect('/account'); | ||||
|     } | ||||
|     if (err) return next(err); | ||||
|     user.password = req.body.password; | ||||
|     user.save(function(err) { | ||||
|       if (err) { | ||||
|         req.flash('error', err.message); | ||||
|         return res.redirect('/account'); | ||||
|       } | ||||
|       if (err) return next(err); | ||||
|       req.flash('success', 'Password has been changed'); | ||||
|       res.redirect('/account'); | ||||
|     }); | ||||
| @@ -123,7 +117,6 @@ exports.postLogin = function(req, res, next) { | ||||
|  */ | ||||
| exports.getSignup = function(req, res) { | ||||
|   if (req.user) return res.redirect('back'); | ||||
|  | ||||
|   res.render('signup', { | ||||
|     title: 'Create Account', | ||||
|     user: req.user, | ||||
| @@ -154,9 +147,11 @@ exports.postSignup = function(req, res, next) { | ||||
|     password: req.body.password | ||||
|   }); | ||||
|  | ||||
|   // TODO: simplify | ||||
|   user.save(function(err) { | ||||
|     if (err) { | ||||
|       if (err.name === 'ValidationError') { | ||||
|         // TODO: make more explicit | ||||
|         req.flash('messages', _.map(err.errors, function(value, key) { return value.message; })); | ||||
|       } | ||||
|       if (err.code === 11000) { | ||||
| @@ -166,7 +161,7 @@ exports.postSignup = function(req, res, next) { | ||||
|     } | ||||
|  | ||||
|     req.logIn(user, function(err) { | ||||
|       if (err) throw err; | ||||
|       if (err) return next(err); | ||||
|       res.redirect('/'); | ||||
|     }); | ||||
|   }); | ||||
|   | ||||
| @@ -24,7 +24,7 @@ block content | ||||
|             | Google | ||||
|       .form-group | ||||
|         label.control-label(for='username') Email | ||||
|         input.form-control(type='text', name='username', id='username', placeholder='Email', autofocus='') | ||||
|         input.form-control(type='text', name='username', id='username', placeholder='Email', autofocus=true) | ||||
|       .form-group | ||||
|         label.control-label(for='username') Password | ||||
|         input.form-control(type='password', name='password', id='password', placeholder='Password') | ||||
|   | ||||
| @@ -11,7 +11,7 @@ block content | ||||
|     .form-group | ||||
|       label.col-sm-3.control-label(for='username') Email | ||||
|       .col-sm-7 | ||||
|         input.form-control(type='email', name='username', id='username', placeholder='Email', autofocus='') | ||||
|         input.form-control(type='email', name='username', id='username', placeholder='Email', autofocus=true) | ||||
|     .form-group | ||||
|       label.col-sm-3.control-label(for='username') Password | ||||
|       .col-sm-7 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user