简体   繁体   English

如何在sharepoint中使用Javascript验证登录用户

[英]How to verify the logged in user using Javascript in sharepoint

I need to check whether the logged in user is a administrator or non-admin user by using JavaScript in sharepoint designer or content editor webpart. 我需要通过在sharepoint设计器或内容编辑器webpart中使用JavaScript来检查登录用户是管理员还是非管理员用户。

Can anybody suggest? 谁有人建议?

You can use the HasRights javascript function defined in SharePoints core.js , you just have to pass the lower (limit) permission mask as well as the upper limit. 您可以使用SharePoints core.js定义的HasRights javascript函数,您只需传递较低(限制)权限掩码以及上限。

See the post about Checking Permissions with Javascript in Sharepoint 2007 and the list of permission masks . 请参阅Sharepoint 2007中有关使用Javascript检查权限的帖子以及权限掩码列表 As you want to check whether it is an administrator you could try the ManageWeb permission mask: 0x0000000040000000 如果要检查它是否是管理员,可以尝试使用ManageWeb权限掩码: 0x0000000040000000


Edit: Another possibility is not using the HasRights function, but a SPSecurityTrimmedControl to simply set a global Javascript variable. 编辑:另一种可能性是不使用HasRights函数,而是使用SPSecurityTrimmedControl来简单地设置全局Javascript变量。 An example you can find here: SharePoint: Run JavaScript based on user rights / permissions . 您可以在此处找到示例: SharePoint:根据用户权限/权限运行JavaScript This of course means extra markup (and doesn't work in a content editor webpart), but it does work. 这当然意味着额外的标记(并且在内容编辑器webpart中不起作用),但它确实有效。

You can use JQuery and SPServices to examine the group a logged in user belongs to, see my post here which explains the principle. 您可以使用JQuery和SPServices来检查登录用户所属的组,请参阅此处的帖子其中说明了原理。 In that case, it hides an element if a user belongs to a particular group. 在这种情况下,如果用户属于特定组,它会隐藏元素。

On the web part, after you edit it there is aa field called target audience. 在Web部件上,在您编辑它之后,有一个名为目标受众的字段。 You can only put groups here so put the user in group first. 您只能在此处放置组,因此请先将用户置于组中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何验证用户通过javascript中的Firebase登录 - How to verify user is logged in through firebase in javascript SharePoint-使用ASP获取登录用户,使用JavaScript进行操作? - SharePoint - get logged-in user with ASP, manipulate with javascript? 如何使用Javascript添加事件监听器来验证用户输入? - How to verify user input using Javascript add Event Listener? 如何使用 Javascript 在 Firestore 中验证用户的 ID 令牌? - How to verify a user's ID token in firestore using Javascript? 如何通过在SharePoint2013中使用angularJS登录的用户筛选列表结果 - How do I filter my list results by the user logged on using angularJS in SharePoint2013 如何显示使用javascript登录html页面的用户数据? - How to display data of user logged in in an html page using javascript? 如何使用JavaScript找出登录用户的域? - How do I find out the domain of logged on user using JavaScript? 如何使用javascript确定登录用户的浏览器版本和IP地址 - how to determine the browser version and IP address of logged in user using javascript 验证用户已登录的正确方法 - Right way to verify that a user is logged 收到推送通知时如何验证用户是否仍处于登录状态? - How to verify the user is still logged in when getting a push notification?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM