mirror of
https://github.com/wassname/flask-security.git
synced 2026-06-27 16:10:11 +08:00
re #343: Add slash before or after token in flask-security URLs correctly
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ from .changeable import change_user_password
|
||||
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'])
|
||||
@@ -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,
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user