Skip to content

Instantly share code, notes, and snippets.

@val314159
Last active August 29, 2015 14:06
Show Gist options
  • Save val314159/48217eca901c2afb29a4 to your computer and use it in GitHub Desktop.
Save val314159/48217eca901c2afb29a4 to your computer and use it in GitHub Desktop.
authsvr.py
PYTHONPATH=`pwd`
export PYTHONPATH
git clone https://github.com/FedericoCeratto/bottle-cork.git
git clone https://gist.github.com/d448af5cc4111bc5de2d.git
ln -s d448af5cc4111bc5de2d/cors.py
cp -r bottle-cork/examples authsvr
cp -r authsvr/example_conf authsvr/conf.auth
if [ -e v ]; then ( echo "exists, skipping" ) else ( virtualenv .v ) fi
cat >env.sh<<EOF
source .v/bin/activate
source ~/.gmail.sh
run_authsvr(){ cd authsvr; python authsvr.py; }
EOF
. env.sh
pip install flask;(cd bottle-cork; python setup.py install)
cd authsvr; cat >authsvr.py<<EOF
from simple_webapp import *
##
import bottle,cors,json
@bottle.get('/auth/login/<username>/<password>')
def login(username,password):
cors.add_headers(bottle.response)
try:
if aaa.login(username, password):
return dict(uuid=aaa.user(username).description)
except: pass
return dict(success=False)
@bottle.get('/auth/require/<username>')
@bottle.get('/auth/require/<username>/<role>')
def require(username,role=None):
cors.add_headers(bottle.response)
try:
aaa.require(username,role)
return dict(uuid=aaa.user(username).description)
except: pass
return dict(success=False)
##
from os import environ as E
aaa.__init__('conf.auth',email_sender=E['EMAIL_SENDER'],
smtp_url=E['SMTP_URL'])
##
import uuid
def u1():return str(uuid.uuid1())
def u4():return str(uuid.uuid4())
def u(): return json.dumps(dict(uuid=u1(),key0=u1(),key1=u4()))
def setd(d,k,v):d[k]=v;return d,k,v
aaa.register=lambda __=aaa.register,*a,**kw: \
__(*a,**setd(kw,'description',u())[0])
##
if __name__=='__main__': bottle.run(quiet=False,reloader=True,debug=True)
EOF
run(){ run_authsvr; }
$*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment