Esempio n. 1
0
File: api.py Progetto: kreopt/pyapi
def get_credentials(sid):
    credentials = mc.get(mc_cred_key(sid))
    if not credentials:
        credentials = {}
        if sid:
            conn, cur=get_cursor('default')
            cur.execute("select id as user_id, "
                        "(select COALESCE(array_agg(role_id), ARRAY[]::integer[]) from user_roles where user_id=users.id) as roles "
                        "from users where id=(select user_id from session where id=%s and expires>%s)", (sid, datetime.now()))
            credentials=cur.fetchone()
            if not credentials:
                credentials={}
            release_cursor('default', cur, conn)
        mc.set(mc_cred_key(sid), credentials)
    return credentials
Esempio n. 2
0
File: api.py Progetto: kreopt/pyapi
 def __init__(self, db_name):
     self.conn, self.db = get_cursor(db_name)
     self.db_name=db_name
     self.request=None