Sam Sam - 7 months ago 25
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?

edit

I've tried

from plone import api
user = api.user.get_current()
user.getProperty('location')


but I get:


CannotGetPortalError: Unable to get the portal object.

Sam Sam
Answer

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