How do I query the ID of the current user?

(Part of ZopeInAnger)

With BrowserView? the request parameter contains the current principal. For example:

class MyBrowserView(BrowserView):

  def __init__(self, context, request):
      super(MyBrowserView,self).__init__(context,request)

        self.id = request.principal.id

If the principal is not authenticated - i.e. . the user is an anonymous, then it will provide the IUnauthenticatedPrincipal? interface:

from zope.app.security.interfaces import IUnauthenticatedPrincipal
if IUnauthenticatedPrincipal.providedBy(self.request.principal):
    print "Anonymous request"
else:
    print "Authenticated request by Principal(%r)" % request.principal.id



( 97 subscribers )