You are not logged in Log in Join
You are here: Home » Members » element » How to: add users in python

Log in
Name

Password

 

How to: add users in python

HOW-TO: Add zope users in Python (external methods)

For a long time I was baffled about how to get users data that I was storing in an external method into the zope "acl_users" folder. There were plenty of how-to's on adding users and user folders in DTML, but I was already storing all my data using python 'Products'.

I wanted to use zope's built-in user manager to handle authentication instead of building my own. I tried the Generic User Folder, but everytime, it locked me out of the folder I installed it in.

After a bit of researching and troubleshooting I found the task of coding this into my product to be very simple.

The first part of the code is found in the primary __init__ method of the primary class. When the product is installed into a folder, this method is called.

My Product is folderish, meaning that it contains other objects. I had to create the acl_users folder inside it.

self.manage_addUserFolder(curr_folder)

In the main __init__ method, python also creates a folder called users, which I am using to allow storage and restricted access to authenticated users. In this folder we can create the users folder automatically by enabling the create a userfolder variable. manage_addFolder's syntax looks like this: manage_addFolder('FolderID','FolderTitle','createAUserFolder','createAPublicInterface')

self.manage_addFolder('Users','Users',1,1)

I also wanted to create a local role for my users, and make them a member of that role.

self._addRole('MyUser')

The second part of the code is found in the primaryclass.addUser method. This code is called after a user fills out a createUserForm. This is where the actual user gets created.

self.Users.acl_users._addUser(username,password,confirmpass,['MyUser'],0)