Esempio n. 1
0
def remove(username):
    userid = getid(username)
    
    if userid == None:
        return False
    del db()[userid]
    return True
Esempio n. 2
0
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]
Esempio n. 3
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 
Esempio n. 4
0
 def save(self):
     if not self.is_init:
         return
     self.doc["_id"], self.doc["_rev"] = db().save(self.doc)
Esempio n. 5
0
 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
Esempio n. 6
0
 def save(self):
     if not self.changed:
         return
     self.id, self.doc["_rev"] = db().save(self.doc)
Esempio n. 7
0
 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()
Esempio n. 8
0
def authenticate(username, password):
    result = db().view("user/auth", include_doc=True, key=[username, password])
    
    for row in result:
        return row.id
Esempio n. 9
0
def getid(username):
    for row in db().view("user/auth", limit=1)[username:]:
        if(row.key[0] != username):
            return
        return row.id