Skip to content

Commit 35c3488

Browse files
author
Johannes Gijsbers
committed
Update customization examples too, expand upgrade notice a bit.
1 parent 56353a1 commit 35c3488

File tree

2 files changed

+44
-32
lines changed

2 files changed

+44
-32
lines changed

doc/customizing.txt

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Customising Roundup
33
===================
44

5-
:Version: $Revision: 1.114 $
5+
:Version: $Revision: 1.115 $
66

77
.. This document borrows from the ZopeBook section on ZPT. The original is at:
88
http://www.zope.org/Documentation/Books/ZopeBook/current/ZPT.stx
@@ -892,15 +892,15 @@ of:
892892
- Also handle the ":queryname" variable and save off the query to the
893893
user's query list.
894894

895-
Each of the actions is implemented by a corresponding ``*actionAction*``
896-
(where "action" is the name of the action) method on the
897-
``roundup.cgi.Client`` class, which also happens to be available in your
898-
tracker instance as ``interfaces.Client``. So if you need to define new
899-
actions, you may add them there (see `defining new web actions`_).
895+
Each of the actions is implemented by a corresponding ``*XxxAction*`` (where
896+
"Xxx" is the name of the action) class in the ``roundup.cgi.actions`` module.
897+
These classes are registered with ``roundup.cgi.client.Client`` which also
898+
happens to be available in your tracker instance as ``interfaces.Client``. So
899+
if you need to define new actions, you may add them there (see `defining new
900+
web actions`_).
900901

901-
Each action also has a corresponding ``*actionPermission*`` (where
902-
"action" is the name of the action) method which determines whether the
903-
action is permissible given the current user. The base permission checks
902+
Each action class also has a ``*permission*`` method which determines whether
903+
the action is permissible given the current user. The base permission checks
904904
are:
905905

906906
**login**
@@ -2101,7 +2101,7 @@ The action classes have the following interface::
21012101
'''
21022102

21032103
The *self.client* attribute is an instance of your tracker ``instance.Client``
2104-
class - thus it's mostly implemented by ``roundup.cgi.Client``. See the
2104+
class - thus it's mostly implemented by ``roundup.cgi.client.Client``. See the
21052105
docstring of that class for details of what it can do.
21062106

21072107
The method will typically check the ``self.form`` variable's contents.
@@ -2826,27 +2826,36 @@ would be::
28262826

28272827
admin:aamrgyQfDFSHw
28282828

2829-
Each user of Roundup must still have their information stored in the
2830-
Roundup database - we just use the passwd file to check their password.
2831-
To do this, we add the following code to our ``Client`` class in the
2832-
tracker home ``interfaces.py`` module::
2829+
Each user of Roundup must still have their information stored in the Roundup
2830+
database - we just use the passwd file to check their password. To do this, we
2831+
need to override the standard ``verifyPassword`` method defined in
2832+
``roundup.cgi.actions.LoginAction`` and register the new class with our
2833+
``Client`` class in the tracker home ``interfaces.py`` module::
28332834

2834-
def verifyPassword(self, userid, password):
2835-
# get the user's username
2836-
username = self.db.user.get(userid, 'username')
2835+
from roundup.cgi.actions import LoginAction
28372836

2838-
# the passwords are stored in the "passwd.txt" file in the
2839-
# tracker home
2840-
file = os.path.join(self.db.config.TRACKER_HOME, 'passwd.txt')
2837+
class ExternalPasswordLoginAction(LoginAction):
2838+
def verifyPassword(self, userid, password):
2839+
# get the user's username
2840+
username = self.db.user.get(userid, 'username')
28412841

2842-
# see if we can find a match
2843-
for ent in [line.strip().split(':') for line in
2844-
open(file).readlines()]:
2845-
if ent[0] == username:
2846-
return crypt.crypt(password, ent[1][:2]) == ent[1]
2842+
# the passwords are stored in the "passwd.txt" file in the
2843+
# tracker home
2844+
file = os.path.join(self.db.config.TRACKER_HOME, 'passwd.txt')
28472845

2848-
# user doesn't exist in the file
2849-
return 0
2846+
# see if we can find a match
2847+
for ent in [line.strip().split(':') for line in
2848+
open(file).readlines()]:
2849+
if ent[0] == username:
2850+
return crypt.crypt(password, ent[1][:2]) == ent[1]
2851+
2852+
# user doesn't exist in the file
2853+
return 0
2854+
2855+
class Client(client.Client):
2856+
actions = client.Client.actions + (
2857+
('login', ExternalPasswordLoginAction)
2858+
)
28502859

28512860
What this does is look through the file, line by line, looking for a
28522861
name that matches.
@@ -3201,9 +3210,10 @@ for more information about doing this.
32013210

32023211
To authenticate off the LDAP store (rather than using the passwords in the
32033212
roundup user database) you'd use the same python-ldap module inside an
3204-
extension to the cgi interface. You'd do this by adding a method called
3205-
"verifyPassword" to the Client class in your tracker's interfaces.py
3206-
module. The method is implemented by default as::
3213+
extension to the cgi interface. You'd do this by overriding the method called
3214+
"verifyPassword" on the LoginAction class in your tracker's interfaces.py
3215+
module (see `using an external password validation source`_). The method is
3216+
implemented by default as::
32073217

32083218
def verifyPassword(self, userid, password):
32093219
''' Verify the password that the user has supplied

doc/upgrading.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ Before 0.7.0 adding or extending web actions was done by overriding or adding
1818
methods on the Client class. Though this approach still works to provide
1919
backwards compatibility, it is recommended you upgrade to the new approach, as
2020
described in the `Defining new web actions`__ section of the customization
21-
documentation.
21+
documentation. You might also want to take a look at the `Using an external
22+
password validation source`__ example.
2223

23-
__ customizing.html#defining-new-web-actions
24+
__ customizing.html#defining-new-web-actions
25+
__ customizing.html#using-an-external-password-validation-source
2426

2527
0.7.0 Getting the current user id
2628
---------------------------------

0 commit comments

Comments
 (0)