def admin(): """Only admin users can see this""" backend.require(role='admin', fail_redirect='/sorry_page') return dict( current_user=backend.current_user, users=backend.list_users(), roles=backend.list_roles())
def auth_require(): """Only authenticated users can see this""" add_headers(bottle.response) if bottle.request.method in ['HEAD','OPTIONS']: return [] try: if backend.require(): return dict() except: pass return dict(success=False, errmsg='Access Denied')
def show_current_user_role(): """Show current user role""" session = bottle.request.environ.get('beaker.session') print "Session from simple_webapp", repr(session) backend.require(fail_redirect='/login') return backend.current_user.role
def restricted_download(): """Only authenticated users can download this file""" backend.require(fail_redirect='/login') return bottle.static_file('static_file', root='.')
def index(): """Only authenticated users can see this""" backend.require(fail_redirect='/login') return 'Welcome! <a href="/admin">Admin page</a> <a href="/logout">Logout</a>'