Zope
  Home arrow Zope arrow Page 4 - 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 - Verification
    ( Page 4 of 4 )

    Our final step in creating our user database is to create a system that will challenge the user's username and password when he or she tries to access a restricted page, permitting him or her to view the page only if their username and password match the stored data. This is easily done by checking the user's cookies. Create a Script ( Python ) object named verify with the following code:

    if context.REQUEST.has_key ( 'username' ) and context.REQUEST.has_key ( 'password' ):
       if not hasattr ( container.users, context.REQUEST.username ):
          return False
       userObject = getattr ( container.users,context.REQUEST.username )
       if context.REQUEST.password != userObject.password:
          return False
       userData = { 'email' : userObject.email }
       return userData
    return False

    First, the script checks to see if the two cookies containing the user's username and password are set. If they are, the script moves on to check if the supplied uesrname exists. If it does, the script checks the passwords against each other. If they match, a dictionary is returned containing the user's email address.

    We'll now create a page to test out our system. Create a Zope Page Template object named private_html:

    <html>
       <head>
          <title>Private Area</title>
       </head>
       <body tal:define='verifyStatus container/verify'>
          <span tal:condition='not:verifyStatus'>
             Uh oh! You don't have permission to access this area!
          </span>
          <span tal:condition='verifyStatus'>
             Welcome to the ultra-secret club.<br /><br />
             Your e-mail address is:<br />
             <span style='font-weight: bold;
                  'tal:content='verifyStatus/email'></span>
          </span>
       </body>
    </html>

    The page calls the verify object and stores the data returned in a variable called verifyStatus. If the user supplied the correct information, verifyStatus will be a dictionary containing his or her email address. The email address is printed if the user has access. If not, the user is presented with an error message.

    Conclusion

    Our system is now complete. If you wish, you can add a field to the registration form asking for other details. This can be accomplished in the same way we added a field and property for the user's email address. Don't forget to add the property to the dictionary in verify.

    As you probably noticed, user management systems are suprisingly easy to create in Zope, as are many other types of applications. A user database could also be implemented using a relational database, such as MySQL. You are not restricted to using flat files for storage.

    Good luck!



     
     
    >>> 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 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek