protected void Page_Load(object sender, EventArgs e)
    {
        CheckPermissions(ModuleName.SOCIALMARKETING, PermissionsEnum.Read.ToString());
        PageTitle.TitleText            = GetString("sm.linkedin.account.companyaccesstoken");
        PageTitle.ShowFullScreenButton = false;
        PageTitle.ShowCloseButton      = false;

        if (Parameters == null)
        {
            ShowError(GetString("dialogs.badhashtext"));
            return;
        }

        var data = LinkedInProvider.GetLinkedInData();

        if (data.UserDeniedAccess)
        {
            ShowError(GetString("sm.linkedin.account.msg.accesstokenrefused"));
            return;
        }

        var url = LinkedInHelper.GetPurifiedUrl();

        if (!String.IsNullOrEmpty(data.Code))
        {
            CompleteAuthorization(data, url);
            return;
        }

        BeginAuthorization(url);
    }
        /// <summary>
        /// Create user from the LinkedIn profile data.
        /// </summary>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        private bool CreateUserFromLinkedInProfileData(string accessToken)
        {
            // get the email address from the profile
            var emailAddress = LinkedInHelper.GetProfileEmailAddress(accessToken);

            if (string.IsNullOrEmpty(emailAddress))
            {
                Log.Write("LinkedIn: Email address not present in the response.");

                return(false);
            }

            // if an account already exist then authenticate
            var existingUser = SitefinityHelper.GetUserByEmail(emailAddress);

            if (existingUser != null)
            {
                if (!AuthenticateUser(emailAddress))
                {
                    Log.Write("LinkedIn: Unable to authenticate user using the email address.");

                    return(false);
                }

                return(true);
            }

            // at this point create a new account

            var profile = LinkedInHelper.GetProfile(accessToken);

            var membershipCreateStatus = SitefinityHelper.CreateUser(
                emailAddress,
                System.Web.Security.Membership.GeneratePassword(12, 2),
                profile.FirstName,
                profile.LastName,
                emailAddress,
                null,
                null,
                null,
                true,
                true
                );

            if (membershipCreateStatus != MembershipCreateStatus.Success)
            {
                Log.Write("LinkedIn: Unable to create user account.");

                return(false);
            }

            if (!AuthenticateUser(emailAddress))
            {
                Log.Write("LinkedIn: Unable to authenticate user using the email address after registration.");

                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (!StopProcessing)
        {
            if (!LicenseHelper.CheckFeature(RequestContext.CurrentDomain, FeatureEnum.LinkedIn))
            {
                Visible = DisplayMessage(String.Format(GetString("licenselimitation.featurenotavailable"), FeatureEnum.LinkedIn));
                return;
            }

            // Check if LinkedIn module is enabled
            if (!LinkedInHelper.LinkedInIsAvailable(SiteContext.CurrentSiteName))
            {
                Visible = DisplayMessage();
                return;
            }

            DisplayButtons();
            linkedInHelper = new LinkedInHelper();
            CheckStatus();
        }
        else
        {
            Visible = false;
        }
    }
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (StopProcessing)
        {
            // Do not process
        }
        else
        {
            // Build plugin code
            string src    = "http://platform.linkedin.com/in.js";
            string apiKey = LinkedInHelper.GetLinkedInApiKey(CMSContext.CurrentSiteName);

            // Try to parse product URL
            if (ProductID.ToLowerCSafe().StartsWithCSafe("http"))
            {
                int indexStart = ProductID.LastIndexOfCSafe("-");
                int indexEnd   = ProductID.LastIndexOfCSafe("/");

                if ((indexStart != -1) && (indexEnd != -1))
                {
                    ProductID = ProductID.Substring(indexStart + 1, indexEnd - indexStart - 1);
                }
            }

            string output = "<div style=\"overflow: hidden; width: {0}px;\"><script src=\"{1}\" type=\"text/javascript\">api_key: {5}</script><script type=\"IN/RecommendProduct\" data-company=\"{2}\" data-product=\"{3}\" data-counter=\"{4}\"></script></div>";
            ltlButtonCode.Text = String.Format(output, Width.ToString(), src, CompanyID, ProductID, CountBox, apiKey);
        }
    }
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected override void SetupControl()
    {
        if (StopProcessing)
        {
            // Do not process
        }
        else
        {
            // Initialize variables
            string src         = "http://platform.linkedin.com/in.js";
            string dataModules = String.Empty;
            string apiKey      = LinkedInHelper.GetLinkedInApiKey(SiteContext.CurrentSiteName);

            //Check optional parameters
            if (ShowNetwork)
            {
                dataModules += ",innetwork";
            }

            if (ShowNewHires)
            {
                dataModules += ",newhires";
            }

            if (ShowPromotions)
            {
                dataModules += ",jobchanges";
            }

            // Build plugin code
            string output = "<div style=\"overflow: hidden;\"><script src=\"{0}\" type=\"text/javascript\">api_key: {3}</script><script type=\"IN/CompanyInsider\" data-id=\"{1}\" data-modules=\"{2}\"></script></div>";
            ltlPluginCode.Text = String.Format(output, src, CompanyID, dataModules.TrimStart(','), apiKey);
        }
    }
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (!StopProcessing)
        {
            if (SystemContext.IsFullTrustLevel)
            {
                if (!LicenseHelper.CheckFeature(RequestContext.CurrentDomain, FeatureEnum.LinkedIn))
                {
                    Visible = DisplayMessage(String.Format(GetString("licenselimitation.featurenotavailable"), FeatureEnum.LinkedIn));
                    return;
                }

                // Check if LinkedIn module is enabled
                if (!LinkedInHelper.LinkedInIsAvailable(SiteContext.CurrentSiteName))
                {
                    Visible = DisplayMessage();
                    return;
                }

                DisplayButtons();
                linkedInHelper = new LinkedInHelper();
                CheckStatus();
            }
            // Error label is displayed in Design mode when LinkedIn library is not loaded
            else
            {
                lblError.ResourceString = "socialnetworking.fulltrustrequired";
                lblError.Visible        = true;
            }
        }
        else
        {
            Visible = false;
        }
    }
Ejemplo n.º 7
0
        /// <summary>
        /// Get LinkedIn feed
        /// </summary>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        public static List <SocialFeedItemModel> GetLinkedInPosts(string accessToken)
        {
            var linkedInHelper = new LinkedInHelper(accessToken);

            //var posts = linkedInHelper.GetCurrentUserFeed();

            return(new List <SocialFeedItemModel>());
        }
    /// <summary>
    /// Sign in button event.
    /// </summary>
    protected void btnSignIn_Click(object sender, EventArgs e)
    {
        var apiKey    = LinkedInHelper.GetLinkedInApiKey(CurrentSiteName);
        var apiSecret = LinkedInHelper.GetLinkedInSecretKey(CurrentSiteName);
        var data      = new LinkedInData(apiKey, apiSecret);

        linkedInHelper.SendRequest(data);
    }
Ejemplo n.º 9
0
    /// <summary>
    /// Sign in button event.
    /// </summary>
    protected void btnSignIn_Click(object sender, EventArgs e)
    {
        var apiKey    = LinkedInHelper.GetLinkedInApiKey(CurrentSiteName);
        var apiSecret = LinkedInHelper.GetLinkedInSecretKey(CurrentSiteName);
        var data      = new LinkedInData(apiKey, apiSecret);

        data.AdditionalQueryParameters["scope"] = Scope;

        linkedInHelper.SendRequest(data);
    }
    /// <summary>
    /// Completes the authorization process. Access tokens and list of administrated companies are retrived and set to control that opened the dialog.
    /// </summary>
    private void CompleteAuthorization()
    {
        LinkedInAccessToken token;

        try
        {
            token = LinkedInHelper.CompleteAuthorization(TokenManager);
        }
        catch (Exception ex)
        {
            LogAndShowError("LinkedInCompanyAccessToken", "AUTH_COMPLETE", ex);

            return;
        }
        finally
        {
            SessionHelper.Remove(TokenManagerStoreKey);
        }

        List <LinkedInCompany> companies;

        try
        {
            companies = LinkedInHelper.GetUserCompanies((string)Parameters["ApiKey"], (string)Parameters["ApiSecret"], token.AccessToken, token.AccessTokenSecret);
        }
        catch (Exception ex)
        {
            LogAndShowError("LinkedInCompanyAccessToken", "GET_COMPANIES", ex);

            return;
        }

        string formattedExpiration = token.Expiration.HasValue ? TimeZoneHelper.ConvertToUserTimeZone(token.Expiration.Value, true, MembershipContext.AuthenticatedUser, SiteContext.CurrentSite) : String.Empty;
        JavaScriptSerializer sr    = new JavaScriptSerializer();
        string json = sr.Serialize(
            new
        {
            accessToken           = token.AccessToken,
            accessTokenSecret     = token.AccessTokenSecret,
            tokenExpiration       = token.Expiration.HasValue ? token.Expiration.Value.ToString("g", CultureInfo.InvariantCulture) : String.Empty,
            tokenExpirationString = formattedExpiration,
            tokenAppId            = Parameters["AppInfoId"],
            companies
        }
            );

        // Set retrieved access token to the opener window
        string script = String.Format(@"
if(wopener.linkedInCompanyControl && wopener.linkedInCompanyControl['{0}']) {{
    wopener.linkedInCompanyControl['{0}'].setData({1});
}}
CloseDialog();", Parameters["ClientID"], json);

        ScriptHelper.RegisterStartupScript(Page, typeof(string), "TokenScript", script, true);
    }
Ejemplo n.º 11
0
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (!this.StopProcessing)
        {
            // Check renamed DLL library
            if (CMSOpenIDHelper.CheckOpenIdDLL())
            {
                // Check if LinkedIn module is enabled
                if (LinkedInHelper.LinkedInIsAvailable(CMSContext.CurrentSiteName))
                {
                    DisplayButtons();
                    linkedInHelper = new LinkedInHelper();
                    CheckStatus();
                }
                else
                {
                    // Error label is displayed in Design mode when LinkedIn is disabled
                    if (CMSContext.ViewMode == ViewModeEnum.Design)
                    {
                        StringBuilder parameter = new StringBuilder();
                        parameter.Append(GetString("header.sitemanager") + " -> ");
                        parameter.Append(GetString("settingscategory.cmssettings") + " -> ");
                        parameter.Append(GetString("settingscategory.cmsmembership") + " -> ");
                        parameter.Append(GetString("settingscategory.cmsmembershipauthentication") + " -> ");
                        parameter.Append(GetString("settingscategory.cmslinkedin"));
                        if (CMSContext.CurrentUser.UserSiteManagerAdmin)
                        {
                            // Make it link for SiteManager Admin
                            parameter.Insert(0, "<a href=\"" + URLHelper.GetAbsoluteUrl("~/CMSSiteManager/default.aspx?section=settings") + "\" target=\"_top\">");
                            parameter.Append("</a>");
                        }

                        lblError.Text    = String.Format(GetString("mem.linkedin.disabled"), parameter.ToString());
                        lblError.Visible = true;
                    }
                    else
                    {
                        this.Visible = false;
                    }
                }
            }
            // Error label is displayed in Design mode when LinkedIn library is not loaded
            else
            {
                lblError.ResourceString = "mem.openid.library";
                lblError.Visible        = true;
            }
        }
        else
        {
            this.Visible = false;
        }
    }
Ejemplo n.º 12
0
        public ActionResult getTokenLinkedIn()
        {
            var Url = LinkedInHelper.GetToken();

            if (!string.IsNullOrEmpty(Url))
            {
                return(Redirect(Url));
            }
            else
            {
                return(Redirect("/"));
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Check if LinkedIn token is expired
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool IsLinkedInTokenExpired(SocialMediaAuthorizeModel model)
        {
            try
            {
                var linkedInHelper = new LinkedInHelper(model.AccessToken);

                var userInfo = linkedInHelper.GetCurrentUser();
            }
            catch (Exception)
            {
                return(true);
            }

            return(false);
        }
 /// <summary>
 /// Begins authorization process and redirects client to the LinkedIn authorization page.
 /// </summary>
 private void BeginAuthorization()
 {
     try
     {
         // Store token manager in the session
         TokenManager = new TokenManager((string)Parameters["ApiKey"], (string)Parameters["ApiSecret"]);
         LinkedInHelper.BeginAuthorization(TokenManager, URLHelper.AddParameterToUrl(RequestContext.CurrentURL, "tokenManagerKey", TokenManagerStoreKey));
     }
     catch (LinkedInApiUnauthorizedException)
     {
         // The keys in LinkedIn application are not valid
         ShowError(GetString("sm.linkedin.account.msg.unauthorized"));
     }
     catch (Exception ex)
     {
         LogAndShowError("LinkedInCompanyAccessToken", "AUTH_BEGIN", ex);
     }
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Handle sign-in with LinkedIn.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private LinkedInSignInViewModel HandleLinkedInSignIn(LinkedInSignInRequest request)
        {
            var viewModel = new LinkedInSignInViewModel();

            if (SitefinityHelper.IsUserLoggedIn())
            {
                return(viewModel);
            }

            if (!LinkedInHelper.IsValidState(request.State))
            {
                viewModel.Error = "The response from LinkedIn is in invalid state. Please go back and try again.";

                return(viewModel);
            }

            var redirectUrl = LinkedInHelper.CreateSignInRedirectUrl(request.Redirect, request.Data);

            try
            {
                var accessTokenResponse = LinkedInHelper.GetAccessTokenFromAuthorisationCode(request.Code, redirectUrl);

                if (string.IsNullOrEmpty(accessTokenResponse.Error))
                {
                    if (!CreateUserFromLinkedInProfileData(accessTokenResponse.AccessToken))
                    {
                        viewModel.Error = "There was some problem while sign-in. Please go back and try again.";
                    }
                }
                else
                {
                    viewModel.Error = accessTokenResponse.Error;
                }
            }
            catch (Exception err)
            {
                viewModel.Error = "There was some problem during authentication with LinkedIn. Please go back and try again.";

                Log.Write(err);
            }

            return(viewModel);
        }
Ejemplo n.º 16
0
        public void GetData(object UserId)
        {
            Guid userId = (Guid)UserId;

            LinkedInHelper            objliHelper = new LinkedInHelper();
            LinkedInAccountRepository objLiRepo   = new LinkedInAccountRepository();
            oAuthLinkedIn             _oauth      = new oAuthLinkedIn();
            ArrayList arrLiAccount = objLiRepo.getAllLinkedinAccountsOfUser(userId);

            foreach (LinkedInAccount itemLi in arrLiAccount)
            {
                _oauth.Token       = itemLi.OAuthToken;
                _oauth.TokenSecret = itemLi.OAuthSecret;
                _oauth.Verifier    = itemLi.OAuthVerifier;
                objliHelper.GetUserProfile(_oauth, itemLi.LinkedinUserId, userId);

                objliHelper.GetLinkedInFeeds(_oauth, itemLi.LinkedinUserId, userId);
            }
        }
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (StopProcessing)
        {
            // Do not process
        }
        else
        {
            // Build plugin code
            string src    = "http://platform.linkedin.com/in.js";
            string apiKey = LinkedInHelper.GetLinkedInApiKey(CMSContext.CurrentSiteName);

            if (string.IsNullOrEmpty(UrlToShare))
            {
                UrlToShare = URLHelper.GetAbsoluteUrl(URLHelper.CurrentURL);
            }

            string output = "<div style=\"overflow: hidden; width: {0}px;\"><script src=\"{1}\" type=\"text/javascript\">api_key: {4}</script><script type=\"IN/Share\" data-url=\"{2}\" data-counter=\"{3}\"></script></div>";
            ltlButtonCode.Text = String.Format(output, Width.ToString(), src, UrlToShare, CountBox, apiKey);
        }
    }
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (StopProcessing)
        {
            // Do not process
        }
        else
        {
            // Initialize variables
            string src = "http://platform.linkedin.com/in.js";
            string dataFormat = null, dataText = null;
            string apiKey = LinkedInHelper.GetLinkedInApiKey(CMSContext.CurrentSiteName);

            // Check optional parameters
            if (DisplayMode.EqualsCSafe("inline"))
            {
                dataFormat = DisplayMode;
            }
            else
            {
                dataFormat = Behavior;
            }

            if (DisplayMode.EqualsCSafe("iconname"))
            {
                dataText = " data-text=\"" + CompanyName + "\"";
            }
            else
            {
                dataText = String.Empty;
            }

            // Build plugin code
            string output = "<div style=\"overflow: hidden; width: {0}px;\"><script src=\"{1}\" type=\"text/javascript\">api_key: {6}</script><script type=\"IN/CompanyProfile\" data-id=\"{2}\" data-format=\"{3}\" data-related=\"{4}\"{5}></script></div>";
            ltlPluginCode.Text = String.Format(output, Width.ToString(), src, CompanyID, dataFormat, ShowConnections.ToString().ToLowerCSafe(), dataText, apiKey);
        }
    }
Ejemplo n.º 19
0
        /// <summary>
        /// Get LinkedIn account info
        /// </summary>
        /// <param name="model"></param>
        /// <param name="callbackUrl"></param>
        /// <returns></returns>
        public static SocialMediaResponseModel GetLinkedInAccountInfo(SocialMediaResponseModel model, string callbackUrl)
        {
            model.Verifier = HttpContext.Current.Request["code"];

            DateTime expiredDate;

            // Get access token and expired date
            model.AccessToken = LinkedInHelper.GetAccessToken(model.AppId, model.AppSecret, model.Verifier, callbackUrl, out expiredDate);

            model.ExpiredDate = expiredDate;

            #region Get User Profile

            var linkedLinkHelper = new LinkedInHelper(model.AccessToken);

            var userInfo = linkedLinkHelper.GetCurrentUser();

            model.FullName = StringUtilities.GenerateFullName(userInfo.FirstName, userInfo.LastName);
            model.Email    = userInfo.Email;

            #endregion

            return(model);
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Get linked in authorize url
 /// </summary>
 /// <param name="clientId"></param>
 /// <param name="callbackUrl"></param>
 /// <returns></returns>
 public static string GetLinkedInAuthorizeUrl(string clientId, string callbackUrl)
 {
     return(LinkedInHelper.GetLinkedInAuthorizeUrl(clientId, callbackUrl));
 }
Ejemplo n.º 21
0
    /// <summary>
    /// Checks status of current user.
    /// </summary>
    protected void CheckStatus()
    {
        // Get current site name
        string siteName = SiteContext.CurrentSiteName;
        string error    = null;

        // Check return URL
        string returnUrl = QueryHelper.GetString("returnurl", null);

        returnUrl = HttpUtility.UrlDecode(returnUrl);

        // Get current URL
        string currentUrl = LinkedInHelper.GetPurifiedUrl().ToString();

        // Get LinkedIn response status
        switch (linkedInHelper.CheckStatus(RequireFirstName, RequireLastName, RequireBirthDate, out mLinkedInProfile))
        {
        // User is authenticated
        case LinkedInHelper.RESPONSE_AUTHENTICATED:
            // LinkedIn profile Id not found  = save new user
            if (UserInfoProvider.GetUserInfoByLinkedInID(mLinkedInProfile.Id) == null)
            {
                string additionalInfoPage = SettingsKeyInfoProvider.GetValue(siteName + ".CMSRequiredLinkedInPage").Trim();

                // No page set, user can be created
                if (String.IsNullOrEmpty(additionalInfoPage))
                {
                    // Register new user
                    UserInfo ui = AuthenticationHelper.AuthenticateLinkedInUser(mLinkedInProfile.Id, mLinkedInProfile.LocalizedFirstName, mLinkedInProfile.LocalizedLastName, siteName, true, true, ref error);

                    // If user was successfully created
                    if (ui != null)
                    {
                        var birthDate = mLinkedInProfile.BirthDate?.ToDateTime();
                        if (birthDate != null && birthDate.Value != DateTimeHelper.ZERO_TIME)
                        {
                            ui.UserSettings.UserDateOfBirth = birthDate.Value;
                        }

                        UserInfoProvider.SetUserInfo(ui);

                        // If user is enabled
                        if (ui.Enabled)
                        {
                            // Create authentication cookie
                            AuthenticationHelper.SetAuthCookieWithUserData(ui.UserName, true, Session.Timeout, new[] { "linkedinlogin" });

                            MembershipActivityLogger.LogLogin(ui.UserName, DocumentContext.CurrentDocument);
                        }

                        // Notify administrator
                        if (NotifyAdministrator && !String.IsNullOrEmpty(FromAddress) && !String.IsNullOrEmpty(ToAddress))
                        {
                            AuthenticationHelper.NotifyAdministrator(ui, FromAddress, ToAddress);
                        }

                        // Log user registration into the web analytics and track conversion if set
                        AnalyticsHelper.TrackUserRegistration(siteName, ui, TrackConversionName, ConversionValue);

                        MembershipActivityLogger.LogRegistration(ui.UserName, DocumentContext.CurrentDocument);
                    }

                    // Redirect when authentication was successful
                    if (String.IsNullOrEmpty(error))
                    {
                        if (URLHelper.IsLocalUrl(returnUrl))
                        {
                            URLHelper.Redirect(returnUrl);
                        }
                        else
                        {
                            URLHelper.Redirect(currentUrl);
                        }
                    }
                    // Display error otherwise
                    else
                    {
                        lblError.Text    = error;
                        lblError.Visible = true;
                    }
                }
                // Additional information page is set
                else
                {
                    // Store LinkedIn profile in session for additional use
                    if (mLinkedInProfile != null)
                    {
                        SessionHelper.SetValue(SESSION_NAME_USERDATA, mLinkedInProfile);
                    }

                    // Redirect to additional info page
                    string targetURL = URLHelper.GetAbsoluteUrl(additionalInfoPage);

                    if (URLHelper.IsLocalUrl(returnUrl))
                    {
                        // Add return URL to parameter
                        targetURL = URLHelper.AddParameterToUrl(targetURL, "returnurl", HttpUtility.UrlEncode(returnUrl));
                    }
                    URLHelper.Redirect(UrlResolver.ResolveUrl(targetURL));
                }
            }
            // LinkedIn profile id is in DB
            else
            {
                // Login existing user
                UserInfo ui = AuthenticationHelper.AuthenticateLinkedInUser(mLinkedInProfile.Id, mLinkedInProfile.LocalizedFirstName, mLinkedInProfile.LocalizedLastName, siteName, false, true, ref error);

                if ((ui != null) && (ui.Enabled))
                {
                    // Create authentication cookie
                    AuthenticationHelper.SetAuthCookieWithUserData(ui.UserName, true, Session.Timeout, new[] { "linkedinlogin" });

                    MembershipActivityLogger.LogLogin(ui.UserName, DocumentContext.CurrentDocument);

                    // Redirect user
                    if (URLHelper.IsLocalUrl(returnUrl))
                    {
                        URLHelper.Redirect(UrlResolver.ResolveUrl(URLHelper.GetAbsoluteUrl(returnUrl)));
                    }
                    else
                    {
                        URLHelper.Redirect(currentUrl);
                    }
                }
                // Display error which occurred during authentication process
                else if (!String.IsNullOrEmpty(error))
                {
                    lblError.Text    = error;
                    lblError.Visible = true;
                }
                // Otherwise is user disabled
                else
                {
                    lblError.Text    = GetString("membership.userdisabled");
                    lblError.Visible = true;
                }
            }
            break;

        // No authentication, do nothing
        case LinkedInHelper.RESPONSE_NOTAUTHENTICATED:
            break;
        }
    }
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (!this.StopProcessing)
        {
            // Check renamed DLL library
            if (CMSOpenIDHelper.CheckOpenIdDLL())
            {
                // Check if LinkedIn module is enabled
                if (LinkedInHelper.LinkedInIsAvailable(CMSContext.CurrentSiteName))
                {
                    DisplayButtons();
                    linkedInHelper = new LinkedInHelper();
                    CheckStatus();
                }
                else
                {
                    // Error label is displayed in Design mode when LinkedIn is disabled
                    if (CMSContext.ViewMode == ViewModeEnum.Design)
                    {
                        StringBuilder parameter = new StringBuilder();
                        parameter.Append(GetString("header.sitemanager") + " -> ");
                        parameter.Append(GetString("settingscategory.cmssettings") + " -> ");
                        parameter.Append(GetString("settingscategory.cmsmembership") + " -> ");
                        parameter.Append(GetString("settingscategory.cmsmembershipauthentication") + " -> ");
                        parameter.Append(GetString("settingscategory.cmslinkedin"));
                        if (CMSContext.CurrentUser.UserSiteManagerAdmin)
                        {
                            // Make it link for SiteManager Admin
                            parameter.Insert(0, "<a href=\"" + URLHelper.GetAbsoluteUrl("~/CMSSiteManager/default.aspx?section=settings") + "\" target=\"_top\">");
                            parameter.Append("</a>");
                        }

                        lblError.Text = String.Format(GetString("mem.linkedin.disabled"), parameter.ToString());
                        lblError.Visible = true;
                    }
                    else
                    {
                        this.Visible = false;
                    }
                }
            }
            // Error label is displayed in Design mode when LinkedIn library is not loaded
            else
            {
                lblError.ResourceString = "mem.openid.library";
                lblError.Visible = true;
            }
        }
        else
        {
            this.Visible = false;
        }
    }
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (!StopProcessing)
        {
            plcError.Visible = false;

            // Check renamed DLL library
            if (!SystemContext.IsFullTrustLevel)
            {
                // Error label is displayed when OpenID library is not enabled
                lblError.ResourceString = "socialnetworking.fulltrustrequired";
                plcError.Visible = true;
                plcContent.Visible = false;
            }

            // Check if LinkedIn module is enabled
            if (!LinkedInHelper.LinkedInIsAvailable(SiteContext.CurrentSiteName) && !plcError.Visible)
            {
                // Error label is displayed only in Design mode
                if (PortalContext.IsDesignMode(PortalContext.ViewMode))
                {
                    StringBuilder parameter = new StringBuilder();
                    parameter.Append(UIElementInfoProvider.GetApplicationNavigationString("cms", "Settings") + " -> ");
                    parameter.Append(GetString("settingscategory.socialmedia") + " -> ");
                    parameter.Append(GetString("settingscategory.cmslinkedin"));
                    if (MembershipContext.AuthenticatedUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.GlobalAdmin))
                    {
                        // Make it link for Admin
                        parameter.Insert(0, "<a href=\"" + URLHelper.GetAbsoluteUrl(UIContextHelper.GetApplicationUrl("cms", "settings")) + "\" target=\"_top\">");
                        parameter.Append("</a>");
                    }

                    lblError.Text = String.Format(GetString("mem.linkedin.disabled"), parameter);
                    plcError.Visible = true;
                    plcContent.Visible = false;
                }
                // In other modes is web part hidden
                else
                {
                    Visible = false;
                }
            }

            // Display web part when no error occurred
            if (!plcError.Visible && Visible)
            {
                // Hide web part if user is authenticated
                if (AuthenticationHelper.IsAuthenticated())
                {
                    Visible = false;
                    return;
                }

                plcPasswordNew.Visible = AllowFormsAuthentication;
                pnlExistingUser.Visible = AllowExistingUser;

                // Load LinkedIn data from session
                linkedInHelper = new LinkedInHelper();
                string linkedInData = ValidationHelper.GetString(SessionHelper.GetValue(SESSION_NAME_USERDATA), string.Empty);
                if (!string.IsNullOrEmpty(linkedInData))
                {
                    var doc = new XmlDocument();
                    doc.LoadXml(linkedInData);
                    linkedInHelper.Initialize(doc);
                }

                // There is no LinkedIn user ID stored in session - hide all
                if (string.IsNullOrEmpty(linkedInHelper.MemberId) && HideForNoLinkedInUserID)
                {
                    Visible = false;
                }
                else if (!RequestHelper.IsPostBack())
                {
                    LoadData();
                }
            }
        }
        else
        {
            Visible = false;
        }
    }
Ejemplo n.º 24
0
        public void GetAccessToken()
        {
            LinkedInProfile objProfile = new LinkedInProfile();

            LinkedInProfile.UserProfile objUserProfile = new LinkedInProfile.UserProfile();
            LinkedInHelper liHelper       = new LinkedInHelper();
            User           user           = (User)Session["LoggedUser"];
            string         oauth_token    = Request.QueryString["oauth_token"];
            string         oauth_verifier = Request.QueryString["oauth_verifier"];

            try
            {
                if (oauth_token != null && oauth_verifier != null)
                {
                    try
                    {
                        _oauth.Token = oauth_token;
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                    }
                    try
                    {
                        _oauth.TokenSecret = Session["reuqestTokenSecret"].ToString();
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                    }
                    try
                    {
                        _oauth.Verifier = oauth_verifier;
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                    }
                    try
                    {
                        _oauth.AccessTokenGet(oauth_token);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                    }

                    // Update Access Token in DB
                    try
                    {
                        int res = UpdateLDToken(user.Id.ToString(), _oauth.Token);
                    }
                    catch { };
                    //***********************

                    Session.Remove("oauth_token");
                    Session.Remove("oauth_TokenSecret");

                    try
                    {
                        objUserProfile = objProfile.GetUserProfile(_oauth);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                    }
                    try
                    {
                        liHelper.GetLinkedInUserProfile(objUserProfile, _oauth, user);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                    }
                    try
                    {
                        // liHelper.getLinkedInNetworkUpdate(_oauth,user);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                    }
                    Session["LinkedInUser"] = _oauth;
                    Session["datatable"]    = null;
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.StackTrace);
            }
        }
Ejemplo n.º 25
0
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (!StopProcessing)
        {
            plcError.Visible = false;

            // Check if LinkedIn module is enabled
            if (!LinkedInHelper.LinkedInIsAvailable(SiteContext.CurrentSiteName) && !plcError.Visible)
            {
                // Error label is displayed only in Design mode
                if (PortalContext.IsDesignMode(PortalContext.ViewMode))
                {
                    StringBuilder parameter = new StringBuilder();
                    parameter.Append(UIElementInfoProvider.GetApplicationNavigationString("cms", "Settings") + " -> ");
                    parameter.Append(GetString("settingscategory.cmsmembership") + " -> ");
                    parameter.Append(GetString("settingscategory.cmsmembershipauthentication") + " -> ");
                    parameter.Append(GetString("settingscategory.cmslinkedin"));
                    if (MembershipContext.AuthenticatedUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.GlobalAdmin))
                    {
                        // Make it link for Admin
                        parameter.Insert(0, "<a href=\"" + URLHelper.GetAbsoluteUrl(ApplicationUrlHelper.GetApplicationUrl("cms", "settings")) + "\" target=\"_top\">");
                        parameter.Append("</a>");
                    }

                    lblError.Text      = String.Format(GetString("mem.linkedin.disabled"), parameter);
                    plcError.Visible   = true;
                    plcContent.Visible = false;
                }
                // In other modes is web part hidden
                else
                {
                    Visible = false;
                }
            }

            // Display web part when no error occurred
            if (!plcError.Visible && Visible)
            {
                // Hide web part if user is authenticated
                if (AuthenticationHelper.IsAuthenticated())
                {
                    Visible = false;
                    return;
                }

                plcPasswordNew.Visible  = AllowFormsAuthentication;
                pnlExistingUser.Visible = AllowExistingUser;

                SetLinkedInProfileFromSession();

                // There is no LinkedIn profile stored in session - hide all
                if (mLinkedInProfile == null && HideForNoLinkedInUserID)
                {
                    Visible = false;
                }
                else if (!RequestHelper.IsPostBack())
                {
                    LoadData();
                }
            }
        }
        else
        {
            Visible = false;
        }
    }
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (StopProcessing)
        {
            // Do not process
        }
        else
        {
            // Initialize variables
            string dataJobLocation = String.Empty, dataLogo = String.Empty, dataThemeColor = String.Empty, dataButtonSize = String.Empty, dataQuestions = String.Empty;
            string src       = "http://platform.linkedin.com/in.js";
            string apiKey    = LinkedInHelper.GetLinkedInApiKey(CMSContext.CurrentSiteName);
            string apiSecret = LinkedInHelper.GetLinkedInSecretKey(CMSContext.CurrentSiteName);

            // Check settings
            if (!String.IsNullOrEmpty(apiKey) && !String.IsNullOrEmpty(apiSecret))
            {
                // Check if optional parameters are set and transform them accordingly
                if (!string.IsNullOrEmpty(CompanyLogo))
                {
                    dataLogo = "data-logo=\"" + URLHelper.GetAbsoluteUrl(CompanyLogo) + "\"";
                }

                if (!string.IsNullOrEmpty(JobLocation))
                {
                    dataJobLocation = "data-joblocation=\"" + JobLocation + "\"";
                }

                if (!string.IsNullOrEmpty(ThemeColor))
                {
                    dataThemeColor = "data-themecolor=\"" + ThemeColor + "\"";
                }

                if (ButtonSize.EqualsCSafe("medium"))
                {
                    dataButtonSize = "data-size=\"medium\"";
                }

                // Parse questions string and format it
                if (!string.IsNullOrEmpty(Questions))
                {
                    dataQuestions = "data-questions='[";
                    string[] questionArray = Questions.Split(new string[1] {
                        Environment.NewLine
                    }, StringSplitOptions.None);
                    foreach (string s in questionArray)
                    {
                        dataQuestions += "{\"question\": \"" + s + "\"},";
                    }
                    dataQuestions  = dataQuestions.TrimEnd(',');
                    dataQuestions += "]'";
                }

                // Build plugin code
                string output = "<div style=\"overflow: hidden; width: {0}px;\"><script src=\"{1}\" type=\"text/javascript\">api_key: {2}</script><script type=\"IN/Apply\" data-companyid=\"{3}\" data-jobtitle=\"{4}\" data-email=\"{5}\" {6} data-phone=\"{7}\" data-coverletter=\"{8}\" {9} data-showtext=\"{10}\" {11} {12} {13}></script></div>";
                ltlPluginCode.Text = String.Format(output, Width, src, apiKey, CompanyID, JobTitle, DeliveryEmail, dataJobLocation, RequestPhone, RequestCoverLetter, dataLogo, ShowHelpText.ToString().ToLowerCSafe(), dataThemeColor, dataButtonSize, dataQuestions);
            }
            else
            {
                if (CMSContext.ViewMode == ViewModeEnum.Design)
                {
                    string pathToSettings = SocialNetworkingHelper.GetPathToLinkedInSettings();

                    ltlPluginCode.Text = "<span class='ErrorLabel'>" + String.Format(ResHelper.GetString("socialnetworking.linkedin.settingsrequired"), pathToSettings) + "</span>";
                }

                // Log event
                EventLogProvider.LogException("SocialNetworking", "LinkedInApplyWith", new Exception("Missing LinkedIn settings."));
            }
        }
    }
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (!StopProcessing)
        {
            plcError.Visible = false;

            // Check renamed DLL library
            if (!CMSOpenIDHelper.CheckOpenIdDLL())
            {
                // Error label is displayed when OpenID library is not enabled
                lblError.ResourceString = "mem.openid.library";
                plcError.Visible        = true;
                plcContent.Visible      = false;
            }

            string currentSiteName = CMSContext.CurrentSiteName;

            // Check if LinkedIn module is enabled
            if (!LinkedInHelper.LinkedInIsAvailable(CMSContext.CurrentSiteName) && !plcError.Visible)
            {
                // Error label is displayed only in Design mode
                if (CMSContext.ViewMode == ViewModeEnum.Design)
                {
                    StringBuilder parameter = new StringBuilder();
                    parameter.Append(GetString("header.sitemanager") + " -> ");
                    parameter.Append(GetString("settingscategory.cmssettings") + " -> ");
                    parameter.Append(GetString("settingscategory.socialnetworks") + " -> ");
                    parameter.Append(GetString("settingscategory.cmslinkedin"));
                    if (CMSContext.CurrentUser.UserSiteManagerAdmin)
                    {
                        // Make it link for SiteManager Admin
                        parameter.Insert(0, "<a href=\"" + URLHelper.GetAbsoluteUrl("~/CMSSiteManager/default.aspx?section=settings") + "\" target=\"_top\">");
                        parameter.Append("</a>");
                    }

                    lblError.Text      = String.Format(GetString("mem.linkedin.disabled"), parameter.ToString());
                    plcError.Visible   = true;
                    plcContent.Visible = false;
                }
                // In other modes is webpart hidden
                else
                {
                    Visible = false;
                }
            }

            // Display webpart when no error occured
            if (!plcError.Visible && Visible)
            {
                // Hide webpart if user is authenticated
                if (CMSContext.CurrentUser.IsAuthenticated())
                {
                    Visible = false;
                    return;
                }

                plcPasswordNew.Visible  = AllowFormsAuthentication;
                pnlExistingUser.Visible = AllowExistingUser;

                linkedInHelper = new LinkedInHelper();
                linkedInHelper.Initialize(SessionHelper.GetValue(SESSION_NAME_USERDATA) as XmlDocument);

                // There is no LinkedIn user ID stored in session - hide all
                if (string.IsNullOrEmpty(linkedInHelper.MemberId) && HideForNoLinkedInUserID)
                {
                    Visible = false;
                }
                else if (!RequestHelper.IsPostBack())
                {
                    LoadData();
                }
            }
        }
        else
        {
            Visible = false;
        }
    }
Ejemplo n.º 28
0
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (!StopProcessing)
        {
            if (SystemContext.IsFullTrustLevel)
            {
                if (!LicenseHelper.CheckFeature(RequestContext.CurrentDomain, FeatureEnum.LinkedIn))
                {
                    Visible = DisplayMessage(String.Format(GetString("licenselimitation.featurenotavailable"), FeatureEnum.LinkedIn));
                    return;
                }

                // Check if LinkedIn module is enabled
                if (!LinkedInHelper.LinkedInIsAvailable(SiteContext.CurrentSiteName))
                {
                    Visible = DisplayMessage();
                    return;
                }

                DisplayButtons();
                linkedInHelper = new LinkedInHelper();
                CheckStatus();
            }
            // Error label is displayed in Design mode when LinkedIn library is not loaded
            else
            {
                lblError.ResourceString = "socialnetworking.fulltrustrequired";
                lblError.Visible = true;
            }
        }
        else
        {
            Visible = false;
        }
    }
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (!this.StopProcessing)
        {
            plcError.Visible = false;

            // Check renamed DLL library
            if (!CMSOpenIDHelper.CheckOpenIdDLL())
            {
                // Error label is displayed when OpenID library is not enabled
                lblError.ResourceString = "mem.openid.library";
                plcError.Visible = true;
                plcContent.Visible = false;
            }

            string currentSiteName = CMSContext.CurrentSiteName;

            // Check if LinkedIn module is enabled
            if (!LinkedInHelper.LinkedInIsAvailable(CMSContext.CurrentSiteName) && !this.plcError.Visible)
            {
                // Error label is displayed only in Design mode
                if (CMSContext.ViewMode == ViewModeEnum.Design)
                {
                    StringBuilder parameter = new StringBuilder();
                    parameter.Append(GetString("header.sitemanager") + " -> ");
                    parameter.Append(GetString("settingscategory.cmssettings") + " -> ");
                    parameter.Append(GetString("settingscategory.cmsmembership") + " -> ");
                    parameter.Append(GetString("settingscategory.cmsmembershipauthentication") + " -> ");
                    parameter.Append(GetString("settingscategory.cmslinkedin"));
                    if (CMSContext.CurrentUser.UserSiteManagerAdmin)
                    {
                        // Make it link for SiteManager Admin
                        parameter.Insert(0, "<a href=\"" + URLHelper.GetAbsoluteUrl("~/CMSSiteManager/default.aspx?section=settings") + "\" target=\"_top\">");
                        parameter.Append("</a>");
                    }

                    lblError.Text = String.Format(GetString("mem.linkedin.disabled"), parameter.ToString());
                    plcError.Visible = true;
                    plcContent.Visible = false;
                }
                // In other modes is webpart hidden
                else
                {
                    this.Visible = false;
                }
            }

            // Display webpart when no error occured
            if (!plcError.Visible && this.Visible)
            {
                // Hide webpart if user is authenticated
                if (CMSContext.CurrentUser.IsAuthenticated())
                {
                    this.Visible = false;
                    return;
                }

                plcPasswordNew.Visible = this.AllowFormsAuthentication;
                pnlExistingUser.Visible = this.AllowExistingUser;

                linkedInHelper = new LinkedInHelper();
                linkedInHelper.Initialize(SessionHelper.GetValue(SESSION_NAME_USERDATA) as XmlDocument);

                // There is no LinkedIn user ID stored in session - hide all
                if (string.IsNullOrEmpty(linkedInHelper.MemberId) && HideForNoLinkedInUserID)
                {
                    this.Visible = false;
                }
                else if (!RequestHelper.IsPostBack())
                {
                    LoadData();
                }
            }
        }
        else
        {
            this.Visible = false;
        }
    }
Ejemplo n.º 30
0
        /// <summary>
        /// Post status to Twitter
        /// </summary>
        /// <param name="model"></param>
        /// <param name="message"></param>
        public static object PostLinkedInStatus(SocialMediaAuthorizeModel model, SocialMessageModel message)
        {
            var linkedInHelper = new LinkedInHelper(model.AccessToken);

            return(linkedInHelper.PostStatus(message));
        }
Ejemplo n.º 31
0
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (!StopProcessing)
        {
            plcError.Visible = false;

            // Check renamed DLL library
            if (!SystemContext.IsFullTrustLevel)
            {
                // Error label is displayed when OpenID library is not enabled
                lblError.ResourceString = "socialnetworking.fulltrustrequired";
                plcError.Visible        = true;
                plcContent.Visible      = false;
            }

            // Check if LinkedIn module is enabled
            if (!LinkedInHelper.LinkedInIsAvailable(SiteContext.CurrentSiteName) && !plcError.Visible)
            {
                // Error label is displayed only in Design mode
                if (PortalContext.IsDesignMode(PortalContext.ViewMode))
                {
                    StringBuilder parameter = new StringBuilder();
                    parameter.Append(UIElementInfoProvider.GetApplicationNavigationString("cms", "Settings") + " -> ");
                    parameter.Append(GetString("settingscategory.cmsmembership") + " -> ");
                    parameter.Append(GetString("settingscategory.cmsmembershipauthentication") + " -> ");
                    parameter.Append(GetString("settingscategory.cmslinkedin"));
                    if (MembershipContext.AuthenticatedUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.GlobalAdmin))
                    {
                        // Make it link for Admin
                        parameter.Insert(0, "<a href=\"" + URLHelper.GetAbsoluteUrl(UIContextHelper.GetApplicationUrl("cms", "settings")) + "\" target=\"_top\">");
                        parameter.Append("</a>");
                    }

                    lblError.Text      = String.Format(GetString("mem.linkedin.disabled"), parameter);
                    plcError.Visible   = true;
                    plcContent.Visible = false;
                }
                // In other modes is web part hidden
                else
                {
                    Visible = false;
                }
            }

            // Display web part when no error occurred
            if (!plcError.Visible && Visible)
            {
                // Hide web part if user is authenticated
                if (AuthenticationHelper.IsAuthenticated())
                {
                    Visible = false;
                    return;
                }

                plcPasswordNew.Visible  = AllowFormsAuthentication;
                pnlExistingUser.Visible = AllowExistingUser;

                // Load LinkedIn data from session
                linkedInHelper = new LinkedInHelper();
                string linkedInData = ValidationHelper.GetString(SessionHelper.GetValue(SESSION_NAME_USERDATA), string.Empty);
                if (!string.IsNullOrEmpty(linkedInData))
                {
                    var doc = new XmlDocument();
                    doc.LoadXml(linkedInData);
                    linkedInHelper.Initialize(doc);
                }

                // There is no LinkedIn user ID stored in session - hide all
                if (string.IsNullOrEmpty(linkedInHelper.MemberId) && HideForNoLinkedInUserID)
                {
                    Visible = false;
                }
                else if (!RequestHelper.IsPostBack())
                {
                    LoadData();
                }
            }
        }
        else
        {
            Visible = false;
        }
    }