Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Expand authentication module to make space for email auth code
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitpaulk committed Jul 13, 2017
1 parent 6431268 commit bf076dc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions gratipay/security/authentication/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from __future__ import absolute_import, division, print_function, unicode_literals
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from gratipay.security.crypto import constant_time_compare
from gratipay.security.user import User, SESSION


ANON = User()

def _get_user_via_api_key(api_key):
Expand Down Expand Up @@ -56,11 +55,6 @@ def _turn_off_csrf(request):
request.headers.cookie['csrf_token'] = csrf_token
request.headers['X-CSRF-TOKEN'] = csrf_token

def start_user_as_anon():
"""Make sure we always have a user object, regardless of exceptions during authentication.
"""
return {'user': ANON}

def authenticate_user_if_possible(request, user):
"""This signs the user in.
"""
Expand All @@ -86,3 +80,8 @@ def add_auth_to_response(response, request=None, user=ANON):
if SESSION in request.headers.cookie:
if not user.ANON:
user.keep_signed_in(response.headers.cookie)

def start_user_as_anon():
"""Make sure we always have a user object, regardless of exceptions during authentication.
"""
return {'user': ANON}
9 changes: 5 additions & 4 deletions gratipay/website.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from aspen.website import Website as BaseWebsite

from . import utils, security, typecasting, version
from .security import authentication, csrf
from .security import csrf
from .security.authentication import website_helpers as auth_helpers
from .utils import erase_cookie, http_caching, i18n, set_cookie, set_version_header, timer
from .renderers import csv_dump, jinja2_htmlescaped, eval_, scss
from .models import team
Expand Down Expand Up @@ -86,8 +87,8 @@ def modify_algorithm(self, tell_sentry):
utils.use_tildes_for_participants,
algorithm['redirect_to_base_url'],
i18n.set_up_i18n,
authentication.start_user_as_anon,
authentication.authenticate_user_if_possible,
auth_helpers.start_user_as_anon,
auth_helpers.authenticate_user_if_possible,
security.only_allow_certain_methods,
csrf.extract_token_from_cookie,
csrf.reject_forgeries,
Expand All @@ -106,7 +107,7 @@ def modify_algorithm(self, tell_sentry):
algorithm['get_response_for_exception'],

set_version_header,
authentication.add_auth_to_response,
auth_helpers.add_auth_to_response,
csrf.add_token_to_response,
http_caching.add_caching_to_response,
security.add_headers_to_response,
Expand Down

0 comments on commit bf076dc

Please sign in to comment.