From 0dfd3ea31a3ecc2d637e2c128f1f17871beacb2c Mon Sep 17 00:00:00 2001 From: andrea Date: Sat, 11 Feb 2017 15:33:32 +0100 Subject: [PATCH 1/3] added sample parameters for jwt --- config.sample.json | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/config.sample.json b/config.sample.json index de7e198..49a3ce9 100644 --- a/config.sample.json +++ b/config.sample.json @@ -2,7 +2,13 @@ create a db_config.json here's */ { - "config":{ - "db_params":{"uri":"postgresql://user:password@host:port/dbname"} + "config": { + "db_params": { + "uri": "postgresql://user:password@host:port/dbname" + }, + "jwt": { + "secret": "secret", + "expire_seconds": 3600 + } } } \ No newline at end of file From 1ea4ec5df619e4787a41bc67c328a52488ea0a10 Mon Sep 17 00:00:00 2001 From: andrea Date: Sat, 11 Feb 2017 15:33:48 +0100 Subject: [PATCH 2/3] load user --- dbmanager.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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 + From 49dce8ecaa877ad8b402d1f45c892a6be814577e Mon Sep 17 00:00:00 2001 From: Andrea Zucchelli Date: Sun, 19 Feb 2017 23:39:05 +0100 Subject: [PATCH 3/3] CORS + fake login --- server.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/server.py b/server.py index 58a6fb3..c50be84 100644 --- a/server.py +++ b/server.py @@ -1,10 +1,10 @@ -from bottle import route, run,template,app,default_app +from bottle import route, run,template,app,default_app,request,response,get,post import logging import json import os logging.basicConfig(level=logging.DEBUG,) -log=logging.getLogger("rudemaps") +log=logging.getLogger("rudemaps: "+__name__) CONFIG={} @@ -27,14 +27,29 @@ def root(): def myName(item): return template('map_template', item=item) -load_config() +@get('/login') +@post('/login') +def login(): + #response.status_="403 Login failed" + response.headers['Access-Control-Allow-Origin'] = '*' + print request.body + return {"status":"KO","error":"login failed"} + +@route('/<:re:.*>', method='OPTIONS') +def enableCORSGenericRoute(): + print 'Generic regex route' + response.headers['Access-Control-Allow-Origin'] = '*' + response.headers['Access-Control-Allow-Methods'] = "POST, GET, OPTIONS" + response.headers['Access-Control-Allow-Headers'] = "content-type" if __name__=='__main__': #DEVEL SERVER from bottle import debug debug(True) - run(host='localhost', port=9093,reloader=True) + load_config() + run(host='localhost', port=8080,reloader=True) else: #WSGI + load_config() os.chdir(os.path.dirname(__file__)) application = default_app()