This is (hopefully) the last email for this issue: Re: [Zope] How can I check a user_acl folder to see if a user already exists? First of all, thanks to everyone who responded. Second of all, here's the finished form and Python script for any other Newbies who need this in the future... Make sure that you have an acl_users folder in the same folder with the following items... ---------------------------------------------------------------------------------------------------- Here's the HTML form that the user submits: <form action="checkUsers"> Username: <input type="text" size="25" name="name"> Password: <input type="password" size="25" name="password"> Password (confirm): <input type="password" size="25" name="confirm"> <input type="hidden" name="roles" value="put_whatever_role_you_want_the_person_to_have_here"> <input type="hidden" name="domains" value=""> <input type="submit" value="Continue" name="submitButtonName"> </form> ---------------------------------------------------------------------------------------------------- Notice the above form is posting to "checkUsers" checkUsers is a python script located in the same folder as the form - you can name it anything you want Here's the code for checkUsers: #These two lines of code are generated automatically when you create a new script... just leave them there. request = container.REQUEST RESPONSE = request.RESPONSE #This line of code looks to see if there is already a user in the acl_users folder... if context.acl_users.getUser(request.form['name']): #If it finds someone with that name, you can send the user to a page with the following line... RESPONSE.redirect('/UserAlreadyExists.html') return #If it doesn't find anyone, it moves to the following line which checks to make sure the password and confirmation fields are identical... if request.form['password'] <> request.form['confirm']: #If the fields don't match, you can forward the user to another page and tell them... RESPONSE.redirect('/PasswordsDontMatch.html') return #If everything checks out, this next line finally adds the user... context.acl_users.manage_users('Add', context.REQUEST) #You can then use this last line to forward to yet another page with a confirmation... RESPONSE.redirect('/UserhasBeenAdded.html') ---------------------------------------------------------------------------------------------------- If any of you Python gurus want to add anything to this, please feel free... I'm eventually going to take a bunch of examples and create a tutorial for Newbies. Thanks, Rob On Tuesday, October 30, 2001, at 07:06 AM, M. Adam Kendall wrote:
First, you might want to take Danny Adairs advice (as posted to the list), as he is correct in that if you have quite a few users, his method will work much faster when checking if a user exists. Also, the parameters that should be in the REQUEST for manage_users are: name password confirm roles domains So you will have to either 1. Change your form to submit these same variable names, or, 2. do a context.REQUEST.set('name', context.REQUEST.form['Username']) etc, for each item you submit in the form and then pass REQUEST on to manage_users. After making sure the right variables are defined in the request, your first attempt: context.acl_users.manage_users('Add', context.REQUEST) should work for you.
On Tue, 2001-10-30 at 00:47, Rob Foster wrote:
Adam,
Thanks for the code... I tried it out and it works great... However, I realized that I was doing the check correctly. What I WASN'T doing right was the "add user here" part... here are the various lines of code that I tried under the "else:" with no luck... A little more help with possibly some explanation as to what's happening would be great...
Here are the various lines I've tried:
NUMBER ONE ATTEMPT: context.acl_users.manage_users('Add', context.REQUEST)
NUMBER TWO ATTEMPT: self.acl_users._addUser(username,password,confirmpass,liste_role,0)
NUMBER THREE ATTEMPT: userfolder.manage_users(submit='Add', REQUEST=user_info)
I got these bits of code from off various tutorials... Sometimes it really sucks being a newbie :)
Thanks again, Rob
---------------------------------------------------------------------------------------------
On Monday, October 29, 2001, at 10:14 PM, M. Adam Kendall wrote:
basically, you'll want to do something along the lines of:
request = context.REQUEST response = request.RESPONSE if request.form['Username'] in context.acl_users.getUserNames(): response.redirect('/UserAlreadyExists.html') else: # add user here
On Mon, 2001-10-29 at 12:11, Rob Foster wrote: Here's the setup:
I'm trying to add users to my site by having them fill out a form with the following fields:
Username Password Confirm (password confirmation)
I want the form to post to a python script that will check the folder and do a redirect to another document depending on what happens... I don't know Python that well. I've tried doing it in dtml with no results.
Can someone help me with a little example code or at least point me to a product that does this? Thanks in advance. -Rob