[Zope3-checkins] CVS: Zope3/src/zope/app/browser - auth.py:1.1 auth.zcml:1.1 login.pt:1.1 logout.pt:1.1 configure.zcml:1.19
Stephan Richter
srichter@cosmos.phy.tufts.edu
Thu, 31 Jul 2003 23:22:06 -0400
Update of /cvs-repository/Zope3/src/zope/app/browser
In directory cvs.zope.org:/tmp/cvs-serv1850/browser
Modified Files:
configure.zcml
Added Files:
auth.py auth.zcml login.pt logout.pt
Log Message:
After I finally got sick of not having a Login/Logout button, I implemented
it. The code is simple and straight forward. If someone has a different
authentication method (cookies or via URL), then s/he just needs to register
their own ling.html and logout.html following pretty much what I have done
for HTTP Authentication.
Only one thing is left: How in the world do you want to write tests for
this functionality?!? As sson as I hear a good suggestion I will add a test
or two for this code.
=== Added File Zope3/src/zope/app/browser/auth.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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: auth.py,v 1.1 2003/08/01 03:21:28 srichter Exp $
"""
from zope.interface import implements
from zope.app.interfaces.publisher.http import ILogin, ILogout
from zope.app.security.registries.principalregistry import \
UnauthenticatedPrincipal
from zope.app.pagetemplate import ViewPageTemplateFile
class HTTPAuthenticationLogin(object):
implements(ILogin)
def login(self, nextURL=None):
"""See zope.app.interfaces.security.ILogin"""
if isinstance(self.request.user, UnauthenticatedPrincipal):
self.request.unauthorized("basic realm='Zope'")
else:
if nextURL is None:
return self.confirmation()
else:
self.request.response.redirect(nextURL)
confirmation = ViewPageTemplateFile('login.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.interfaces.security.ILogout"""
if not isinstance(self.request.user, UnauthenticatedPrincipal):
self.request.unauthorized("basic realm='Zope'")
else:
if nextURL is None:
return self.confirmation()
else:
self.request.response.redirect(nextURL)
confirmation = ViewPageTemplateFile('logout.pt')
=== Added File Zope3/src/zope/app/browser/auth.zcml ===
<zopeConfigure
xmlns:browser="http://namespaces.zope.org/browser">
<browser:page
name="login.html"
for="*"
class=".auth.HTTPAuthenticationLogin"
attribute="login"
permission="zope.Public"
allowed_interface="zope.app.interfaces.publisher.http.ILogin"
/>
<browser:page
name="logout.html"
for="*"
class=".auth.HTTPAuthenticationLogout"
attribute="logout"
permission="zope.Public"
allowed_interface="zope.app.interfaces.publisher.http.ILogout"
/>
</zopeConfigure>
=== Added File Zope3/src/zope/app/browser/login.pt ===
<html metal:use-macro="context/@@standard_macros/dialog">
<body>
<div metal:fill-slot="body">
<h1>Login successful!</h1>
<p style="font-size: 200%">
You are now logged in as <em tal:content="view/request/user/getTitle"/>.
</p>
<a href=".">Back to the main page.</a>
</div>
</body>
</html>
=== Added File Zope3/src/zope/app/browser/logout.pt ===
<html metal:use-macro="context/@@standard_macros/dialog">
<body>
<div metal:fill-slot="body">
<h1>Logout successful!</h1>
<p style="font-size: 200%">
You are now logged out.
</p>
<a href=".">Back to the main page.</a>
</div>
</body>
</html>
=== Zope3/src/zope/app/browser/configure.zcml 1.18 => 1.19 ===
--- Zope3/src/zope/app/browser/configure.zcml:1.18 Sat Jul 12 23:35:42 2003
+++ Zope3/src/zope/app/browser/configure.zcml Thu Jul 31 23:21:28 2003
@@ -21,6 +21,7 @@
<include file="introspector.zcml" />
<include file="traversal.zcml" />
<include file="undo.zcml" />
+<include file="auth.zcml" />
<include package=".exception" />