diff --git a/flask_security/utils.py b/flask_security/utils.py index fa0b17d..0aca374 100644 --- a/flask_security/utils.py +++ b/flask_security/utils.py @@ -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) diff --git a/flask_security/views.py b/flask_security/views.py index 8acb5fd..e9d8a57 100644 --- a/flask_security/views.py +++ b/flask_security/views.py @@ -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']) @@ -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 + '/', + bp.route(state.login_url + slash_url_suffix(state.login_url, ''), endpoint='token_login')(token_login) else: bp.route(state.login_url, @@ -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 + '/', + bp.route(state.reset_url + slash_url_suffix(state.reset_url, ''), methods=['GET', 'POST'], endpoint='reset_password')(reset_password) @@ -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 + '/', + bp.route(state.confirm_url + slash_url_suffix(state.confirm_url, ''), methods=['GET', 'POST'], endpoint='confirm_email')(confirm_email)