Skip to content

Instantly share code, notes, and snippets.

@scott2b
Last active August 2, 2024 09:52
Show Gist options
  • Select an option

  • Save scott2b/7539594 to your computer and use it in GitHub Desktop.

Select an option

Save scott2b/7539594 to your computer and use it in GitHub Desktop.

Revisions

  1. scott2b revised this gist Nov 19, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions auth_views.py
    Original 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
  2. scott2b revised this gist Nov 19, 2013. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions auth_views.py
    Original 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)
  3. scott2b created this gist Nov 19, 2013.
    58 changes: 58 additions & 0 deletions auth_views.py
    Original 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
    }