if(config.protocol == 'local') {
// check if we have a username and password to verify
var username = params[config.options.userField];
var password = params[config.options.pwdField];
if(username && password) {
return api.models.operator.find({where: {username: username}})
.then(function(operator) {
if(!operator) {
throw 'no username/password match 1';
}
return operator;
})
.then(function(operator) {
return api.models.credential.find({where: { operator_id: operator.get('id')}})
.then(function(cred) {
if(!cred) {
throw 'no username/password match 2';
}
if( cred.verifyPassword(password) ) {
// do stuff
}
else {
throw 'no username/password match 3';
}
})
.catch(function(e) {
connection.error = 'error fetching credential for: ' + operator.get('id') +'\nmessage: ' + e;
});
})
.catch(function(e) {
connection.error = 'error fetching operator: ' + username +'\nmessage: ' + e;
})
.finally(next(connection,true));
}
else {
connection.error = 'missing username and/or password';
}
}
return next(connection, true);
f(config.protocol == 'local') {
// check if we have a username and password to verify
var username = params[config.options.userField];
var password = params[config.options.pwdField];
if(username && password) {
return api.models.operator.find({where: {username: username}})
.then(function(operator) {
//console.log(operator);
if(!operator) {
throw 'no username/password match 1';
}
return operator;
})
.then(function(operator) {
return api.models.credential.find({where: { operator_id: operator.get('id')}});
})
.then(function(cred) {
//console.log(cred);
if(!cred) {
throw 'no username/password match 2';
}
if(cred.verifyPassword(password)) {
// create cookie
console.log('we good!');
}
else {
throw 'no username/password match 3';
}
})
.catch(function(e) {
//console.log(e);
connection.error = e; // TODO: user vs system error
})
.finally(function() {
next(connection,true);
'use strict';
module.exports = { loadPriority: 990, startPriority: 1000, stopPriority: 1000, initialize: function( api, next ) {
api.Promise = require( 'bluebird' );
api.Promise.promisifyAll( api.chatRoom ); api.Promise.promisifyAll( api.tasks );
next(); }, start: function( api, next ) { next(); }, stop: function( api, next ) { next(); }}
api.chatLogic.createAndJoinRoom = function( connection, roomId, extraInfo ) { return api.chatRoom.addAsync( roomId ) .then( function( count ) { api.log( '...finished adding room, now adding member. count=' + count, api.chatLogic.logLevel ); if( !count ) { api.log( 'Error initializing room [' + roomId + '].' + ( !!extraInfo ? ' info=' + JSON.stringify( extraInfo ) : '' ), 'error' ); throw new Error( 'Could not initialize room.' ); } //Room has been added, now join it return api.chatRoom.addMemberAsync( connection.id, roomId ); } ) .then( function( added ) { api.log( '...member added to room. Done! added=' + added, api.chatLogic.logLevel ); //Should always be added at this point. No other members since room just joined. return { success: added, roomId: roomId, members: [] }; } ); };
Everything you want to do should be fine... just `next.apply()` at some point :D
Hopefully the new `data` object in actionhero v11 should make this easier because there are less objects you'll need to keep in scope.