categories and homepage: add /auth and /tryauth paths (#6177)
This commit is contained in:
parent
4f790b48a0
commit
2d2e422e30
|
@ -84,6 +84,28 @@ def get_user_forms(formdef):
|
|||
|
||||
from wcs.forms.common import FormStatusPage
|
||||
|
||||
def tryauth(url):
|
||||
# tries to log the user in before redirecting to the asked url; this won't
|
||||
# do anything for local logins but will use a passive SAML request when
|
||||
# configured to use an external identity provider.
|
||||
if get_request().user:
|
||||
return redirect(url)
|
||||
ident_methods = get_cfg('identification', {}).get('methods', ['idp'])
|
||||
if not 'idp' in ident_methods:
|
||||
# when configured with local logins and not logged in, redirect to
|
||||
# asked url.
|
||||
return redirect(url)
|
||||
login_url = '/login/?ReturnUrl=%s&IsPassive=true' % urllib2.quote(url)
|
||||
return redirect(login_url)
|
||||
|
||||
def auth(url):
|
||||
# logs the user in before redirecting to asked url.
|
||||
if get_request().user:
|
||||
return redirect(url)
|
||||
login_url = '/login/?ReturnUrl=%s' % urllib2.quote(url)
|
||||
return redirect(login_url)
|
||||
|
||||
|
||||
class TokenDirectory(Directory):
|
||||
_q_exports = ['']
|
||||
|
||||
|
@ -886,27 +908,10 @@ class FormPage(Directory):
|
|||
return r.getvalue()
|
||||
|
||||
def tryauth(self):
|
||||
# this URL tries to log the user in before displaying the form; this
|
||||
# won't do anything for local logins but will use a passive SAML
|
||||
# request when configured to use an external identity provider.
|
||||
form_url = self.formdef.get_url()
|
||||
if self.user:
|
||||
return redirect(form_url)
|
||||
ident_methods = get_cfg('identification', {}).get('methods', ['idp'])
|
||||
if not 'idp' in ident_methods:
|
||||
# when configured with local logins and not logged in, display the
|
||||
# form.
|
||||
return redirect(form_url)
|
||||
login_url = '/login/?ReturnUrl=%s&IsPassive=true' % urllib2.quote(form_url)
|
||||
return redirect(login_url)
|
||||
return tryauth(self.formdef.get_url())
|
||||
|
||||
def auth(self):
|
||||
# this URL logs the user in before displaying the form.
|
||||
form_url = self.formdef.get_url()
|
||||
if self.user:
|
||||
return redirect(form_url)
|
||||
login_url = '/login/?ReturnUrl=%s' % urllib2.quote(form_url)
|
||||
return redirect(login_url)
|
||||
return auth(self.formdef.get_url())
|
||||
|
||||
def qrcode(self):
|
||||
img = qrcode.make(self.formdef.get_url())
|
||||
|
@ -950,7 +955,7 @@ class FormPage(Directory):
|
|||
|
||||
|
||||
class RootDirectory(AccessControlled, Directory):
|
||||
_q_exports = ['', 'json', 'categories', 'code']
|
||||
_q_exports = ['', 'json', 'categories', 'code', 'tryauth', 'auth']
|
||||
|
||||
category = None
|
||||
code = TrackingCodesDirectory()
|
||||
|
@ -959,6 +964,20 @@ class RootDirectory(AccessControlled, Directory):
|
|||
self.category = category
|
||||
get_publisher().substitutions.feed(category)
|
||||
|
||||
def tryauth(self):
|
||||
if self.category:
|
||||
base_url = self.category.get_url()
|
||||
else:
|
||||
base_url = get_publisher().get_root_url()
|
||||
return tryauth(base_url)
|
||||
|
||||
def auth(self):
|
||||
if self.category:
|
||||
base_url = self.category.get_url()
|
||||
else:
|
||||
base_url = get_publisher().get_root_url()
|
||||
return auth(base_url)
|
||||
|
||||
def _q_access(self):
|
||||
if self.category:
|
||||
response = get_response()
|
||||
|
|
|
@ -189,13 +189,20 @@ class RegisterDirectory(Directory):
|
|||
class RootDirectory(Directory):
|
||||
_q_exports = ['admin', 'backoffice', 'forms', 'login', 'logout', 'token', 'saml',
|
||||
'ident', 'register', 'afterjobs', 'themes', 'myspace', 'user', 'roles',
|
||||
'pages', ('tmp-upload', 'tmp_upload'), 'api', '__version__']
|
||||
'pages', ('tmp-upload', 'tmp_upload'), 'api', '__version__',
|
||||
'tryauth', 'auth']
|
||||
|
||||
api = ApiDirectory()
|
||||
themes = template.ThemesDirectory()
|
||||
myspace = MyspaceDirectory()
|
||||
pages = qommon.pages.PagesDirectory()
|
||||
|
||||
def tryauth(self):
|
||||
return forms.root.tryauth(get_publisher().get_root_url())
|
||||
|
||||
def auth(self):
|
||||
return forms.root.auth(get_publisher().get_root_url())
|
||||
|
||||
def __version__(self):
|
||||
if VersionMiddleware is None:
|
||||
raise errors.TraversalError()
|
||||
|
|
Loading…
Reference in New Issue