Zope在關于用戶的2個操作
發表于:2007-06-11來源:作者:點擊數:
標簽:
1.在Zpt內獲取當前用戶名稱 Curruser is p tal:define="a python:modules['AccessControl']" tal:replace="python:a.getSecurityManager().getUser()" user/p 在Zpt內使用python module可以采用tal:define="a python:modules[modulename]"方式,如上在python
1.在Zpt內獲取當前用戶名稱
Curruser is
<p tal:define="a python:modules['Aclearcase/" target="_blank" >ccessControl']"
tal:replace="python:a.getSecurityManager().getUser()"> user</p>
|
在Zpt內使用python module可以采用tal:define="a python:modules[modulename]"方式,如上在pythonScript中可以:
a = AccessControl.getSecurityManager().getUser()
print a
getUser()返回的 AuthenticatedUser |
值得注意的是,在Zpt和pyscript中不是所有的模塊都可以引入,比如你引入了AuthenticatedUser,會被提示再次上下文不能引入。要想避免該限制應該改用External Method
2.判斷用戶是否有某一個角色
au = AccessControl.getSecurityManager().getUser()
print au.getRoles()
if au.has_role("技巧管理者"):
print "ok"
else:
print "no" |
(責任編輯:銘銘)