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 Version 3 and Version 4 of IdentityManagement


Ignore:
Timestamp:
11/11/05 20:08:00 (9 years ago)
Author:
koorb
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • IdentityManagement

    v3 v4  
    1 '''''This was ripped from [http://metrocat.org/nerd/2005/10/identity-management-for-turbogears Jeff Watkins' blog].''''' 
     1= Identity Management = 
    22 
    3 '''''...with a little changes to play nice with latest svn [as of 6th Nov 2005]''''' 
     3 
     4  '''This was ripped from [http://metrocat.org/nerd/2005/10/identity-management-for-turbogears Jeff Watkins' blog].''' 
     5 
     6  ...with a little changes to play nice with latest svn [as of 6th Nov 2005] 
     7 
    48 
    59I 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. 
     
    711This How To is written from the perspective of a fresh quick-started project, but most everything applies for existing projects. 
    812 
     13---- 
    914'''Step 1''' Create new project (idtest). Set dburi. 
    10  
     15---- 
    1116'''Step 2''' Edit idtest.egg-info/sqlobject.txt 
    1217{{{ 
     18#!python 
    1319db_module=idtest.model,  turbogears.identity.model.somodel 
    1420}}} 
     21---- 
    1522'''Step 3''' Create login.kid 
    1623{{{ 
     24#!text/html 
    1725    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    1826        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     
    4452'''Step 4''' Create secured.kid 
    4553{{{ 
     54#!text/html 
    4655<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    4756    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     
    6271</html> 
    6372}}} 
    64 '''Step 5''' Modify controllers.py 
     73---- 
     74'''Step 5''' Add to the top of controllers.py: 
    6575{{{ 
    6676#!python 
    6777from turbogears import identity 
    6878import cherrypy 
    69  
     79}}} 
     80and to the model class: 
     81{{{ 
     82#!python 
    7083@turbogears.expose( html="idtest.templates.login" ) 
    7184def login( self, *args, **kw ): 
     
    8497    return dict() 
    8598}}} 
     99---- 
    86100'''Step 6''' Turn on Identity management and configure failure url in dev.cfg 
    87101{{{ 
     
    90104identity.failure_url="/login" 
    91105}}} 
     106---- 
    92107'''Step 7''' Create the database 
    93108{{{ 
    94109tg-admin sql create 
    95110}}} 
     111---- 
    96112'''Step 8''' Create a user and group 
    97113{{{ 
     
    110126>>> 
    111127}}} 
     128---- 
    112129'''Step 9''' Start project and visit secured page and login. Should fail with message: 
    113130{{{ 
    114131Not member of group: admin 
    115132}}} 
     133---- 
    116134'''Step 10''' Add user to admin group 
    117135{{{ 
     
    130148>>> 
    131149}}} 
     150---- 
    132151'''Step 11''' Revisit secured page and login. Should succeed. 
    133152 
     
    135154=== Other Considerations === 
    136155 
    137 Question: how do I retrieve the userId in my application code? 
    138 Answer: Actually you can access the entire User object by accessing turbogears.identity.current.user. This gives you access to the userId, displayName, emailAddress, and creation date. 
     156'''How do I retrieve the userId in my application code?''' 
    139157 
    140 Question: So, if I wanted to access the users’ group info, how would I do that?  
    141 Answer:  
     158Actually you can access the entire User object by accessing turbogears.identity.current.user. This gives you access to the userId, displayName, emailAddress, and creation date. 
     159 
     160'''So, if I wanted to access the users’ group info, how would I do that?''' 
     161 
     162There are two ways you can access the group information. 
     163 
     164'''1.''' Via the current identity object: 
    142165{{{ 
    143 ...there are two ways you can access the group information. 
    144  
    145    1. Via the current identity object: 
    146  
     166#!python 
    147167from turbogears import identity 
    148168if 'admin' in identity.current.groups: 
    149169    pass 
    150  
    151    2. Via the user object on the current identity: 
    152  
     170}}} 
     171'''2.''' Via the user object on the current identity: 
     172{{{ 
     173#!python 
    153174from turbogears import identity 
    154175if 'admin' in [g.groupId for g in identity.current.user.groups]: 
    155176    pass 
    156  
    157 Option number 2 only works if your using a Model that supports groups on the user object. So, with the default model you’ll be set. Other models might not work so well. 
    158177}}} 
    159178 
     179''Option number 2 only works if your using a Model that supports groups on the user object. So, with the default model you’ll be set. Other models might not work so well.''