Skip to content

Instantly share code, notes, and snippets.

@js2854
Forked from vsergeyev/login_required
Created September 28, 2018 01:34
Show Gist options
  • Save js2854/0ce82ef6d1d5811abb2e19b693b6c29f to your computer and use it in GitHub Desktop.
Save js2854/0ce82ef6d1d5811abb2e19b693b6c29f to your computer and use it in GitHub Desktop.
@login_required decorator to use with bottle.py
from bottle import *
from bottlepy_user_auth import User
def validate_login():
return User().loggedin
def login_required(view, check_func=validate_login):
'''
Check if user has logined to app
'''
def wrapped(*args, **kwargs):
auth = check_func()
if auth:
return view(*args, **kwargs)
return redirect('/login/')
return wrapped
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment