Let owners tweak users to their utter enjoyment.

This commit is contained in:
Jeremy Fincher 2004-04-30 05:45:05 +00:00
parent 95ef531cb2
commit f9442d9483
2 changed files with 61 additions and 41 deletions

View File

@ -1,3 +1,8 @@
* Changed User.{addhostmask,removehostmask,register,unregister}
to allow owner users to do what they will with their users. You
can now add hostmasks, remove hostmasks, register users, and
unregister users willy-nilly.
* Changed and moved several configuration variables. * Changed and moved several configuration variables.
supybot.{throttleTime,maxHistoryLength,pingServer,pingInterval} supybot.{throttleTime,maxHistoryLength,pingServer,pingInterval}
all moved to supybot.protocols.irc; supybot.httpPeekSize moved to all moved to supybot.protocols.irc; supybot.httpPeekSize moved to

View File

@ -107,7 +107,8 @@ class User(callbacks.Privmsg):
""" """
(optlist, rest) = getopt.getopt(args, '', ['hashed']) (optlist, rest) = getopt.getopt(args, '', ['hashed'])
(name, password) = privmsgs.getArgs(rest, required=2) (name, password) = privmsgs.getArgs(rest, required=2)
hashed = False addHostmask = True
hashed = conf.supybot.databases.users.hash()
for (option, arg) in optlist: for (option, arg) in optlist:
if option == '--hashed': if option == '--hashed':
hashed = True hashed = True
@ -123,6 +124,9 @@ class User(callbacks.Privmsg):
return return
try: try:
u = ircdb.users.getUser(msg.prefix) u = ircdb.users.getUser(msg.prefix)
if u.checkCapability('owner'):
addHostmask = False
else:
irc.error('Your hostmask is already registered to %s' % u.name) irc.error('Your hostmask is already registered to %s' % u.name)
return return
except KeyError: except KeyError:
@ -130,28 +134,32 @@ class User(callbacks.Privmsg):
(id, user) = ircdb.users.newUser() (id, user) = ircdb.users.newUser()
user.name = name user.name = name
user.setPassword(password, hashed=hashed) user.setPassword(password, hashed=hashed)
if addHostmask:
user.addHostmask(msg.prefix) user.addHostmask(msg.prefix)
ircdb.users.setUser(id, user) ircdb.users.setUser(id, user)
irc.replySuccess() irc.replySuccess()
def unregister(self, irc, msg, args): def unregister(self, irc, msg, args):
"""<name> <password> """<name> [<password>]
Unregisters <name> from the user database. Unregisters <name> from the user database. If the user giving this
command is an owner user, the password is not necessary.
""" """
(name, password) = privmsgs.getArgs(args, required=2) (name, password) = privmsgs.getArgs(args, optional=1)
self._checkNotChannel(irc, msg, password) self._checkNotChannel(irc, msg, password)
try: try:
id = ircdb.users.getUserId(name) id = ircdb.users.getUserId(name)
user = ircdb.users.getUser(id) u = ircdb.users.getUser(id)
except KeyError: except KeyError:
irc.error('That username isn\'t registered.') irc.error('That username isn\'t registered.')
return return
if user.checkPassword(password): if not u.checkPassword(password):
u = ircdb.users.getUser(msg.prefix)
if not u.checkCapability('owner'):
irc.error(conf.supybot.replies.incorrectAuthentication())
return
ircdb.users.delUser(id) ircdb.users.delUser(id)
irc.replySuccess() irc.replySuccess()
else:
irc.error(conf.supybot.replies.incorrectAuthentication())
def changename(self, irc, msg, args): def changename(self, irc, msg, args):
"""<name> <new name> [<password>] """<name> <new name> [<password>]
@ -186,7 +194,9 @@ class User(callbacks.Privmsg):
Adds the hostmask <hostmask> to the user specified by <name>. The Adds the hostmask <hostmask> to the user specified by <name>. The
<password> may only be required if the user is not recognized by <password> may only be required if the user is not recognized by
hostmask. If you include the <password> parameter, this message must hostmask. If you include the <password> parameter, this message must
be sent to the bot privately (not on a channel). be sent to the bot privately (not on a channel). <password> is also
not required if an owner user is giving the command on behalf of some
other user.
""" """
(name, hostmask, password) = privmsgs.getArgs(args, 2, 1) (name, hostmask, password) = privmsgs.getArgs(args, 2, 1)
self._checkNotChannel(irc, msg, password) self._checkNotChannel(irc, msg, password)
@ -210,7 +220,12 @@ class User(callbacks.Privmsg):
return return
except KeyError: except KeyError:
pass pass
if user.checkHostmask(msg.prefix) or user.checkPassword(password): if not user.checkPassword(password) and \
not user.checkHostmask(msg.prefix):
u = ircdb.users.getUser(msg.prefix)
if not u.checkCapability('owner'):
irc.error(conf.supybot.replies.incorrectAuthentication())
return
try: try:
user.addHostmask(hostmask) user.addHostmask(hostmask)
except ValueError, e: except ValueError, e:
@ -218,9 +233,6 @@ class User(callbacks.Privmsg):
return return
ircdb.users.setUser(id, user) ircdb.users.setUser(id, user)
irc.replySuccess() irc.replySuccess()
else:
irc.error(conf.supybot.replies.incorrectAuthentication())
return
def removehostmask(self, irc, msg, args): def removehostmask(self, irc, msg, args):
"""<name> <hostmask> [<password>] """<name> <hostmask> [<password>]
@ -239,7 +251,12 @@ class User(callbacks.Privmsg):
except KeyError: except KeyError:
irc.errorNoUser() irc.errorNoUser()
return return
if user.checkHostmask(msg.prefix) or user.checkPassword(password): if not user.checkPassword(password) and \
not user.checkHostmask(msg.prefix):
u = ircdb.users.getUser(msg.prefix)
if not u.checkCapability('owner'):
irc.error(conf.supybot.replies.incorrectAuthentication())
return
try: try:
s = '' s = ''
if hostmask == 'all': if hostmask == 'all':
@ -252,9 +269,6 @@ class User(callbacks.Privmsg):
return return
ircdb.users.setUser(id, user) ircdb.users.setUser(id, user)
irc.replySuccess(s) irc.replySuccess(s)
else:
irc.error(conf.supybot.replies.incorrectAuthentication())
return
def setpassword(self, irc, msg, args): def setpassword(self, irc, msg, args):
"""[--hashed] <name> <old password> <new password> """[--hashed] <name> <old password> <new password>
@ -263,12 +277,13 @@ class User(callbacks.Privmsg):
<new password>. Obviously this message must be sent to the bot <new password>. Obviously this message must be sent to the bot
privately (not in a channel). If --hashed is given, the password will privately (not in a channel). If --hashed is given, the password will
be hashed on disk (rather than being stored in plaintext. If the be hashed on disk (rather than being stored in plaintext. If the
requesting user is an owner user, the <old password> needn't be requesting user is an owner user (and the user whose password is being
changed isn't that same owner user), then <old password> needn't be
correct. correct.
""" """
(optlist, rest) = getopt.getopt(args, '', ['hashed']) (optlist, rest) = getopt.getopt(args, '', ['hashed'])
(name, oldpassword, newpassword) = privmsgs.getArgs(rest, 3) (name, oldpassword, newpassword) = privmsgs.getArgs(rest, 3)
hashed = False hashed = conf.supybot.databases.users.hash()
for (option, arg) in optlist: for (option, arg) in optlist:
if option == '--hashed': if option == '--hashed':
hashed = True hashed = True
@ -279,9 +294,9 @@ class User(callbacks.Privmsg):
except KeyError: except KeyError:
irc.errorNoUser() irc.errorNoUser()
return return
requester = ircdb.users.getUser(msg.prefix) u = ircdb.users.getUser(msg.prefix)
if user.checkPassword(oldpassword) or \ if user.checkPassword(oldpassword) or \
(requester.checkCapability('owner') and not requester == user): (u.checkCapability('owner') and not u == user):
user.setPassword(newpassword, hashed=hashed) user.setPassword(newpassword, hashed=hashed)
ircdb.users.setUser(id, user) ircdb.users.setUser(id, user)
irc.replySuccess() irc.replySuccess()