Sam Sam - 1 year ago 99
Python Question

get current logged user on Plone

I would like to get the 'location' (an attribute, like username, user id, ...) of current logged user in my plone instance.

To get the current user I've tried:

from AccessControl import getSecurityManager
user = getSecurityManager().getUser()
username = user.getUserName()

But for both user and username I get the string "System Processes"

How can I solve this?


I've tried

from plone import api
user = api.user.get_current()

but I get:

CannotGetPortalError: Unable to get the portal object.

Sam Sam
Answer Source

I've found a solution here.

from Products.CMFCore.utils import getToolByName

membership = getToolByName(self.context, 'portal_membership')
authenticated_user = membership.getAuthenticatedMember().getProperty('location') 
print authenticated_user