Last active
August 2, 2024 09:52
-
-
Save scott2b/7539594 to your computer and use it in GitHub Desktop.
Revisions
-
scott2b revised this gist
Nov 19, 2013 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,6 @@ from pyramid.view import view_config from pyramid.security import remember from pyramid.security import authenticated_userid from pyramid_persona.views import verify_login USE_WHITELIST = False -
scott2b revised this gist
Nov 19, 2013 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -29,6 +29,14 @@ def email_blacklist(): return [] @view_config(route_name='new_user', renderer='templates/new_user.jinja2') def new_user_view(request): email = authenticated_userid(request) return { 'email': email } @view_config(route_name='login', check_csrf=True, renderer='json') def login(request): email = verify_login(request) -
scott2b created this gist
Nov 19, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,58 @@ from pyramid.view import view_config from pyramid.security import remember from pyramid_persona.views import verify_login USE_WHITELIST = False WHITELIST_REJECT_MESSAGE = 'Sorry, you are not authorized to access this site.' WHITELIST_REJECT_REDIRECT = '/' USE_BLACKLIST = False BLACKLIST_REJECT_MESSAGE = 'Sorry, you are not authorized to access this site.' BLACKLIST_REJECT_REDIRECT = '/' NEW_USER_REDIRECT = None REDIRECT = '/' def user_exists(email): """TODO: Implement me""" return False def create_profile(email): """TODO: Implement me""" pass def email_whitelist(): return [] def email_blacklist(): return [] @view_config(route_name='login', check_csrf=True, renderer='json') def login(request): email = verify_login(request) if USE_WHITELIST and email not in email_whitelist(): request.session.flash(WHITELIST_REJECT_MESSAGE) return { 'redirect': '/', 'success': False } if USE_BLACKLIST and email in email_blacklist(): request.session.flash(BLACKLIST_REJECT_MESSAGE) return { 'redirect': '/', 'success': False } request.response.headers.extend(remember(request, email)) if not user_exists(email): create_profile(email) if NEW_USER_REDIRECT is not None: return { 'redirect': '/new-user', 'success': True } return { 'redirect': REDIRECT, 'success': True }