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

Commit

Permalink
Merge pull request #347 from Jaza/slash-url-suffix
Browse files Browse the repository at this point in the history
re #343: Add slash before or after token in flask-security URLs correctly
  • Loading branch information
Matt Wright committed May 2, 2015
2 parents cd8982f + 665b164 commit 4d3c1c0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 8 additions & 0 deletions flask_security/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ 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 @@ -334,7 +334,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 @@ -350,7 +350,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 @@ -363,7 +363,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 4d3c1c0

Please sign in to comment.