[Product-Developers] Determining the UserName, grok.View class, permission = zope2.View

Kevin Gill kevin at movieextras.ie
Tue Mar 8 15:10:06 UTC 2011


On 08/03/11 14:27, Martin Aspeli wrote:
> On 8 March 2011 13:56, Kevin Gill<kevin at movieextras.ie>  wrote:
>> Hi,
>>
>> I have a view, which is available to all users. I want to have different
>> logic based on the user name if the user is logged in. The view is a
>> grok.View. Unfortunately, the user is not authenticated before the view is
>> invoked. Is there another View baseclass that I should be using?
>>
>> My understanding is that "zope2.View" should invoke the authentication
>> machinery whereas "zope2.Public" would not.
> Correct (ish),but security is never set up in __init__ on any view.
> You cannot do security or principal checks there. Use update()
> instead.
>
Thanks martin. That make sense.

Kevin


> Martin
>
>> Thanks,
>>
>> Kevin
>>
>>
>> from five import grok
>>
>> class ListTags(grok.View):
>>     grok.context(Interface)
>>     grok.require('zope2.View')
>>
>>     def __init__(self, context, request):
>>         super(ListTags, self).__init__(context, request)
>>         import pdb; pdb.set_trace()
>>
>> However, even though I am logged in
>>
>> (Pdb) context.portal_membership.isAnonymousUser()
>> 1
>>
>> Later on in the same request, code called from a viewlet is authenticated...
>>
>> (Pdb) context.portal_membership.isAnonymousUser()
>> 0
>>
>>
>> _______________________________________________
>> Product-Developers mailing list
>> Product-Developers at lists.plone.org
>> https://lists.plone.org/mailman/listinfo/product-developers
>>




More information about the Product-Developers mailing list