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


Ignore:
Timestamp:
11/06/05 16:24:05 (9 years ago)
Author:
anonymous
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • IdentityManagement

    v2 v3  
    11'''''This was ripped from [http://metrocat.org/nerd/2005/10/identity-management-for-turbogears Jeff Watkins' blog].''''' 
    22 
    3 '''''...with a little change to play nice with latest svn [as of 6th Nov 2005]''''' 
     3'''''...with a little changes to play nice with latest svn [as of 6th Nov 2005]''''' 
    44 
    55I 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. 
     
    7676    cherrypy.response.status=403 
    7777    return dict( message=msg, previous_url=cherrypy.request.path ) 
     78    #to preserve the session you may want to return this instead: 
     79    #return dict( message = msg, previous_url = turbogears.url( cherrypy.request.path, cherrypy.request.paramMap ) ) 
    7880 
    7981@turbogears.expose( html="idtest.templates.secured" ) 
     
    132134---- 
    133135=== Other Considerations === 
     136 
     137Question: how do I retrieve the userId in my application code? 
     138Answer: 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. 
     139 
     140Question: So, if I wanted to access the users’ group info, how would I do that?  
     141Answer:  
     142{{{ 
     143...there are two ways you can access the group information. 
     144 
     145   1. Via the current identity object: 
     146 
     147from turbogears import identity 
     148if 'admin' in identity.current.groups: 
     149    pass 
     150 
     151   2. Via the user object on the current identity: 
     152 
     153from turbogears import identity 
     154if 'admin' in [g.groupId for g in identity.current.user.groups]: 
     155    pass 
     156 
     157Option 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. 
     158}}} 
     159