Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Changes between Initial Version and Version 1 of IdentityManagement


Ignore:
Timestamp:
11/01/05 12:56:42 (14 years ago)
Author:
SuperJared
Comment:

Added IdentityManagement page

Legend:

Unmodified
Added
Removed
Modified
  • IdentityManagement

    v1 v1  
     1'''''This was ripped from [http://metrocat.org/nerd/2005/10/identity-management-for-turbogears Jeff Watkins' blog].''''' 
     2 
     3I just committed the code for the TurboGears identity management support (revision 89). And because this is such new code, I thought it might be helpful to include a short How To for getting everything up and running. 
     4 
     5This How To is written from the perspective of a fresh quick-started project, but most everything applies for existing projects. 
     6 
     7'''Step 1''' Create new project (idtest). Set dburi. 
     8 
     9'''Step 2''' Edit idtest.egg-info/sqlobject.txt 
     10{{{ 
     11db_module=idtest.model, turbogears.identity.model 
     12}}} 
     13'''Step 3''' Create login.kid 
     14{{{ 
     15    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
     16        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     17    <html xmlns="http://www.w3.org/1999/xhtml" 
     18        xmlns:py="http://purl.org/kid/ns#" 
     19        py:extends="'master.kid'"> 
     20 
     21    <head> 
     22        <meta content="text/html; charset=UTF-8" 
     23            http-equiv="content-type" py:replace="''"/> 
     24        <title>Login to TurboGears</title> 
     25    </head> 
     26 
     27    <body> 
     28        <h2>Login</h2> 
     29        <p>${message}</p> 
     30        <form action="${previous_url}" method="POST"> 
     31            <label for="user_name">User Name:</label> 
     32            <input type="text" id="user_name" name="user_name"/><br/> 
     33 
     34            <label for="password">Password:</label> 
     35            <input type="password" id="password" name="password"/><br/> 
     36 
     37            <input type="submit" value="Login"/> 
     38        </form> 
     39    </body> 
     40    </html> 
     41}}} 
     42'''Step 4''' Create secured.kid 
     43{{{ 
     44<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
     45    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     46<html xmlns="http://www.w3.org/1999/xhtml" 
     47   xmlns:py="http://purl.org/kid/ns#" 
     48   py:extends="'master.kid'"> 
     49 
     50<head> 
     51    <meta content="text/html; charset=UTF-8" 
     52        http-equiv="content-type" py:replace="''"/> 
     53   <title>Welcome to Secured TurboGears</title> 
     54</head> 
     55 
     56<body> 
     57    <h2>Secure!</h2> 
     58    <p>This page is secured.</p> 
     59</body> 
     60</html> 
     61}}} 
     62'''Step 5''' Modify controllers.py 
     63{{{ 
     64#!python 
     65from turbogears import identity 
     66import cherrypy 
     67 
     68@turbogears.expose( html="idtest.templates.login" ) 
     69def login( self, *args, **kw ): 
     70    if hasattr(cherrypy.request,"identity_exception"): 
     71        msg= str(cherrypy.request.identity_exception) 
     72    else: 
     73        msg= "Please log in" 
     74    cherrypy.response.status=403 
     75    return dict( message=msg, previous_url=cherrypy.request.path ) 
     76 
     77@turbogears.expose( html="idtest.templates.secured" ) 
     78@identity.require( group="admin" ) 
     79def secured( self ): 
     80    return dict() 
     81}}} 
     82'''Step 6''' Turn on Identity management and configure failure url in dev.cfg 
     83{{{ 
     84[global] 
     85identity.on=True 
     86identity.failure_url="/login" 
     87}}} 
     88'''Step 7''' Create the database 
     89{{{ 
     90tg-admin sql create 
     91}}} 
     92'''Step 8''' Create a user and group 
     93{{{ 
     94tg-admin shell 
     95 
     96Python 2.4.1 (#2, Mar 31 2005, 00:05:10)  
     97[GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin 
     98Type "help", "copyright", "credits" or "license" for more information. 
     99(InteractiveConsole) 
     100>>> from turbogears.identity.model import * 
     101>>> hub.begin() 
     102>>> u=User( userId="jeff", emailAddress="jeff@metrocat.org", 
     103            displayName="Jeff Watkins", password="xxxxx" ) 
     104>>> g=Group( groupId="admin", displayName="Administrators" ) 
     105>>> hub.commit() 
     106>>> 
     107}}} 
     108'''Step 9''' Start project and visit secured page and login. Should fail with message: 
     109{{{ 
     110Not member of group: admin 
     111}}} 
     112'''Step 10''' Add user to admin group 
     113{{{ 
     114tg-admin shell 
     115 
     116Python 2.4.1 (#2, Mar 31 2005, 00:05:10)  
     117[GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin 
     118Type "help", "copyright", "credits" or "license" for more information. 
     119(InteractiveConsole) 
     120>>> from turbogears.identity.model import * 
     121>>> hub.begin() 
     122>>> u=User.get(1) 
     123>>> g=Group.get(1) 
     124>>> u.addGroup(g) 
     125>>> hub.commit() 
     126>>> 
     127}}} 
     128'''Step 11''' Revisit secured page and login. Should succeed. 
     129 
     130---- 
     131=== Other Considerations ===