diff --git a/config.sample.json b/config.sample.json index c4b9ac4..49a3ce9 100644 --- a/config.sample.json +++ b/config.sample.json @@ -1,9 +1,14 @@ /* -create a db_config.json here's a sample +create a db_config.json here's */ { - "config":{ - "db_params":{"uri":"postgresql://user:password@host:port/dbname"}, - "jwt_secret":"Secret for jwt encryption" + "config": { + "db_params": { + "uri": "postgresql://user:password@host:port/dbname" + }, + "jwt": { + "secret": "secret", + "expire_seconds": 3600 + } } } \ No newline at end of file diff --git a/dbmanager.py b/dbmanager.py index 034b4c6..9c1f782 100644 --- a/dbmanager.py +++ b/dbmanager.py @@ -1,10 +1,17 @@ import psycopg2 - +import psycopg2.extras class DbManager(object): def __init__(self,db_uri): self.db_uri=db_uri - self.conn=psycopg2.connect(db_uri) + self.conn=psycopg2.connect(db_uri,cursor_factory=psycopg2.extras.DictCursor) + + def load_user(self,username): + with self.conn.cursor() as c: + c.execute("select * from users where username=%s",(username,)) + user=c.fetchOne() + return user + diff --git a/server.py b/server.py index 995d15b..90e40ac 100644 --- a/server.py +++ b/server.py @@ -10,7 +10,6 @@ log=logging.getLogger("rudemaps") CONFIG={} - def load_config(config_file="config.json"): global CONFIG log.debug("loading configuration file")