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

Commit

Permalink
re #343: Add slash before or after token in flask-security URLs corre…
Browse files Browse the repository at this point in the history
…ctly
  • Loading branch information
Jaza committed Nov 27, 2014
1 parent c7d0ea9 commit 4d70f01
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 6 additions & 0 deletions flask_security/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ def get_url(endpoint_or_url):
return endpoint_or_url


def slash_url_suffix(url, suffix):
"""Adds a slash either to the beginning or the end of a suffix (which is to be appended to a URL), depending on whether or not the URL ends with a slash."""

return url.endswith('/') and ('%s/' % suffix) or ('/%s' % suffix)


def get_security_endpoint_name(endpoint):
return '%s.%s' % (_security.blueprint_name, endpoint)

Expand Down
8 changes: 4 additions & 4 deletions flask_security/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from .registerable import register_user
from .utils import config_value, do_flash, get_url, get_post_login_redirect, \
get_post_register_redirect, get_message, login_user, logout_user, \
url_for_security as url_for
url_for_security as url_for, slash_url_suffix

# Convenient references
_security = LocalProxy(lambda: current_app.extensions['security'])
Expand Down Expand Up @@ -333,7 +333,7 @@ def create_blueprint(state, import_name):
bp.route(state.login_url,
methods=['GET', 'POST'],
endpoint='login')(send_login)
bp.route(state.login_url + '/<token>',
bp.route(state.login_url + slash_url_suffix(state.login_url, '<token>'),
endpoint='token_login')(token_login)
else:
bp.route(state.login_url,
Expand All @@ -349,7 +349,7 @@ def create_blueprint(state, import_name):
bp.route(state.reset_url,
methods=['GET', 'POST'],
endpoint='forgot_password')(forgot_password)
bp.route(state.reset_url + '/<token>',
bp.route(state.reset_url + slash_url_suffix(state.reset_url, '<token>'),
methods=['GET', 'POST'],
endpoint='reset_password')(reset_password)

Expand All @@ -362,7 +362,7 @@ def create_blueprint(state, import_name):
bp.route(state.confirm_url,
methods=['GET', 'POST'],
endpoint='send_confirmation')(send_confirmation)
bp.route(state.confirm_url + '/<token>',
bp.route(state.confirm_url + slash_url_suffix(state.confirm_url, '<token>'),
methods=['GET', 'POST'],
endpoint='confirm_email')(confirm_email)

Expand Down

0 comments on commit 4d70f01

Please sign in to comment.