provide usable login/logout stuff
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@1215 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
4f4fccfe44
commit
3d9908f2d5
3 changed files with 126 additions and 0 deletions
51
browser/loops/auth.py
Normal file
51
browser/loops/auth.py
Normal file
|
@ -0,0 +1,51 @@
|
|||
#
|
||||
# Copyright (c) 2006 Helmut Merz helmutm@cy55.de
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
"""
|
||||
login, logout and similar stuff.
|
||||
|
||||
$Id$
|
||||
"""
|
||||
|
||||
import urllib
|
||||
from zope.app import zapi
|
||||
from zope.app.security.browser.auth import LoginLogout as BaseLoginLogout
|
||||
from zope.cachedescriptors.property import Lazy
|
||||
from zope.i18n import translate
|
||||
from zope.app.security.interfaces import IUnauthenticatedPrincipal
|
||||
from zope.app.security.interfaces import ILogoutSupported
|
||||
from zope.app.i18n import ZopeMessageFactory as _
|
||||
|
||||
|
||||
class LoginLogout(BaseLoginLogout):
|
||||
|
||||
def __call__(self):
|
||||
if IUnauthenticatedPrincipal.providedBy(self.request.principal):
|
||||
return u'<a href="@@login.html">%s</a>' % (
|
||||
#urllib.quote(self.request.getURL()),
|
||||
translate(_('[Login]'), context=self.request,
|
||||
default='[Login]'))
|
||||
elif ILogoutSupported(self.request, None) is not None:
|
||||
return u'<a href="@@logout.html?nextURL=%s/login.html">%s</a>' % (
|
||||
urllib.quote(zapi.absoluteURL(self.context, self.request)),
|
||||
translate(_('[Logout]'), context=self.request,
|
||||
default='[Logout]'))
|
||||
else:
|
||||
return None
|
||||
|
||||
|
|
@ -17,4 +17,22 @@
|
|||
<resource name="favicon.png" file="loops_favicon.png" layer="loops" />
|
||||
<resource name="zope3logo.gif" file="loops_logo.png" layer="loops" />
|
||||
|
||||
<!-- login/logout stuff -->
|
||||
|
||||
<zope:adapter factory="zope.app.security.LogoutSupported" />
|
||||
|
||||
<page
|
||||
name="login_logout" for="*"
|
||||
class=".auth.LoginLogout"
|
||||
permission="zope.Public"
|
||||
layer="loops"
|
||||
/>
|
||||
|
||||
<page
|
||||
name="loginForm.html" for="*"
|
||||
template="loginform.pt"
|
||||
permission="zope.Public"
|
||||
layer="loops"
|
||||
/>
|
||||
|
||||
</configure>
|
||||
|
|
57
browser/loops/loginform.pt
Normal file
57
browser/loops/loginform.pt
Normal file
|
@ -0,0 +1,57 @@
|
|||
<html metal:use-macro="context/@@standard_macros/page"
|
||||
i18n:domain="zope">
|
||||
<head>
|
||||
<title metal:fill-slot="title" i18n:translate="">
|
||||
Sign in
|
||||
</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<metal:slot fill-slot="logo"><img
|
||||
tal:attributes="src context/++resource++zope3logo.gif" />
|
||||
</metal:slot>
|
||||
|
||||
<metal:ignore fill-slot="navigators" />
|
||||
|
||||
<metal:empty fill-slot="breadcrumbs">
|
||||
<br />
|
||||
</metal:empty>
|
||||
|
||||
<div metal:fill-slot="body" tal:define="principal python:request.principal.id">
|
||||
<p i18n:translate="" tal:condition="python: principal == 'zope.anybody'">
|
||||
Please provide Login Information</p>
|
||||
<p i18n:translate="" tal:condition="python: principal != 'zope.anybody'">
|
||||
You are not authorized to perform this action. However, you may login as a
|
||||
different user who is authorized.</p>
|
||||
<form action="" method="post">
|
||||
<div tal:omit-tag=""
|
||||
tal:condition="python:principal != 'zope.anybody' and 'SUBMIT' in request">
|
||||
<span tal:define="dummy python:
|
||||
request.response.redirect(request.get('camefrom', ''))" />
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="label" i18n:translate="">User Name</div>
|
||||
<div class="field">
|
||||
<input type="text" name="login"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="label" i18n:translate="">Password</div>
|
||||
<div class="field">
|
||||
<input type="password" name="password"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<input class="form-element" type="submit"
|
||||
name="SUBMIT" value="Log in" i18n:attributes="value login-button" />
|
||||
</div>
|
||||
<input type="hidden" name="camefrom"
|
||||
tal:attributes="value request/camefrom | nothing">
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Add table
Reference in a new issue