Provides the structure required to hold user meta-data. It includes user ID, name/alias, logged-in user name, and email.
Exemplo n.º 1
0
        /// <summary>
        /// This method will get user profile picture of the login user
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        public async Task<Users> GetUserProfilePicture(Client client)
        {
            Users users = new Users();
            try
            {
                string accessToken = spoAuthorization.GetGraphAccessToken();
                using (var httpClient = new HttpClient())
                {
                    httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);                    
                    var url = $"{generalSettings.GraphUrl}/v1.0/me/photo/$value";
                    var resultAsString = await httpClient.GetStreamAsync(url);

                    using (var newStream = new MemoryStream())
                    {
                        resultAsString.CopyTo(newStream);
                        byte[] bytes = newStream.ToArray();
                        users.LargePictureUrl = ServiceConstants.BASE64_IMAGE_FORMAT + Convert.ToBase64String(bytes);
                    }
                    return users;
                }
            }
            catch(Exception ex) when(ex.Message.Contains("404"))
            {
                users.LargePictureUrl = "";
                return users;
            }
            catch (Exception ex)
            {
                throw;
            }

        }
Exemplo n.º 2
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="searchRequestVM"></param>
 /// <returns></returns>
 public async Task<IList<Users>> GetUsersAsync(SearchRequestVM searchRequestVM)
 {
     IList<PeoplePickerUser> foundUsers = await Task.FromResult(search.SearchUsers(searchRequestVM));
     IList<Users> users = new List<Users>();
     if (foundUsers != null && foundUsers.Count != 0)
     {
         foreach (PeoplePickerUser item in foundUsers)
         {
             Users tempUser = new Users();
             tempUser.Name = Convert.ToString(item.DisplayText, CultureInfo.InvariantCulture);
             tempUser.LogOnName = Convert.ToString(item.Key, CultureInfo.InvariantCulture);
             tempUser.Email = string.Equals(item.EntityType, ServiceConstants.PEOPLE_PICKER_ENTITY_TYPE_USER, StringComparison.OrdinalIgnoreCase) ?
                 Convert.ToString(item.Description, CultureInfo.InvariantCulture) : Convert.ToString(item.EntityData.Email, CultureInfo.InvariantCulture);
             tempUser.EntityType = Convert.ToString(item.EntityType, CultureInfo.InvariantCulture);
             tempUser.EntityDataTitle = string.IsNullOrWhiteSpace(item.EntityData.Title) ? "" : "(" + item.EntityData.Title.Trim() + ")";
             users.Add(tempUser);
         }
         return users;
     }
     return users;
 }
Exemplo n.º 3
0
        /// <summary>
        /// This method will return the user object who has currently logged into the system
        /// </summary>
        /// <param name="clientContext"></param>
        /// <returns></returns>
        public static Users GetLoggedInUserDetails(ClientContext clientContext)
        {
            Users currentUserDetail = new Users();
            try
            {
                clientContext.Load(clientContext.Web.CurrentUser, userInfo => userInfo.Title, userInfo => userInfo.Email, userInfo => userInfo.LoginName);
                clientContext.ExecuteQuery();
                currentUserDetail.Name = clientContext.Web.CurrentUser.Title;
                currentUserDetail.Email = clientContext.Web.CurrentUser.Email;

                //Check if email is available to get account name, if not use login name
                if (!String.IsNullOrEmpty(currentUserDetail.Email))
                {
                    currentUserDetail.LogOnName = currentUserDetail.Email;
                }
                else
                {
                    currentUserDetail.LogOnName = clientContext.Web.CurrentUser.LoginName;
                }

                //Retrieve user name from login
                int splitPositionStart;
                int splitPositionEnd = currentUserDetail.LogOnName.LastIndexOf(ServiceConstants.SYMBOL_AT, StringComparison.OrdinalIgnoreCase);
                if (splitPositionEnd == -1)  //The user is an on-premise account
                {
                    splitPositionStart = currentUserDetail.LogOnName.LastIndexOf(ServiceConstants.BACKWARD_SLASH, StringComparison.OrdinalIgnoreCase) + 1;
                    splitPositionEnd = currentUserDetail.LogOnName.Length;
                }
                else
                {
                    splitPositionStart = currentUserDetail.LogOnName.LastIndexOf(ServiceConstants.PIPE, StringComparison.OrdinalIgnoreCase) + 1;
                }
                currentUserDetail.LogOnName = currentUserDetail.LogOnName.Substring(splitPositionStart, splitPositionEnd - splitPositionStart);
                return currentUserDetail;
            }

            catch (Exception exception)
            {
                throw;
            }

        }
Exemplo n.º 4
0
 public async Task<IActionResult> GetUsers([FromBody]SearchRequestVM searchRequestVM)
 {
     try
     {                
         #region Error Checking                
         GenericResponseVM genericResponse = null;                
         if (searchRequestVM.Client == null && string.IsNullOrWhiteSpace(searchRequestVM.Client.Url))
         {
             genericResponse = new GenericResponseVM()
             {
                 Value = errorSettings.MessageNoInputs,
                 Code = HttpStatusCode.BadRequest.ToString(),
                 IsError = true
             };
             return matterCenterServiceFunctions.ServiceResponse(genericResponse, (int)HttpStatusCode.OK);
         }
         #endregion
         searchRequestVM.SearchObject.SearchTerm = (!string.IsNullOrWhiteSpace(searchRequestVM.SearchObject.SearchTerm)) ? 
             searchRequestVM.SearchObject.SearchTerm : string.Empty;
         IList<Users> users = await userRepositoy.GetUsersAsync(searchRequestVM);
         if (users != null && users.Count != 0)
         {
             return matterCenterServiceFunctions.ServiceResponse(users, (int)HttpStatusCode.OK);
         }
         else
         {
             Users noResult = new Users()
             {
                 Name = errorSettings.PeoplePickerNoResults,
                 LogOnName = string.Empty,
                 Email = string.Empty,
                 EntityType = string.Empty
             };
             users.Add(noResult);
             return matterCenterServiceFunctions.ServiceResponse(users, (int)HttpStatusCode.OK);
         }
     }
     catch (Exception ex)
     {
         customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
         throw;
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// get users
 /// </summary>        
 /// <param name="client">Client object containing Client data</param>
 /// <param name="details">Term Store object containing Term store data</param>
 /// <returns>Returns JSON object to the client</returns>        ///
 public async Task<IActionResult> GetUsers([FromBody]SearchRequestVM searchRequestVM)
 {
     try
     {
         spoAuthorization.AccessToken = HttpContext.Request.Headers["Authorization"];
         #region Error Checking                
         ErrorResponse errorResponse = null;
         //if the token is not valid, immediately return no authorization error to the user
         if (errorResponse != null && !errorResponse.IsTokenValid)
         {
             return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.Unauthorized);
         }
         if (searchRequestVM.Client == null)
         {
             errorResponse = new ErrorResponse()
             {
                 Message = errorSettings.MessageNoInputs,
                 ErrorCode = HttpStatusCode.BadRequest.ToString(),
                 Description = "No input data is passed"
             };
             return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.BadRequest);
         }
         #endregion
         searchRequestVM.SearchObject.SearchTerm = (!string.IsNullOrWhiteSpace(searchRequestVM.SearchObject.SearchTerm)) ? searchRequestVM.SearchObject.SearchTerm : string.Empty;
         IList<Users> users = await matterRepositoy.GetUsersAsync(searchRequestVM);
         if (users != null && users.Count != 0)
         {
             return matterCenterServiceFunctions.ServiceResponse(users, (int)HttpStatusCode.OK);
         }
         else
         {
             Users noResult = new Users()
             {
                 Name = errorSettings.PeoplePickerNoResults,
                 LogOnName = string.Empty,
                 Email = string.Empty,
                 EntityType = string.Empty
             };
             users.Add(noResult);
             return matterCenterServiceFunctions.ServiceResponse(users, (int)HttpStatusCode.OK);
         }
     }
     catch (Exception ex)
     {
         customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
         throw;
     }
 }