From a808a649d053bc44608b0dc6b9033f03840efc53 Mon Sep 17 00:00:00 2001 From: Roger Ineichen Date: Tue, 4 Jan 2005 00:31:13 +0000 Subject: [PATCH] Simpliest part first, beautifiy grant.html view --- browser/auth.py | 111 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 browser/auth.py diff --git a/browser/auth.py b/browser/auth.py new file mode 100644 index 0000000..42e96b2 --- /dev/null +++ b/browser/auth.py @@ -0,0 +1,111 @@ +############################################################################## +# +# Copyright (c) 2003 Zope Corporation and Contributors. +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# +############################################################################## +"""Login and Logout screens + +$Id$ +""" +from zope.interface import implements +from zope.i18n import translate +from zope.app.publisher.interfaces.http import ILogin, ILogout +from zope.app.security.interfaces import IAuthenticationUtility +from zope.app.security.principalregistry import UnauthenticatedPrincipal +from zope.app.pagetemplate import ViewPageTemplateFile +from zope.proxy import removeAllProxies +from zope.app.i18n import ZopeMessageIDFactory as _ + + +search_label = _('search-button', 'Search') + +class AuthUtilitySearchView(object): + __used_for__ = IAuthenticationUtility + + def __init__(self, context, request): + self.context = context + self.request = request + + def render(self, name): + print "" + print "AuthUtilitySearchView render" + html = [] + html.append('
') + html.append('
') + html.append('Search String') + html.append('
') + html.append('
') + html.append('' %(name+'.searchstring')) + + html.append('' + % (name+'.search', + translate(search_label, context=self.request))) + + html.append('
') + html.append('
') + + return '\n'.join(html) + + def results(self, name): + if not (name+'.search' in self.request): + return None + searchstring = self.request[name+'.searchstring'] + return [principal.id + for principal in self.context.getPrincipals(searchstring)] + + +class HTTPAuthenticationLogin(object): + implements(ILogin) + + def login(self, nextURL=None): + """See zope.app.security.interfaces.ILogin""" + if isinstance(removeAllProxies(self.request.principal), \ + UnauthenticatedPrincipal): + self.request.unauthorized("basic realm='Zope'") + return self.failed() + else: + if nextURL is None: + return self.confirmation() + else: + self.request.response.redirect(nextURL) + + confirmation = ViewPageTemplateFile('login.pt') + + failed = ViewPageTemplateFile('login_failed.pt') + + +class HTTPAuthenticationLogout(object): + """Since HTTP Authentication really does not know about logout, we are + simply challenging the client again.""" + + implements(ILogout) + + def __init__(self, context, request): + self.context = context + self.request = request + + def logout(self, nextURL=None): + """See zope.app.security.interfaces.ILogout""" + if not isinstance(self.request.principal, UnauthenticatedPrincipal): + self.request.unauthorized("basic realm='Zope'") + if nextURL: + return self.redirect() + + if nextURL is None: + return self.confirmation() + else: + return self.request.response.redirect(nextURL) + + confirmation = ViewPageTemplateFile('logout.pt') + + redirect = ViewPageTemplateFile('redirect.pt') + +