コード例 #1
0
ファイル: user.py プロジェクト: bjornua/dna
def authenticate(username, password):
    doc = None
    for x in db().view("user/auth",
                       key=[username, password],
                       include_docs=True):
        doc = x["doc"]
        break

    if doc is None:
        return

    macs = doc["macaddrs"]
    maxmacs = doc["macaddrs_max"]

    if macaddr != None:
        macs.append(macaddr)

        while len(macs) > maxmacs:
            iptables.delmac(macs.pop(0))

        if len(macs) == 0:
            return

        iptables.addmac(macaddr)

        db().save_doc(doc)

        return x["id"]
コード例 #2
0
ファイル: user.py プロジェクト: bjornua/dna
def authenticate(username, password):
    doc = None
    for x in db().view("user/auth", key=[username, password], include_docs=True):
        doc = x["doc"]
        break

    if doc is None:
        return
        
    macs = doc["macaddrs"]
    maxmacs = doc["macaddrs_max"]
    
    if macaddr != None:
        macs.append(macaddr)

        while len(macs) > maxmacs:
            iptables.delmac(macs.pop(0))
        
        if len(macs) == 0:
            return

        iptables.addmac(macaddr)
        
        db().save_doc(doc)
        
        return x["id"]
コード例 #3
0
def delete(uid, id_):
    user = db()[uid]
    entry = db()[id_]

    if entry["group"] != user["group"]:
        raise PermissionError()
    
    entry["deletedby"] = uid

    db().save_doc(entry)
コード例 #4
0
def add(username, group, password):
    password = sha224(password).hexdigest()
    db().save_doc(
        {
            "type": "user",
            "group": group,
            "password": password,
            "username": username,
            "date_added": dateutils.nowtuple(),
            "has_changed_password": False,
        }
    )
コード例 #5
0
def update(id, name, phone, email, year, rustur):
    doc = db()[id]

    for fieldname, fieldvalue in (
        ("name", name),
        ("phone", phone),
        ("email", email),
        ("year", year),
        ("rustur", rustur),
    ):
        if fieldvalue == None and fieldname in doc:
            del doc[fieldname]
        else:
            doc[fieldname] = fieldvalue
    db().save(doc)
コード例 #6
0
ファイル: user.py プロジェクト: bjornua/dna
def create(username, email, macaddrs_max, password=u""):
    if password == u"":
        password = generatepassword()
    
    userid = getid(username)
    if userid != None:
        raise UserExist("User %s already exist with id %s" % (repr(username), repr(userid)))

    db().save_doc({
        "type": "user",
        "username": username,
        "email": email,
        "macaddrs_max": macaddrs_max,
        "macaddrs": [],
        "password": password,
    })
コード例 #7
0
def getgroup(uid):
    group = user.getgroup(uid)
    q = db().view("entry/groups",
        startkey=[group+u"\ufff0"],
        endkey=[group],
        include_docs=True,
        descending=True
    )

    for x in q:
        doc = x["doc"]
        username = user.getname(doc["uid"])
        deletedby = doc.get("deletedby")
        deletedby = deletedby and user.getname(deletedby)
        user.getname(doc["uid"])
        debtors = doc["debtors"]
        debtors = dict((user.getname(x),y) for x,y in debtors)
        
        creditor = user.getname(doc["creditor"])

        yield {
            "id": doc["_id"],
            "amount": doc["amount"],
            "creditor": creditor,
            "date": dateutils.fromtuple(doc["date"]),
            "description": doc["description"],
            "debtors": debtors,
            "username": username,
            "deletedby": deletedby,
        }
コード例 #8
0
ファイル: user.py プロジェクト: bjornua/dna
def create(username, email, macaddrs_max, password=u""):
    if password == u"":
        password = generatepassword()

    userid = getid(username)
    if userid != None:
        raise UserExist("User %s already exist with id %s" %
                        (repr(username), repr(userid)))

    db().save_doc({
        "type": "user",
        "username": username,
        "email": email,
        "macaddrs_max": macaddrs_max,
        "macaddrs": [],
        "password": password,
    })
コード例 #9
0
ファイル: user.py プロジェクト: bjornua/dna
def get(uid):
    try:
        doc = db()[uid]
    except ResourceNotFound:
        raise UserDoesntExist("The user with id %s was not found" % (repr(uid),))

    if doc.get("type") != "user":
        raise UserDoesntExist("Document id %s is not a user" % (repr(uid),))

    return doc
コード例 #10
0
ファイル: user.py プロジェクト: bjornua/dna
def get(uid):
    try:
        doc = db()[uid]
    except ResourceNotFound:
        raise UserDoesntExist("The user with id %s was not found" %
                              (repr(uid), ))

    if doc.get("type") != "user":
        raise UserDoesntExist("Document id %s is not a user" % (repr(uid), ))

    return doc
コード例 #11
0
def getbalances(uid):
    group = user.getgroup(uid)
    q = db().view("entry/balances",
        startkey=[group],
        endkey=[group+u"\ufff0"],
        group=True,
        reduce=True,
        group_level=2
    )
    
    for x in q:
        yield user.getname(x["key"][1]), x["value"]
コード例 #12
0
ファイル: user.py プロジェクト: bjornua/dna
def update(uid, username=None, email=None, macaddrs_max=None, password=None):
    doc = get(uid)
    
    if username != None:
        if username != doc["username"]:
            userid = getid(username)
            if userid != None:
                raise UserExist("User %s already exist with id %s" % (repr(username), repr(userid)))
            
        doc["username"] = username

    if email != None:
        doc["email"] = email

    if macaddrs_max != None:
        doc["macaddrs_max"] = macaddrs_max
    
    if password != None:
        doc["password"] = password
    
    db().save_doc(doc)
コード例 #13
0
def main():
    views = set()
    for p in get_nodes(["views"]):
        if len(p) != 2:
            continue
        
        p = path.join(*p)

        if not path.isdir(p):
            continue
        
        couchdbkit.designer.push(p, db())
コード例 #14
0
ファイル: update_database.py プロジェクト: bjornua/dna
def main():
    views = set()
    for p in get_nodes(["views"]):
        if len(p) != 2:
            continue

        p = path.join(*p)

        if not path.isdir(p):
            continue

        couchdbkit.designer.push(p, db())
コード例 #15
0
ファイル: user.py プロジェクト: bjornua/dna
def update(uid, username=None, email=None, macaddrs_max=None, password=None):
    doc = get(uid)

    if username != None:
        if username != doc["username"]:
            userid = getid(username)
            if userid != None:
                raise UserExist("User %s already exist with id %s" %
                                (repr(username), repr(userid)))

        doc["username"] = username

    if email != None:
        doc["email"] = email

    if macaddrs_max != None:
        doc["macaddrs_max"] = macaddrs_max

    if password != None:
        doc["password"] = password

    db().save_doc(doc)
コード例 #16
0
def add(uid, group, description, amount, creditor, debtors):
    date = dateutils.totuple(dateutils.now())
    
    members = set(x[0] for x in user.getmembers(uid))

    if not creditor in members:
        raise PermissionError()

    for debtor in debtors:
        if not debtor[0] in members:
            raise PermissionError()

    db().save_doc({
        "type": "entry",
        "amount": amount,
        "creditor": creditor,
        "date": date,
        "debtors": debtors,
        "description": description,
        "group": group,
        "uid": uid,
        "deletedby":None,
    })
コード例 #17
0
def info(id):
    doc = db()[id]

    name = doc.get("name")
    phone = doc.get("phone")
    email = doc.get("email")
    year = doc.get("year")
    rustur = doc.get("rustur")
    
    id = doc.id
    name = name and unicode(name)
    phone = phone and unicode(phone)
    email = email and unicode(email)
    year = year and unicode(year)
    rustur = rustur and unicode(rustur)

    return name, phone, email, year, rustur
コード例 #18
0
def browse(page=0, perpage=10):
    skip = page * perpage
    result = db().view("rus/default", include_docs=True, skip=skip, limit=perpage, reduce=False)
    
    for row in result:
        doc = row.doc
        
        name = doc.get("name")
        phone = doc.get("phone")
        email = doc.get("email")
        year = doc.get("year")
        rustur = doc.get("rustur")
        
        id = doc.id
        name = name and unicode(name)
        phone = phone and unicode(phone)
        email = email and unicode(email)
        rustur = rustur and unicode(rustur)

        if year != None:
            year = unicode(year)
        
        yield id, name, phone, email, year, rustur
コード例 #19
0
ファイル: user.py プロジェクト: bjornua/dna
def getname(uid):
    return db()[uid]["username"]
コード例 #20
0
def browse_total_pages(perpage=10):
    result = db().view("rus/default", reduce=True)
    for row in result:
        return ((row.value - 1) // perpage) + 1
コード例 #21
0
ファイル: user.py プロジェクト: bjornua/dna
def delete(uid):
    get(uid) # Make sure the user exist and display pretty error message if not
    db().delete_doc(uid)
コード例 #22
0
ファイル: user.py プロジェクト: bjornua/dna
def list_docs():
    for x in db().view("user/auth", include_docs=True):
        yield x["doc"]
コード例 #23
0
ファイル: session.py プロジェクト: bjornua/rus-browser
 def save(self):
     if not self.changed:
         return
     self.id, self.doc["_rev"] = db().save(self.doc)
コード例 #24
0
ファイル: session.py プロジェクト: bjornua/rus-browser
 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()
コード例 #25
0
 def save(self):
     if self.is_init:
         db().save_doc(self.doc)
         self.id = self.doc["_id"]
コード例 #26
0
 def get_doc(self, id_):
     for result in db().view("session/by_id", key=id_, include_docs=True):
         return result["doc"]
コード例 #27
0
 def get_doc(self, id_):
     for result in db().view("session/by_id", key=id_, include_docs=True):
         return result["doc"]
コード例 #28
0
 def save(self):
     if self.is_init:
         db().save_doc(self.doc)
         self.id = self.doc["_id"]
コード例 #29
0
ファイル: user.py プロジェクト: bjornua/dna
def getmacs():
    for x in db().view("user/macaddr"):
        yield x["key"][0]
コード例 #30
0
def getmembers(uid):
    group = getgroup(uid)
    q = db().view("user/group", startkey=[group], endkey=[group + u"\fff0"], include_docs=True)

    for x in q:
        yield x["id"], x["doc"]["username"]
コード例 #31
0
def getname(uid):
    name = local.cache.get(("uid-name", uid))
    if name is None:
        name = db()[uid]["username"]
        local.cache[("uid-name", uid)] = name
    return name
コード例 #32
0
ファイル: user.py プロジェクト: bjornua/dna
def delete(uid):
    get(uid
        )  # Make sure the user exist and display pretty error message if not
    db().delete_doc(uid)
コード例 #33
0
ファイル: user.py プロジェクト: bjornua/dna
def getid(username):
    for x in db().view("user/auth",
                       startkey=[username, u""],
                       endkey=[username, u"\ufff0"],
                       limit=1):
        return x["id"]
コード例 #34
0
def haschangedpasswd(uid):
    return db()[uid]["has_changed_password"]
コード例 #35
0
ファイル: user.py プロジェクト: bjornua/dna
def getmacs():
    for x in db().view("user/macaddr"):
        yield x["key"][0]
コード例 #36
0
def changepassword(uid, password):
    password = sha224(password).hexdigest()
    user = db()[uid]
    user["has_changed_password"] = True
    user["password"] = password
    db().save_doc(user)
コード例 #37
0
ファイル: user.py プロジェクト: bjornua/dna
def getname(uid):
    return db()[uid]["username"]
コード例 #38
0
def getgroup(uid):
    return db()[uid]["group"]
コード例 #39
0
ファイル: user.py プロジェクト: bjornua/dna
def list_docs():
    for x in db().view("user/auth", include_docs=True):
        yield x["doc"]
コード例 #40
0
def authenticate(username, password):
    password = sha224(password).hexdigest()
    for x in db().view("user/auth", key=[username, password]):
        return x["id"]
コード例 #41
0
ファイル: user.py プロジェクト: bjornua/dna
def getid(username):
    for x in db().view("user/auth", startkey=[username, u""], endkey=[username, u"\ufff0"], limit=1):
        return x["id"]