diff --git a/flask_security/core.py b/flask_security/core.py index 7e922b4..fb2a6b6 100644 --- a/flask_security/core.py +++ b/flask_security/core.py @@ -350,6 +350,9 @@ class _SecurityState(object): rv.update(fn()) return rv + def context_processor(self, fn): + self._add_ctx_processor(None, fn) + def forgot_password_context_processor(self, fn): self._add_ctx_processor('forgot_password', fn) diff --git a/tests/templates/custom_security/change_password.html b/tests/templates/custom_security/change_password.html index 75ab2c0..129ab38 100644 --- a/tests/templates/custom_security/change_password.html +++ b/tests/templates/custom_security/change_password.html @@ -1,3 +1,3 @@ CUSTOM CHANGE PASSWORD - +{{ global }} {{ foo }} diff --git a/tests/templates/custom_security/forgot_password.html b/tests/templates/custom_security/forgot_password.html index 5cdf923..f6df583 100644 --- a/tests/templates/custom_security/forgot_password.html +++ b/tests/templates/custom_security/forgot_password.html @@ -1,3 +1,3 @@ CUSTOM FORGOT PASSWORD - +{{ global }} {{ foo }} diff --git a/tests/templates/custom_security/login_user.html b/tests/templates/custom_security/login_user.html index 504db8a..e8aa4e6 100644 --- a/tests/templates/custom_security/login_user.html +++ b/tests/templates/custom_security/login_user.html @@ -1,3 +1,3 @@ CUSTOM LOGIN USER - +{{ global }} {{ foo }} diff --git a/tests/templates/custom_security/register_user.html b/tests/templates/custom_security/register_user.html index 2dbca0c..5da11ae 100644 --- a/tests/templates/custom_security/register_user.html +++ b/tests/templates/custom_security/register_user.html @@ -1,3 +1,3 @@ CUSTOM REGISTER USER - +{{ global }} {{ foo }} diff --git a/tests/templates/custom_security/reset_password.html b/tests/templates/custom_security/reset_password.html index d4c21fe..877f956 100644 --- a/tests/templates/custom_security/reset_password.html +++ b/tests/templates/custom_security/reset_password.html @@ -1,3 +1,3 @@ CUSTOM RESET PASSWORD - +{{ global }} {{ foo }} diff --git a/tests/templates/custom_security/send_confirmation.html b/tests/templates/custom_security/send_confirmation.html index d4df61d..3f5eae2 100644 --- a/tests/templates/custom_security/send_confirmation.html +++ b/tests/templates/custom_security/send_confirmation.html @@ -1,3 +1,3 @@ CUSTOM SEND CONFIRMATION - +{{ global }} {{ foo }} diff --git a/tests/templates/custom_security/send_login.html b/tests/templates/custom_security/send_login.html index 3685913..794dbc3 100644 --- a/tests/templates/custom_security/send_login.html +++ b/tests/templates/custom_security/send_login.html @@ -1,3 +1,3 @@ CUSTOM SEND LOGIN - +{{ global }} {{ foo }} diff --git a/tests/templates/security/email/reset_instructions.html b/tests/templates/security/email/reset_instructions.html index aa0937e..1fe4704 100644 --- a/tests/templates/security/email/reset_instructions.html +++ b/tests/templates/security/email/reset_instructions.html @@ -1,3 +1,3 @@ CUSTOM RESET INSTRUCTIONS - +{{ global }} {{ foo }} diff --git a/tests/test_context_processors.py b/tests/test_context_processors.py index dd8de0f..697eb1e 100644 --- a/tests/test_context_processors.py +++ b/tests/test_context_processors.py @@ -24,11 +24,16 @@ from utils import authenticate send_confirmation_template='custom_security/send_confirmation.html', register_user_template='custom_security/register_user.html') def test_context_processors(client, app): + @app.security.context_processor + def default_ctx_processor(): + return {'global': 'global'} + @app.security.forgot_password_context_processor def forgot_password(): return {'foo': 'bar'} response = client.get('/reset') + assert b'global' in response.data assert b'bar' in response.data @app.security.login_context_processor @@ -36,6 +41,7 @@ def test_context_processors(client, app): return {'foo': 'bar'} response = client.get('/login') + assert b'global' in response.data assert b'bar' in response.data @app.security.register_context_processor @@ -43,6 +49,7 @@ def test_context_processors(client, app): return {'foo': 'bar'} response = client.get('/register') + assert b'global' in response.data assert b'bar' in response.data @app.security.reset_password_context_processor @@ -50,6 +57,7 @@ def test_context_processors(client, app): return {'foo': 'bar'} response = client.get('/reset') + assert b'global' in response.data assert b'bar' in response.data @app.security.change_password_context_processor @@ -58,6 +66,7 @@ def test_context_processors(client, app): authenticate(client) response = client.get('/change') + assert b'global' in response.data assert b'bar' in response.data @app.security.send_confirmation_context_processor @@ -65,6 +74,7 @@ def test_context_processors(client, app): return {'foo': 'bar'} response = client.get('/confirm') + assert b'global' in response.data assert b'bar' in response.data @app.security.mail_context_processor @@ -75,6 +85,7 @@ def test_context_processors(client, app): client.post('/reset', data=dict(email='matt@lp.com')) email = outbox[0] + assert b'global' in email.html assert 'bar' in email.html