Zope
  Home arrow Zope arrow Page 4 - Flat User Management in Zope
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
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? 
ZOPE

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

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

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    PCmover - $15 Off with Coupon Code CJPH7Q

    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!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · For programmers familiar with other languages, most of that is pretty self...
       · Hello. Thanks for your commnents!There are a few other articles on DevShed which...
       · This article is very hard to follow for people new to Zope. Saying things like...
       · thanks for the tutorial! after going through it, i was able to easily migrate the...
     

       

    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-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway