在Plone上获取当前登录的用户(get current logged user on Plone)
我想在我的plone实例中获取当前登录用户的“位置”(属性,如用户名,用户ID等)。
为了获得当前用户,我尝试过:
from AccessControl import getSecurityManager user = getSecurityManager().getUser() username = user.getUserName()但对于用户和用户名,我得到字符串“系统进程”
我怎么解决这个问题?
编辑
我试过了
from plone import api user = api.user.get_current() user.getProperty('location')但我得到:
CannotGetPortalError:无法获取门户网站对象。
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.
最满意答案
我建议在这里使用plone.api。 您可以执行以下操作:
from plone import api user = api.user.get_current() user.getProperty('location')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更多推荐
发布评论