def _get_and_validate_user(self, username, password): user = User.get_by_user_id(username) if user == None or not user.validate_password(password): raise AuthenticationError( 'Username or password does not match.' ) return user
def get_user(self, username): user = User.get_by_user_id(username) return { 'user_id': user.user_id, 'ldap_id': user.ldap_id, 'banned': user.banned, 'gets_mail': user.gets_mail, }
def get_tweets(self, username = None, limit = 20): if username == None: posts = Post.get_last(limit) else: posts = Post.get_by_user_id(username, limit) return map( lambda x: { 'poster': User.get_by_user_id(x.poster_id).ldap_id, 'status_id': x.status_id }, posts )
def do_identify(self, username, password): nick = self._get_nick() user = User.get_by_user_id(username) login_error_reply = "Username or password is wrong." if user == None: reply = login_error_reply else: if user.login(self.event.source(), password): reply = "You are now identified as %s." % user.user_id else: reply = login_error_reply self._do_reply(reply)
def _set_bann(self, username, bann_status): try: if username[0] == '@': bannee = User.get_by_user_id(username[1:]) else: bannee = User.get_by_irc_id(username) banner = User.get_by_irc_id(self.event.source()) if banner.banned: reply = 'You are banned.' elif not banner.admin: reply = 'You are no admin.' elif bannee != None: if bannee.user_id == banner.user_id: reply = 'You can\'t %sban yourself.' % ('' if bann_status else 'un') else: bannee.banned = bann_status reply = 'You %sbanned user %s.' % ('' if bann_status else 'un', bannee.user_id) else: reply = 'User %s does not exist.' % username except User.NotLoggedIn, e: reply = str(e)
def do_admin(self,username): try: if username[0] == '@': user = User.get_by_user_id(username[1:]) else: user = User.get_by_irc_id(username) admin = User.get_by_irc_id(self.event.source()) if admin == None: reply = 'You are no admin.' elif not admin.admin: reply = 'You are no admin.' elif user != None: if user.user_id != admin.user_id: user.admin = not user.admin if user.admin: reply = 'You made %s an admin.' % user.user_id else: reply = 'You took admin rights from %s.' % user.user_id else: reply = 'You can not strip yourself of your admin rights.' except User.NotLoggedIn, e: reply = str(e)