Created
November 21, 2011 01:02
-
-
Save Krayons/1381317 to your computer and use it in GitHub Desktop.
For Poo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#views.py | |
#Response | |
from pyramid.response import Response | |
from pyramid.view import view_config | |
from pyramid.renderers import render_to_response | |
from pyramid.url import route_url | |
#Security | |
from pyramid.security import authenticated_userid | |
from pyramid.security import remember | |
from pyramid.security import forget | |
from pyramid.httpexceptions import HTTPFound | |
#You Users, (normally from a DB call) | |
USERS = {'Username':'Password'} | |
GROUPS = {'jut':['group:admin']} | |
def groupfinder(userid, request): | |
if userid in USERS: | |
return GROUPS.get(userid, []) | |
#Quick Login | |
def login(request): | |
message = '' | |
login = '' | |
password = '' | |
if 'form.submitted' in request.params: | |
login = request.params['login'] | |
password = request.params['password'] | |
if USERS.get(login) == password: | |
headers = remember(request, login) | |
return HTTPFound(location = came_from, | |
headers = headers) | |
message = 'Failed login' | |
return dict( | |
message = message, | |
url = request.application_url + '/login', | |
came_from = came_from, | |
login = login, | |
password = password, | |
) | |
#Your protected page | |
def SuperSecret_page(request): | |
#if logged in | |
if logged_in: | |
return dict() | |
#Else send HTTPForbben or Redirect | |
else: | |
return HTTPFound(location = route_url('login', request)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment