def remove(username): userid = getid(username) if userid == None: return False del db()[userid] return True
def create(username, password): userid = getid(username) if not userid == None: raise UserExists("User %s exists with id %s" % (repr(username), repr(userid))) user = { "type": "user", "time_created": nowtuple(), "username": username, "password": password, } return db().save(user)[0]
def search(channel, word): result = db().view("chanmsg/search", include_docs=True, limit=1, startkey=[channel, word], endkey=[channel, word + u"\u9999"], ) for row in result: doc = row.doc time = fromtuple(doc["time"]) sender = doc["sender_nick"] msg = doc["msg"] return time, sender, msg
def save(self): if not self.is_init: return self.doc["_id"], self.doc["_rev"] = db().save(self.doc)
def load_session(self): for row in db().view("session/by_sender", include_docs=True)[self.nick, self.host]: self.doc = row.doc return True return False
def save(self): if not self.changed: return self.id, self.doc["_rev"] = db().save(self.doc)
def load_session(self): try: self.doc = list(db().view("session/by_id", key=self.id, include_docs=True))[0].doc except IndexError: raise InvalidCookieException()
def authenticate(username, password): result = db().view("user/auth", include_doc=True, key=[username, password]) for row in result: return row.id
def getid(username): for row in db().view("user/auth", limit=1)[username:]: if(row.key[0] != username): return return row.id