在Plone上获取当前登录的用户(get current logged user on Plone)

编程入门 行业动态 更新时间:2024-10-24 22:29:44
在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

更多推荐

本文发布于:2023-07-14 20:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1107300.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:用户   Plone   current   user   logged

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!