def process_form(self, form, protocol): try: controls = self.request.POST.items() appstruct = form.validate(controls) except ValidationFailure, e: logger.exception("validation of form failed.") return dict(active=protocol, auth_protocols=auth_protocols(self.request), form=e.render())
def button(request): """If the user is logged in, returns the logout button, otherwise returns the login button""" import markupsafe from pyramid.security import authenticated_userid from phoenix.models import auth_protocols if not authenticated_userid(request): protocols = auth_protocols(request) if len(protocols) > 0: protocol = protocols[-1] else: protocol = 'oauth2' return markupsafe.Markup(SIGNIN_HTML) % (request.route_path('account_login', protocol=protocol)) else: return markupsafe.Markup(SIGNOUT_HTML) % (request.route_path('account_logout'), authenticated_userid(request))
def login(self): protocol = self.request.matchdict.get("protocol", "phoenix") if protocol == "ldap": # Ensure that the ldap connector is created self.ldap_prepare() form = self.generate_form(protocol) if "submit" in self.request.POST: return self.process_form(form, protocol) # TODO: Add ldap to title? return dict( active=protocol, title="Login", auth_protocols=auth_protocols(self.request), form=form.render(self.appstruct(protocol)), )