diff --git a/app.js b/app.js index 18e6aabd3a9..f12bd4d24cf 100755 --- a/app.js +++ b/app.js @@ -21,7 +21,7 @@ var expressValidator = require('express-validator'); var connectAssets = require('connect-assets'); /** - * Load controllers. + * Controllers (route handlers). */ var homeController = require('./controllers/home'); @@ -30,7 +30,7 @@ var apiController = require('./controllers/api'); var contactController = require('./controllers/contact'); /** - * API keys + Passport configuration. + * API keys and Passport configuration. */ var secrets = require('./config/secrets'); @@ -43,7 +43,7 @@ var passportConf = require('./config/passport'); var app = express(); /** - * Mongoose configuration. + * Connect to MongoDB. */ mongoose.connect(secrets.db); @@ -68,11 +68,11 @@ var whitelist = ['/url1', '/url2']; app.set('port', process.env.PORT || 3000); app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'jade'); +app.use(compress()); app.use(connectAssets({ paths: ['public/css', 'public/js'], helperContext: app.locals })); -app.use(compress()); app.use(logger('dev')); app.use(bodyParser.json()); app.use(bodyParser.urlencoded()); @@ -111,7 +111,7 @@ app.use(function(req, res, next) { app.use(express.static(path.join(__dirname, 'public'), { maxAge: week })); /** - * Application routes. + * Main routes. */ app.get('/', homeController.index); @@ -132,6 +132,10 @@ app.post('/account/password', passportConf.isAuthenticated, userController.postU app.post('/account/delete', passportConf.isAuthenticated, userController.postDeleteAccount); app.get('/account/unlink/:provider', passportConf.isAuthenticated, userController.getOauthUnlink); +/** + * API examples routes. + */ + app.get('/api', apiController.getApi); app.get('/api/lastfm', apiController.getLastfm); app.get('/api/nyt', apiController.getNewYorkTimes); @@ -157,7 +161,7 @@ app.get('/api/instagram', passportConf.isAuthenticated, passportConf.isAuthorize app.get('/api/yahoo', apiController.getYahoo); /** - * OAuth routes for sign-in. + * OAuth sign-in routes. */ app.get('/auth/instagram', passport.authenticate('instagram')); @@ -186,7 +190,7 @@ app.get('/auth/linkedin/callback', passport.authenticate('linkedin', { failureRe }); /** - * OAuth routes for API examples that require authorization. + * OAuth authorization routes for API examples. */ app.get('/auth/foursquare', passport.authorize('foursquare')); @@ -204,7 +208,6 @@ app.get('/auth/venmo/callback', passport.authorize('venmo', { failureRedirect: ' /** * 500 Error Handler. - * As of Express 4.0 it must be placed at the end, after all routes. */ app.use(errorHandler()); @@ -217,4 +220,4 @@ app.listen(app.get('port'), function() { console.log('Express server listening on port %d in %s mode', app.get('port'), app.get('env')); }); -module.exports = app; +module.exports = app; \ No newline at end of file diff --git a/controllers/user.js b/controllers/user.js index b347774b6d0..582e62b60d0 100644 --- a/controllers/user.js +++ b/controllers/user.js @@ -177,22 +177,21 @@ exports.postUpdatePassword = function(req, res, next) { /** * POST /account/delete * Delete user account. - * @param id - User ObjectId */ exports.postDeleteAccount = function(req, res, next) { User.remove({ _id: req.user.id }, function(err) { if (err) return next(err); req.logout(); + req.flash('info', { msg: 'Your account has been deleted.' }); res.redirect('/'); }); }; /** * GET /account/unlink/:provider - * Unlink OAuth2 provider from the current user. + * Unlink OAuth provider. * @param provider - * @param id - User ObjectId */ exports.getOauthUnlink = function(req, res, next) { @@ -220,7 +219,6 @@ exports.getReset = function(req, res) { if (req.isAuthenticated()) { return res.redirect('/'); } - User .findOne({ resetPasswordToken: req.params.token }) .where('resetPasswordExpires').gt(Date.now()) @@ -238,6 +236,7 @@ exports.getReset = function(req, res) { /** * POST /reset/:token * Process the reset password request. + * @param token */ exports.postReset = function(req, res, next) {