Skip to content

Instantly share code, notes, and snippets.

@thalesfsp

thalesfsp/hi.js Secret

Last active August 29, 2015 13:56
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save thalesfsp/80fb332ee671e67fa0b4 to your computer and use it in GitHub Desktop.
The problem: even after return res.send(); the console.log(''Hi) is running.
'use strict';
/**
* User Controller
* @module UserController
* @author XXX
* @fileOverview User controller. Includes middlewares, CRUD and custom routes
* @version December, 2013 - API v1 - 0.0.1
*/
/**
* Module Dependencies
*/
var mongoose = require('mongoose'),
middlewares = require('./middlewares'),
resource = '/users',
lodash = require('lodash');
/**
* Module Exportation
*/
module.exports = function (app, messages, config) {
/**
* Custom Middlewares
*/
/**
* CRUD Routes
*/
app.get(resource + '/changePwd/:cancel?', [
middlewares.isAuthenticated,
middlewares.validateReqBodyAgainst(['apiKey', 'cancel'])
], function (req, res) {
User.findOne({apiKey: req.param('apiKey')}, function (err, doc) {
// if occour some error or doc not found, respond
if (err || !doc) {return res.send(404, {status: false, msg: messages.db.docNotFound || err});}
// verifies the origin
if (req.param('cancel') === 'cancel') {
// restore status
doc.status = 'activated';
// clear temporary pwd property
doc.tempPwd = '';
// save
doc.save(function (errSaving) {
// if error, respond
if (errSaving) {cb({status: false, msg: errSaving.message});}
return res.send({status: true, msg: messages.auth.processCanceled});
});
} else {
return res.send(404, {status: false, msg: messages.httpStatusCode['404']});
}
console.log('It should not RUN!');
});
});
// output:
// > It should not RUN!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment