Zope
  Home arrow Zope arrow Page 3 - 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 
IBM Developerworks
 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

    Route your faxes to your email inbox. Private, secure fax numbers available from CallWave. Choose your fax number.

    Flat User Management in Zope - Login
    (Page 3 of 4 )

    We now need to create a login system that allows the user to login with his or her username and password. Create a Zope Page Template object named login_html. The login_html object is almost identical to the register_html object in the previous section:

    <html>
       <head>
          <title>Login</title>
       </head>
       <body tal:define='logStatus container/login'>
          <span tal:condition='logStatus'>
             <span tal:replace='logStatus'></span>
          </span>
          <span tal:condition='not:logStatus'>
             <form method='POST'>
                <label>Username:</label><br />
                <input type='text' name='username'><br />
                <label>Password:</label><br />
                <input type='password' name='password'><br />
                <input type='submit' value='Login'>
             </form>
          </span>
       </body>
    </html>

    However, instead of calling the register object, it calls an object named login. Create a Script ( Python ) object called login:

    if context.REQUEST.has_key ( 'username' ) and context.REQUEST.has_key ( 'password' ):
       if not hasattr ( container.users, context.REQUEST.username ):
          return 'No such user exists.'
       password = container.hash ( context.REQUEST.password )
       userObject = getattr ( container.users,context.REQUEST.username )
       if password != userObject.password:
          return 'You have specified an incorrect password.'
       context.REQUEST.RESPONSE.setCookie ( 'username', context.REQUEST.username )
       context.REQUEST.RESPONSE.setCookie ( 'password', password )
       return 'You have successfully logged in!'
    return False

    Like the register object, the login object first checks to see if the user has submitted the appropriate values. If the user hasn't, the script returns "False" and stops execution. This signals the login_html object to display the login form. If the user has supplied the appropriate values, the script checks to see if the username even exists. If the username does not exist, the script returns a message saying so. If the username does exist, the script uses the hash object to, once again, hash the user's password. It then check to see if the supplied password and the stored password match. If they do, it sets one cookie containing the user's username, and another cookie containing the user's hashed password. It then returns a success message.

    The login system is now done, and it will work in conjunction with the registration system. Feel free to test both systems out.

    More Zope Articles
    More By Peyton McCullough


       · 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 3 hosted by Hostway