The problem: even after return res.send(); the console.log(''Hi) is running.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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