简体   繁体   English

从Sharepoint托管的角度应用程序获取当前登录的用户

[英]getting currently logged in user from sharepoint hosted angular app

I'm trying to figure out how to get at least the currently logged in sharepoint user's id from within a sharepoint-hosted angular sharepoint app. 我试图弄清楚如何从共享点托管的角度共享点应用程序中至少获取当前登录的共享点用户的ID。 I'm unable to call libraries outside of angular and get the value back and apply it to my angular model. 我无法调用angular以外的库并将其取回并将其应用于我的angular模型。 does anyone know how to do this? 有谁知道如何做到这一点?

The _spcontextinfo is null even when i get it using the $windows service or when i try using this code 即使使用$ windows服务获取_spcontextinfo还是尝试使用此代码 ,_spcontextinfo也为null

and I cannot figure out how to call spservices with something like 而且我不知道如何用类似的东西来调用spservices

var thisUsersValues = $().SPServices.SPGetCurrentUser({ fieldNames: ["ID", "Name", "SIP Address"], debug: false });

https://spservices.codeplex.com/wikipage?title=$().SPServices.SPGetCurrentUser&referringTitle=Documentation

what do I need to do in angular to call this code that normally would work in regular javascript? 我需要做些什么才能调用通常在常规javascript中工作的代码?

Getting the SharePoint logged in user without any libraries will be a little tough. 在没有任何库的情况下让SharePoint登录用户会有些困难。 Ideally, you would want to use jQuery and SPServices.JS and it would be relatively straight forward. 理想情况下,您将要使用jQuery和SPServices.JS,并且相对来说比较简单。 However, since you don't want to use a 3rd party library, I would suggest calling one of SharePoints built in web services via your JavaScript. 但是,由于您不想使用第三方库,因此建议您通过JavaScript调用内置于Web服务中的SharePoint之一。

SharePoint Web Services SharePoint Web服务

You can use SharePoint Client Object Model. 您可以使用SharePoint客户端对象模型。 This is a possible solution for you 这是您可能的解决方案

http://www.instantquick.com/index.php/using-the-sharepoint-client-object-model-in-angularjs-apps?c=elumenotion-blog-archive/random-whatnot http://www.instantquick.com/index.php/using-the-sharepoint-client-object-model-in-angularjs-apps?c=elumenotion-blog-archive/random-whatnot

Built a Angular Factory 建一个角工厂

//Angular service Wrapper for ClientContext executeQuery.
//The $q service makes it easy to wrap SharePoint's context.executeQueryAsync for use with Angular
var module = angular.module('iqPart', [])
 .factory('SharePointService', ['$q', function ($q) {
   var SharePointService = {};
   SharePointService.executeQuery = function (context) {
     var deferred = $q.defer();
     context.executeQueryAsync(deferred.resolve, function (o, args) {
       deferred.reject(args);
     });
     return deferred.promise;
  };
  return SharePointService;
}]);

Usage within Angular Controller Angular Controller中的用法

var iqAppPartModule = angular.module('iqAppPartModule', []);
var iqAppPartController = iqAppPartController || {};

iqAppPartController.IQAppPart = function ($scope, sharePointService) {
  //Make a request for the user
  var ctx = SP.ClientContext.get_current();
  var user = ctx.get_web().get_currentUser();
  ctx.load(user);
 sharePointService.executeQuery(ctx)
   .then(function () {
     $scope.UserName = user.get_title();
   },
   function (error) {
     alert(error.get_message());
 });
};
iqAppPartModule.controller('IQAppPart', ['$scope', 'SharePointService', iqAppPartController.IQAppPart]);

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

相关问题 从Firefox扩展中查找当前登录的用户 - Finding the currently logged in user from a Firefox extension 使用Laravel for API和用户登录来反应应用。 有关从数据库中检索当前登录用户的问题 - React app using Laravel for API and user login. Question about retrieving currently logged in user from database 尝试根据属于 Sharepoint 组的当前登录用户隐藏 Sharepoint 列表的新建/编辑表单中的字段 - Trying to hide field in New/Edit form of Sharepoint list based on currently logged in user belonging to a Sharepoint group 用户登录后获取用户个人资料 - Getting user profile in angular after user logged in 将更改保存到当前未登录的用户 - Save changes to a user that is not currently logged in 如何从Internet Explorer删除SharePoint托管的应用程序中的滚动条 - How to remove a scrollbar in a sharepoint hosted App from internet Explorer SharePoint托管的应用程序REST API - SharePoint hosted app REST API 如何使用当前登录的 Windows Active Directory 用户登录 Web 应用程序? - How to use currently logged in Windows Active Directory user to login to a web app? 如何检查用户当前是否正在登录并正在玩Facebook应用程序游戏 - How can I check if a user is currently logged in and playing a facebook app game 从 bearer_token O365 获取当前登录用户的用户信息 - Obtain user information from bearer_token O365 for currently logged in user
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM