Пример #1
0
    /// <summary>
    /// Signs in user or registers a new user.
    /// </summary>
    private void SetupControlForPublicUser()
    {
        RegisterFacebookScript();

        // Validate FB access token against FB server
        string facebookUserId       = null;
        bool   facebookCookiesValid = false;

        string confirmToken = QueryHelper.GetString(CONFIRMATION_URLPARAMETER, null);
        string appSecret    = FacebookConnectHelper.GetFacebookAppSecretKey(SiteContext.CurrentSiteName);

        if (!String.IsNullOrEmpty(confirmToken))
        {
            facebookCookiesValid = FacebookConnectHelper.ValidateFBAccessToken(confirmToken, appSecret, out facebookUserId);
        }

        // If user has signed in
        if (!String.IsNullOrEmpty(facebookUserId) && facebookCookiesValid)
        {
            UserInfo ui = UserInfoProvider.GetUserInfoByFacebookConnectID(facebookUserId);

            // Claimed Facebook ID is in DB
            if (ui != null)
            {
                SignInUser(ui, facebookUserId, confirmToken);
            }
            // Claimed Facebook ID not found  = save new user
            else
            {
                RegisterNewUser(facebookUserId, confirmToken);
            }
        }
    }
Пример #2
0
    /// <summary>
    /// Maps the values of Facebook user profile attributes to the values of CMS user fields depending on the current settings.
    /// </summary>
    /// <param name="mappingTrigger">Specifies when the mapping of Facebook user profile occurs.</param>
    /// <param name="user">The CMS user.</param>
    /// <param name="userProfileId">The Facebook user profile identifier.</param>
    /// <param name="facebookAccessToken">The Facebook access token.</param>
    /// <remarks>
    /// The CMS user name is updated only if it was generated by the CMS.
    /// </remarks>
    private void MapFacebookUserProfile(FacebookUserProfileMappingTriggerEnum mappingTrigger, UserInfo user, string userProfileId, string facebookAccessToken)
    {
        var  facebookUserProvider = new FacebookUserProvider();
        var  facebookUser         = facebookUserProvider.GetFacebookUser(userProfileId, facebookAccessToken, FacebookConnectHelper.GetFacebookAppSecretKey(SiteContext.CurrentSiteName));
        bool userChanged          = false;

        // Change user's full name if it is in default format
        if (String.IsNullOrEmpty(user.FullName) || (user.FullName == UserInfoProvider.FACEBOOKID_FULLNAME_PREFIX + userProfileId))
        {
            user.FullName = facebookUser.FacebookName;
            userChanged   = true;
        }

        // Map Facebook user on appropriate action
        if (FacebookMappingHelper.GetUserProfileMappingTrigger(SiteContext.CurrentSiteName) >= mappingTrigger)
        {
            FacebookMappingHelper.MapUserProfile(facebookUser, user);
            userChanged = true;
        }

        if (userChanged)
        {
            user.Update();
        }
    }