Zope
  Home arrow Zope arrow Page 2 - Flat User Management in Zope
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
ZOPE

Flat User Management in Zope
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 9
    2005-02-07


    Table of Contents:
  • Flat User Management in Zope
  • Registration
  • Login
  • Verification

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Flat User Management in Zope - Registration
    ( Page 2 of 4 )

    We'll first create the Zope Page Template containing the login form. The page will also need to check whether the user has already submitted data. This will be done using a Script ( Python ) object –- the same object which will be responsible for creating the accounts of users.

    Create a file named register_html and insert the following code into it:

    <html>
       <head>
          <title>Register</title>
       </head>
       <body tal:define='regStatus container/register'>
          <span tal:condition='regStatus'>
             <span tal:replace='regStatus'></span>
          </span>
          <span tal:condition='not:regStatus'>
             <form method='POST'>
                <label>Desired Username:</label><br />
                <input type='text' name='username'><br />
                <label>Password:</label><br />
                <input type='text' name='password'><br />
                <label>E-Mail:</label></br />
                <input type='text' name='email'><br />
                <input type='submit' value='Register'>
             </form>
          </span>
       </body>
    </html>

    The file first defines a variable named "regStatus" with a value based upon the result of a file named register. If the file returns a non-zero value, the value is displayed. If it doesn't, the registration form is displayed.

    Before we create the register file, we need to create an external method. Since Zope forbids Script ( Python ) objects from using the "md5" module to hash data such as user passwords, we need to create a separate script to do this for us. External methods can contain any code. Fortunately, external methods are a breeze to create and use. In your Zope instance's folder ( not the document root ), there should be a folder called Extensions. In this folder, create a file named hash.py with this as its contents:

    import md5

    def hash ( text ):
       password = md5.new()
       password.update ( text )
       password = password.hexdigest()
       return password

    This will use the "md5" module to hash data given to it.

    Next, create an External Method object in the same directory as our registration page.

    We're now ready to move on. First, create a Folder object called users. This will store user data. Next, create a Script ( Python ) object named register. Add the following data to it:

    if context.REQUEST.has_key ( 'username' ) and context.REQUEST.has_key ( 'password' ) and context.REQUEST.has_key ( 'email' ):
       if hasattr ( container.users, context.REQUEST.username ):
          return 'Sorry, someone else has registered with your username.'
       password = container.hash ( context.REQUEST.password )
       container.users.manage_addProduct [ 'OFSP' ].manage_addFile ( context.REQUEST.username )
       userObject = getattr ( container.users,context.REQUEST.username )
       userObject.manage_addProperty ( 'password', password, 'string' )
       userObject.manage_addProperty ( 'email', context.REQUEST.email, 'string' )
       return 'Your account has been created.'
    return False

    The script first checks to see if the user has filled in the required values. If the user hasn't, the script returns "False" and ends execution. It then checks to see if the username has been taken. If it has, it returns a message saying so and ends execution. Finally, if everything has gone right, it sends the hash object the user's password. The hash object hashes the user's password and returns it. The script then adds a File object with the user's username as its filename. A property called password is added to the File object containing the user's password. An property for the user's email is also added. The script then returns a success message.

    The registration system is now complete. If you have followed the article correctly, you can now test it out.



     
     
    >>> More Zope Articles          >>> More By Peyton McCullough
     

       

    ZOPE ARTICLES

    - Creating Zope Products
    - Plone Content Types With Archetypes
    - Flat User Management in Zope
    - Creating Basic Zope Applications
    - Getting started with Zope for Linux and Sola...
    - ZPT Basics (part 4)
    - ZPT Basics (part 3)
    - ZPT Basics (part 2)
    - ZPT Basics (part 1)
    - Exception Handling In DTML
    - DTML Basics (part 4)
    - DTML Basics (part 3)
    - DTML Basics (part 2)
    - DTML Basics (part 1)
    - Using Zope With Apache





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek