[Zope-CMF] RE: Help- cmf version problem

David (Hamish) Harvey david.harvey@bristol.ac.uk
Sat, 08 Jun 2002 11:34:34 +0100


--On Friday, June 07, 2002 15:37:20 +0000 Florent Guillaume <fg@nuxeo.com> 
wrote:

> David (Hamish) Harvey <david.harvey@bristol.ac.uk> wrote:
>> which allows . and - as characters in the username. I haven't worked out
>> how to override this without modiying the source code in CMFCore yet,
>> though.
>
> In one of your products, in __init__.py, just do:
>
> import re
> from Products.CMFCore.RegistrationTool import RegistrationTool
> RegistrationTool.__ALLOWED_MEMBER_ID_PATTERN = \
>     re.compile(r"^[A-Za-z][A-Za-z0-9_\.\-]*$")

Still struggling with this. I've added it, as you say, to one of my 
__init__.py scripts - I tried this before and it didn't seem to work. I've 
even added

if not RegistrationTool.__ALLOWED_MEMBER_ID_PATTERN.match('a.b-_'):
    raise "oops"

To make sure it works, and that doesn't throw an exception - the product 
loads fine. However, 'a.b-_' is still rejected as a user id (as is 'a.b' 
for example). If I change the "isMemberIdAllowed" function in 
RegistrationTool to insert the following raise:

        if not self.__ALLOWED_MEMBER_ID_PATTERN.match( id ):
            raise "doh!"
            return 0

then when I try to join with a username as above, it throws the exception 
(I did this to make sure it wasn't being rejected elsewhere).

I've even tried creating a new CMF site (both plain and plone) to check 
that this wasn't a problem with the portal_registration instance not being 
updated along with the class, but this has no effect (I need to read up on 
th python object model here, I think).

And I've tried both restarting and stopping and starting zope between 
changes.

At the same time as the above fails, this gives the "ok" exception:

-----
from Products.CMFDefault.RegistrationTool import RegistrationTool

def test():
    if not RegistrationTool.__ALLOWED_MEMBER_ID_PATTERN.match('a.b-_'):
        raise "oops"
    raise "ok"
-----

while changing the "id" to include a space, or start with a digit, gives 
"oops".

I've run out of things to test and ideas for what might be going on. I 
*surely* must be missing something really simple. Either that or there's 
some odd caching going on somewhere?

> (Beware, you got the regexp syntax wrong regarding backslashes, you
> should use raw strings like I did.)

Thanks for pointing that out - still learning python :-)

Cheers,
Hamish