forms: add /forceauth path to forms (#29059)

This commit is contained in:
Benjamin Dauvergne 2018-12-14 12:17:07 +01:00
parent 135788d5e2
commit b896d1af68
2 changed files with 16 additions and 1 deletions

View File

@ -1242,6 +1242,13 @@ def test_form_tryauth(pub):
pub.cfg['identification'] = {'methods': ['password']}
pub.write_cfg()
def test_form_forceauth(pub):
create_user(pub)
formdef = create_formdef()
formdef.data_class().wipe()
resp = get_app(pub).get('/test/forceauth')
assert resp.location == 'http://example.net/login/?ReturnUrl=http%3A//example.net/test/&forceAuthn=true'
def test_form_no_tracking_code(pub):
formdef = create_formdef()
formdef.data_class().wipe()

View File

@ -100,6 +100,11 @@ def auth(url):
return redirect(login_url)
def forceauth(url):
login_url = '/login/?ReturnUrl=%s&forceAuthn=true' % urllib2.quote(url)
return redirect(login_url)
class TrackingCodeDirectory(Directory):
_q_exports = ['', 'load']
@ -173,7 +178,7 @@ class TrackingCodesDirectory(Directory):
class FormPage(Directory, FormTemplateMixin):
_q_exports = ['', 'tempfile', 'schema', 'tryauth',
'auth', 'qrcode', 'autosave', 'code', 'removedraft', 'live']
'auth', 'forceauth', 'qrcode', 'autosave', 'code', 'removedraft', 'live']
do_not_call_in_templates = True
filling_templates = ['wcs/front/formdata_filling.html', 'wcs/formdata_filling.html']
@ -1229,6 +1234,9 @@ class FormPage(Directory, FormTemplateMixin):
def auth(self):
return auth(self.formdef.get_url())
def forceauth(self):
return forceauth(self.formdef.get_url())
def qrcode(self):
img = qrcode.make(self.formdef.get_url())
s = StringIO()