Permalink
Browse files

Merge branch 'fix_auth'

Fixes #5
  • Loading branch information...
2 parents 73e8e61 + 603ec26 commit 3ba795032fa9f413c54e04c6f8858ef3187ea136 @mythmon mythmon committed Aug 14, 2012
Showing with 24 additions and 28 deletions.
  1. +9 −9 auth.js
  2. +7 −6 standup-irc.js
  3. +8 −13 utils.js
View
18 auth.js
@@ -29,24 +29,24 @@ this.AuthManager.prototype.notice = function(nick, message) {
if (level >= this.neededLevel) {
user.auth = true;
- user.emitter.emit('authorized');
+ user.emitter.emit('authorization', true);
} else {
user.auth = false;
- user.emitter.emit('unauthorized');
+ user.emitter.emit('authorization', false);
}
}
};
this.AuthManager.prototype.checkUser = function(nick) {
var self = this;
var user = this._user(nick);
- if (user.auth) {
- process.nextTick(function() {
- user.emitter.emit('authorized');
- });
- } else {
- self._askNickserv(nick);
- }
+ process.nextTick(function() {
+ if (user.auth) {
+ user.emitter.emit('authorization', true);
+ } else {
+ self._askNickserv(nick);
+ }
+ });
return user.emitter;
};
View
@@ -132,7 +132,7 @@ client.on('message', function(user, channel, msg) {
client.on('notice', function(from, to, text) {
if (from === undefined) {
- console.log('Service Notice: ' + text);
+ logger.info('Service Notice: ' + text);
from = '';
}
from = from.toLowerCase();
@@ -198,11 +198,12 @@ var commands = {
/* Check a user's authorization status. */
'trust': function(user, channel, message, args) {
var a = authman.checkUser(args);
- a.once('authorized', function() {
- client.say(channel, 'I trust ' + args);
- });
- a.once('unauthorized', function() {
- client.say(channel, "I don't trust " + args);
+ a.once('authorization', function(trust) {
+ if (trust) {
+ client.say(channel, 'I trust ' + args);
+ } else {
+ client.say(channel, "I don't trust " + args);
+ }
});
},
View
@@ -56,19 +56,14 @@ this.request = request;
this.ifAuthorized = function(user, channel, func) {
var a = authman.checkUser(user);
- function doTrust() {
- a.removeListener(dontTrust);
- func();
- }
-
- function dontTrust() {
- a.removeListener(trust);
- client.say(channel, "I don't trust you, " + user + ", " +
- "are you identified with nickserv?");
- }
-
- a.once('authorized', doTrust);
- a.once('unauthorized', dontTrust);
+ a.once('authorization', function(trust) {
+ if (trust) {
+ func();
+ } else {
+ client.say(channel, "I don't trust you, " + user + ", " +
+ "are you identified with nickserv?");
+ }
+ });
return a;
};

0 comments on commit 3ba7950

Please sign in to comment.