Skip to content

Instantly share code, notes, and snippets.

@js2854
Created October 1, 2018 12:05
Show Gist options
  • Save js2854/2e969017d20acf9e1dc19ec372037418 to your computer and use it in GitHub Desktop.
Save js2854/2e969017d20acf9e1dc19ec372037418 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from functools import wraps
from bottle import request
def login():
def decorator(func):
@wraps(func)
def wrapper(auth, *args, **kwargs):
try:
auth.get_user(request.environ)
return func(*args, **kwargs)
except:
return auth.redirect(request.environ)
return wrapper
return decorator
# @app.route('/')
# @login()
# def home():
# user = auth.get_user(request.environ)
# return "Home page {}".format(pformat(user))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment