Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Commit

Permalink
Made BaseRequest an IParticipation and replaced request.user with
Browse files Browse the repository at this point in the history
request.principal everywhere.
  • Loading branch information
mgedmin committed May 12, 2004
0 parents commit 14778b0
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
70 changes: 70 additions & 0 deletions browser/auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
##############################################################################
#
# 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 2004/03/14 04:45:00 srichter Exp $
"""
from zope.interface import implements
from zope.app.publisher.interfaces.http import ILogin, ILogout
from zope.app.security.principalregistry import UnauthenticatedPrincipal
from zope.app.pagetemplate import ViewPageTemplateFile
from zope.proxy import removeAllProxies

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')


18 changes: 18 additions & 0 deletions browser/login.pt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<html metal:use-macro="context/@@standard_macros/page">
<body>
<div metal:fill-slot="body">

<h1 i18n:translate="">Login successful!</h1>

<p style="font-size: 200%" i18n:translate="">
You are now logged in as
<em tal:content="view/request/principal/title"
i18n:name="UserTitle">Joe Smith</em>.
</p>

<a href="." i18n:translate="">Back to the main page.</a>

</div>
</body>

</html>

0 comments on commit 14778b0

Please sign in to comment.