Skip to content

Commit

Permalink
authentication views
Browse files Browse the repository at this point in the history
  • Loading branch information
ilshad committed May 4, 2010
1 parent 65bcd6d commit 4b7d553
Show file tree
Hide file tree
Showing 14 changed files with 229 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/bbru/answers/browser/javascript/answers.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function load_text_form (context_url, params) {
var url = context_url + "@@text";

$('#form-place').load(url, params, function(text, status, response) {

console.log(response.status);
if (response.status == 202) {
$('#question-body').html(text);
$('#form-place').empty();
Expand Down
1 change: 1 addition & 0 deletions src/bbru/authentication/browser/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# python package
35 changes: 35 additions & 0 deletions src/bbru/authentication/browser/configure.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<configure
xmlns="http://namespaces.zope.org/z3c"
i18n_domain="ice.control">

<pagelet
name="loginForm.html"
for="*"
class=".loginform.Pagelet"
permission="zope.Public"
layer="bbru.skin.interfaces.ILayer"
/>
<template
for=".loginform.Pagelet"
template="loginform.pt"
/>

<pagelet
name="login.html"
for="*"
class=".login.Pagelet"
permission="zope.Public"
allowed_interface="zope.app.publisher.interfaces.http.ILogin"
layer="bbru.skin.interfaces.ILayer"
/>

<pagelet
name="logout.html"
for="*"
class=".logout.Pagelet"
permission="zope.Public"
allowed_interface="zope.app.publisher.interfaces.http.ILogout"
layer="bbru.skin.interfaces.ILayer"
/>

</configure>
8 changes: 8 additions & 0 deletions src/bbru/authentication/browser/login.pt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<h1>Login successful!</h1>

<p style="font-size: 120%; font-weight:bold;">
You are now logged in as
<em tal:content="view/request/principal/title" />
</p>

<a href=".">Back to the main page.</a>
44 changes: 44 additions & 0 deletions src/bbru/authentication/browser/login.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
### -*- coding: utf-8 -*- ####################################################
#
# Copyright (C) 2010 Ilshad R. Khabibullin <astoon.net at gmail.com>
#
# This library 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 3 of the License.
#
# This software 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 software. If not, see <http://www.gnu.org/licenses/>.
#
# Project homepage: <http://launchpad.net/ice.control>
#
# This pagelet is modified browser view based on code of zope.*,
# Copyright (C) Zope Corporation and Contributors.
#
##############################################################################

from zope import interface, component
from zope.app.publisher.interfaces.http import ILogin
from zope.authentication.interfaces import IUnauthenticatedPrincipal
from zope.authentication.interfaces import IAuthentication
from zope.app.pagetemplate import ViewPageTemplateFile

class Pagelet(object):
interface.implements(ILogin)

confirmation = ViewPageTemplateFile('login.pt')
failed = ViewPageTemplateFile('login_failed.pt')

def render(self):
nextURL = self.request.get('nextURL')
if IUnauthenticatedPrincipal(self.request.principal, False):
component.getUtility(IAuthentication).unauthorized(
self.request.principal.id, self.request)
return self.failed()
if nextURL is None:
return self.confirmation()
self.request.response.redirect(nextURL)
8 changes: 8 additions & 0 deletions src/bbru/authentication/browser/login_failed.pt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<h1>Login Failed!</h1>

<p style="font-size: 150%">
You cancelled the login procedure.
<a tal:attributes="href python: view.request.get('nextURL', '.')">
Click here to return.
</a>
</p>
34 changes: 34 additions & 0 deletions src/bbru/authentication/browser/loginform.pt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<tal:block define="principal python:request.principal.id">
<h1 i18n:translate="" tal:condition="python: principal == 'zope.anybody'">
Please provide Login Information
</h1>
<h1 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.
</h1>
<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"><label for="login" i18n:translate="">Login</label></div>
<div class="field">
<input type="text" name="login" id="login" />
</div>
</div>

<div class="row">
<div class="label"><label for="password" i18n:translate="">Password</label></div>
<div class="field">
<input type="password" name="password" id="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>
</tal:block>
21 changes: 21 additions & 0 deletions src/bbru/authentication/browser/loginform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
### -*- coding: utf-8 -*- ####################################################
#
# Copyright (C) 2010 Ilshad R. Khabibullin <astoon.net at gmail.com>
#
# This library 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 3 of the License.
#
# This software 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 software. If not, see <http://www.gnu.org/licenses/>.
#
# Project homepage: <http://launchpad.net/ice.control>
#
##############################################################################

class Pagelet: pass
5 changes: 5 additions & 0 deletions src/bbru/authentication/browser/logout.pt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>Logout successful!</h1>

<p style="font-size: 200%">You are now logged out.</p>

<a href=".">Back to the main page.</a>
45 changes: 45 additions & 0 deletions src/bbru/authentication/browser/logout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
### -*- coding: utf-8 -*- ####################################################
#
# Copyright (C) 2010 Ilshad R. Khabibullin <astoon.net at gmail.com>
#
# This library 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 3 of the License.
#
# This software 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 software. If not, see <http://www.gnu.org/licenses/>.
#
# Project homepage: <http://launchpad.net/ice.control>
#
# This pagelet is modified browser view based on code of zope.*,
# Copyright (C) Zope Corporation and Contributors.
#
##############################################################################

from zc.resourcelibrary import need
from zope import interface, component
from zope.authentication.interfaces import IUnauthenticatedPrincipal
from zope.authentication.interfaces import IAuthentication, ILogout
from zope.app.pagetemplate import ViewPageTemplateFile

class Pagelet(object):
interface.implements(ILogout)

confirmation = ViewPageTemplateFile('logout.pt')
redirect = ViewPageTemplateFile('redirect.pt')

def render(self):
nextURL = self.request.get('nextURL')
if not IUnauthenticatedPrincipal(self.request.principal, False):
auth = component.getUtility(IAuthentication)
ILogout(auth).logout(self.request)
if nextURL:
return self.redirect()
if nextURL is None:
return self.confirmation()
return self.request.response.redirect(nextURL)
22 changes: 22 additions & 0 deletions src/bbru/authentication/browser/redirect.pt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<script type="text/javascript">
try {
if (window.XMLHttpRequest) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "@@", true, "logout", "logout");
xmlhttp.send("");
xmlhttp.abort();
} else if (document.execCommand) {
document.execCommand("ClearAuthenticationCache");
}
} catch(e) { }
</script>

<h1>You are being redirected!</h1>

<p style="font-size: 150%">
<a tal:attributes="href view/request/nextURL">
If you see this screen for more than 5 seconds, click here.
</a>
</p>

<tal:block content="python:request.response.redirect(request.get('nextURL'))" />
2 changes: 2 additions & 0 deletions src/bbru/authentication/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@
name="Create User"
/>

<include package=".browser" />

</configure>
2 changes: 2 additions & 0 deletions src/bbru/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<include package="ice.control" />
<include package="ice.control.repl" />

<include package="z3c.layer.pagelet" />

<include package="zope.sendmail" file="meta.zcml" />
<include package="zope.sendmail" />

Expand Down
3 changes: 1 addition & 2 deletions src/bbru/securitypolicy.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
i18n_domain="zope">

<!-- This file contains sample security policy definition -->

<include package="zope.securitypolicy" />

<securityPolicy
component="zope.securitypolicy.zopepolicy.ZopeSecurityPolicy"
/>
Expand Down

0 comments on commit 4b7d553

Please sign in to comment.