mirror of
https://github.com/wassname/flask-security.git
synced 2026-08-18 12:00:35 +08:00
Add default/global context processor. Fixes #306
This commit is contained in:
@@ -350,6 +350,9 @@ class _SecurityState(object):
|
|||||||
rv.update(fn())
|
rv.update(fn())
|
||||||
return rv
|
return rv
|
||||||
|
|
||||||
|
def context_processor(self, fn):
|
||||||
|
self._add_ctx_processor(None, fn)
|
||||||
|
|
||||||
def forgot_password_context_processor(self, fn):
|
def forgot_password_context_processor(self, fn):
|
||||||
self._add_ctx_processor('forgot_password', fn)
|
self._add_ctx_processor('forgot_password', fn)
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
CUSTOM CHANGE PASSWORD
|
CUSTOM CHANGE PASSWORD
|
||||||
|
{{ global }}
|
||||||
{{ foo }}
|
{{ foo }}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
CUSTOM FORGOT PASSWORD
|
CUSTOM FORGOT PASSWORD
|
||||||
|
{{ global }}
|
||||||
{{ foo }}
|
{{ foo }}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
CUSTOM LOGIN USER
|
CUSTOM LOGIN USER
|
||||||
|
{{ global }}
|
||||||
{{ foo }}
|
{{ foo }}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
CUSTOM REGISTER USER
|
CUSTOM REGISTER USER
|
||||||
|
{{ global }}
|
||||||
{{ foo }}
|
{{ foo }}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
CUSTOM RESET PASSWORD
|
CUSTOM RESET PASSWORD
|
||||||
|
{{ global }}
|
||||||
{{ foo }}
|
{{ foo }}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
CUSTOM SEND CONFIRMATION
|
CUSTOM SEND CONFIRMATION
|
||||||
|
{{ global }}
|
||||||
{{ foo }}
|
{{ foo }}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
CUSTOM SEND LOGIN
|
CUSTOM SEND LOGIN
|
||||||
|
{{ global }}
|
||||||
{{ foo }}
|
{{ foo }}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
CUSTOM RESET INSTRUCTIONS
|
CUSTOM RESET INSTRUCTIONS
|
||||||
|
{{ global }}
|
||||||
{{ foo }}
|
{{ foo }}
|
||||||
|
|||||||
@@ -24,11 +24,16 @@ from utils import authenticate
|
|||||||
send_confirmation_template='custom_security/send_confirmation.html',
|
send_confirmation_template='custom_security/send_confirmation.html',
|
||||||
register_user_template='custom_security/register_user.html')
|
register_user_template='custom_security/register_user.html')
|
||||||
def test_context_processors(client, app):
|
def test_context_processors(client, app):
|
||||||
|
@app.security.context_processor
|
||||||
|
def default_ctx_processor():
|
||||||
|
return {'global': 'global'}
|
||||||
|
|
||||||
@app.security.forgot_password_context_processor
|
@app.security.forgot_password_context_processor
|
||||||
def forgot_password():
|
def forgot_password():
|
||||||
return {'foo': 'bar'}
|
return {'foo': 'bar'}
|
||||||
|
|
||||||
response = client.get('/reset')
|
response = client.get('/reset')
|
||||||
|
assert b'global' in response.data
|
||||||
assert b'bar' in response.data
|
assert b'bar' in response.data
|
||||||
|
|
||||||
@app.security.login_context_processor
|
@app.security.login_context_processor
|
||||||
@@ -36,6 +41,7 @@ def test_context_processors(client, app):
|
|||||||
return {'foo': 'bar'}
|
return {'foo': 'bar'}
|
||||||
|
|
||||||
response = client.get('/login')
|
response = client.get('/login')
|
||||||
|
assert b'global' in response.data
|
||||||
assert b'bar' in response.data
|
assert b'bar' in response.data
|
||||||
|
|
||||||
@app.security.register_context_processor
|
@app.security.register_context_processor
|
||||||
@@ -43,6 +49,7 @@ def test_context_processors(client, app):
|
|||||||
return {'foo': 'bar'}
|
return {'foo': 'bar'}
|
||||||
|
|
||||||
response = client.get('/register')
|
response = client.get('/register')
|
||||||
|
assert b'global' in response.data
|
||||||
assert b'bar' in response.data
|
assert b'bar' in response.data
|
||||||
|
|
||||||
@app.security.reset_password_context_processor
|
@app.security.reset_password_context_processor
|
||||||
@@ -50,6 +57,7 @@ def test_context_processors(client, app):
|
|||||||
return {'foo': 'bar'}
|
return {'foo': 'bar'}
|
||||||
|
|
||||||
response = client.get('/reset')
|
response = client.get('/reset')
|
||||||
|
assert b'global' in response.data
|
||||||
assert b'bar' in response.data
|
assert b'bar' in response.data
|
||||||
|
|
||||||
@app.security.change_password_context_processor
|
@app.security.change_password_context_processor
|
||||||
@@ -58,6 +66,7 @@ def test_context_processors(client, app):
|
|||||||
|
|
||||||
authenticate(client)
|
authenticate(client)
|
||||||
response = client.get('/change')
|
response = client.get('/change')
|
||||||
|
assert b'global' in response.data
|
||||||
assert b'bar' in response.data
|
assert b'bar' in response.data
|
||||||
|
|
||||||
@app.security.send_confirmation_context_processor
|
@app.security.send_confirmation_context_processor
|
||||||
@@ -65,6 +74,7 @@ def test_context_processors(client, app):
|
|||||||
return {'foo': 'bar'}
|
return {'foo': 'bar'}
|
||||||
|
|
||||||
response = client.get('/confirm')
|
response = client.get('/confirm')
|
||||||
|
assert b'global' in response.data
|
||||||
assert b'bar' in response.data
|
assert b'bar' in response.data
|
||||||
|
|
||||||
@app.security.mail_context_processor
|
@app.security.mail_context_processor
|
||||||
@@ -75,6 +85,7 @@ def test_context_processors(client, app):
|
|||||||
client.post('/reset', data=dict(email='matt@lp.com'))
|
client.post('/reset', data=dict(email='matt@lp.com'))
|
||||||
|
|
||||||
email = outbox[0]
|
email = outbox[0]
|
||||||
|
assert b'global' in email.html
|
||||||
assert 'bar' in email.html
|
assert 'bar' in email.html
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user