route declaration scheme

This commit is contained in:
iou1name 2019-10-17 13:37:35 -04:00
parent 660fcfd138
commit c0df27cf96
2 changed files with 16 additions and 15 deletions

10
auth.py
View File

@ -73,7 +73,7 @@ def auth_required(func):
return wrapper
@routes.post(config.url_prefix + '/register/begin', name='register_begin')
@routes.post('/register/begin', name='register_begin')
@auth_required
async def register_begin(request):
user_id = request['session']['id']
@ -96,7 +96,7 @@ async def register_begin(request):
return resp
@routes.post(config.url_prefix + '/register/complete',name='register_complete')
@routes.post('/register/complete',name='register_complete')
@auth_required
async def register_complete(request):
user_id = request['session']['id']
@ -135,8 +135,7 @@ async def register_complete(request):
return resp
@routes.post(config.url_prefix + '/authenticate/begin',
name='authenticate_begin')
@routes.post('/authenticate/begin', name='authenticate_begin')
async def authenticate_begin(request):
user_id = int(request.cookies.get('userid'))
if not user_id:
@ -156,8 +155,7 @@ async def authenticate_begin(request):
return resp
@routes.post(config.url_prefix + '/authenticate/complete',
name='authenticate_complete')
@routes.post('/authenticate/complete', name='authenticate_complete')
async def authenticate_complete(request):
user_id = int(request.cookies.get('userid'))

View File

@ -23,8 +23,8 @@ import config
uvloop.install()
routes = web.RouteTableDef()
@routes.get(config.url_prefix + '/', name='index')
@routes.post(config.url_prefix + '/', name='index')
@routes.get('/', name='index')
@routes.post('/', name='index')
@auth.auth_required
async def index(request):
"""The index page."""
@ -77,8 +77,8 @@ async def index(request):
return render_template("index.html", request, locals())
@routes.get(config.url_prefix + '/login', name='login')
@routes.post(config.url_prefix + '/login', name='login')
@routes.get('/login', name='login')
@routes.post('/login', name='login')
async def login(request):
"""Handle login."""
login_failed = False
@ -147,8 +147,8 @@ async def login(request):
return render_template("login.html", request, locals())
@routes.get(config.url_prefix + '/register', name='register')
@routes.post(config.url_prefix + '/register', name='register')
@routes.get('/register', name='register')
@routes.post('/register', name='register')
async def register(request):
"""Register new accounts."""
confirm_token = request.query.get('confirm')
@ -208,7 +208,7 @@ async def register(request):
return render_template("register_result.html", request, locals())
@routes.get(config.url_prefix + '/add_key', name='add_key')
@routes.get('/add_key', name='add_key')
@auth.auth_required
async def add_key(request):
"""Add a new security key."""
@ -216,7 +216,7 @@ async def add_key(request):
return render_template("register_key.html", request, locals())
@routes.get(config.url_prefix + '/get_session', name='get_session')
@routes.get('/get_session', name='get_session')
async def get_session(request):
"""Returns a user's application session."""
# TODO: only allow LAN IPs
@ -284,7 +284,7 @@ async def get_session(request):
return web.json_response(error)
@routes.post(config.url_prefix + '/set_session', name='set_session')
@routes.post('/set_session', name='set_session')
async def set_session(request):
"""Allows an application to set a user app session."""
# TODO: only allow LAN IPs
@ -339,6 +339,9 @@ async def init_app():
app.router.add_routes(routes)
app.router.add_routes(auth.routes)
app_wrap = web.Application()
app_wrap.add_subapp(config.url_prefix, app)
return app
if __name__ == "__main__":