You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
briancavalier edited this page Nov 3, 2012
·
1 revision
/** * Finds user by email or username. * * @param {String} query */User.findByEmailOrUsername=function(query){varpromises=[];promises.push(User.exists({email: query}));promises.push(User.exists({username: query}));returnwhen.any(promises);}/** * Tests if user exists based on given parameters. * * returns user's id if user exists and false otherwise. * @param {Object} search */User.exists=function(search){vardeferred=when.defer();User.find(search,function(err,ids){if(err||ids.length==0){deferred.reject(newError('user not found'));}else{deferred.resolve(ids[0]);}});returndeferred.promise;}