Пример #1
0
    /// <summary>
    /// Handles btnOkExist click, joins existing user with LinkedIn member id.
    /// </summary>
    protected void btnOkExist_Click(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(mLinkedInProfile?.Id))
        {
            if (!String.IsNullOrEmpty(txtUserName.Text))
            {
                // Try to authenticate user
                UserInfo ui = AuthenticationHelper.AuthenticateUser(txtUserName.Text, txtPassword.Text, SiteContext.CurrentSiteName);

                // Check banned IPs
                BannedIPInfoProvider.CheckIPandRedirect(SiteContext.CurrentSiteName, BanControlEnum.Login);

                if (ui != null)
                {
                    // Add LinkedIn profile member id to user
                    ui.UserSettings.UserLinkedInID = mLinkedInProfile.Id;
                    UserInfoProvider.SetUserInfo(ui);

                    // Set authentication cookie and redirect to page
                    SetAuthCookieAndRedirect(ui);
                }
                else // Invalid credentials
                {
                    lblError.Text    = GetString("Login_FailureText");
                    plcError.Visible = true;
                }
            }
            else // User did not fill the form
            {
                lblError.Text    = GetString("mem.linkedin.fillloginform");
                plcError.Visible = true;
            }
        }
    }
Пример #2
0
    /// <summary>
    /// Handles btnOkExist click, joins existing user with liveid token.
    /// </summary>
    protected void btnOkExist_Click(object sender, EventArgs e)
    {
        // Live user must be retrieved from session
        if (!String.IsNullOrEmpty(facebookUserId))
        {
            if (!String.IsNullOrEmpty(txtUserName.Text))
            {
                // Try to authenticate user
                UserInfo ui = UserInfoProvider.AuthenticateUser(txtUserName.Text, txtPassword.Text, CMSContext.CurrentSiteName);

                // Check banned IPs
                BannedIPInfoProvider.CheckIPandRedirect(CMSContext.CurrentSiteName, BanControlEnum.Login);

                if (ui != null)
                {
                    // Add Facebook Connect user ID token to user
                    ui.UserSettings.UserFacebookID = facebookUserId;
                    UserInfoProvider.SetUserInfo(ui);

                    // Set authentication cookie and redirect to page
                    SetAuthCookieAndRedirect(ui);
                }
                else // Invalid credentials
                {
                    lblError.Text    = GetString("Login_FailureText");
                    plcError.Visible = true;
                }
            }
            else // User did not fill the form
            {
                lblError.Text    = GetString("mem.facebook.fillloginform");
                plcError.Visible = true;
            }
        }
    }
    /// <summary>
    /// Signs in given user.
    /// </summary>
    /// <param name="ui">User that will be signed in.</param>
    /// <param name="facebookUserId">The user's Facebook ID</param>
    /// <param name="facebookAccessToken">The user's access token retrieved from Facebook</param>
    private void SignInUser(UserInfo ui, string facebookUserId, string facebookAccessToken)
    {
        // Login existing user
        if (ui.Enabled)
        {
            MapFacebookUserProfile(FacebookUserProfileMappingTriggerEnum.Login, ui, facebookUserId, facebookAccessToken);

            // Ban IP addresses which are blocked for login
            BannedIPInfoProvider.CheckIPandRedirect(SiteContext.CurrentSiteName, BanControlEnum.Login);

            // Create autentification cookie
            AuthenticationHelper.SetAuthCookieWithUserData(ui.UserName, true, Session.Timeout, new string[] { "facebooklogon" });
            UserInfoProvider.SetPreferredCultures(ui);

            int      contactId = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui);
            Activity activity  = new ActivityUserLogin(contactId, ui, DocumentContext.CurrentDocument, AnalyticsContext.ActivityEnvironmentVariables);
            activity.Log();

            // Redirect user
            string returnUrl = QueryHelper.GetString("returnurl", null);
            if (String.IsNullOrEmpty(returnUrl))
            {
                returnUrl = URLHelper.RemoveParameterFromUrl(RequestContext.CurrentURL, CONFIRMATION_URLPARAMETER);
            }
            URLHelper.Redirect(returnUrl);
        }
        else
        {
            // User is disabled
            lblError.Text    = GetString("membership.userdisabled");
            lblError.Visible = true;
        }
    }
Пример #4
0
    /// <summary>
    /// Handles btnOkExist click, joins existing user with OpenID.
    /// </summary>
    protected void btnOkExist_Click(object sender, EventArgs e)
    {
        // OpenID response object must be retrieved from session
        if (response != null)
        {
            if (txtUserName.Text != String.Empty)
            {
                // Try to authenticate user
                UserInfo ui = AuthenticationHelper.AuthenticateUser(txtUserName.Text, txtPassword.Text, CMSContext.CurrentSiteName);

                // Check banned IPs
                BannedIPInfoProvider.CheckIPandRedirect(CMSContext.CurrentSiteName, BanControlEnum.Login);

                if (ui != null)
                {
                    // Check if user is not already registered with different OpenID provider
                    string openID = OpenIDUserInfoProvider.GetOpenIDByUserID(ui.UserID);
                    if (String.IsNullOrEmpty(openID))
                    {
                        // Add OpenID token to user
                        OpenIDUserInfoProvider.AddOpenIDToUser((string)response["ClaimedIdentifier"], userProviderUrl, ui.UserID);

                        // Remove user info from session
                        SessionHelper.Remove(SESSION_NAME_USERDATA);
                        SessionHelper.Remove(SESSION_NAME_URL);

                        // Set authentication cookie and redirect to page
                        SetAuthCookieAndRedirect(ui);
                    }
                    // User is already registered under different OpenID provider
                    else
                    {
                        lblError.Text    = GetString("mem.openid.alreadyregistered");
                        plcError.Visible = true;
                    }
                }
                else // Invalid credentials
                {
                    lblError.Text    = GetString("Login_FailureText");
                    plcError.Visible = true;
                }
            }
            else // User did not fill the form
            {
                lblError.Text    = GetString("mem.openid.fillloginform");
                plcError.Visible = true;
            }
        }
    }
Пример #5
0
    /// <summary>
    /// Handles btnOkExist click, joins existing user with liveid token.
    /// </summary>
    protected void btnOkExist_Click(object sender, EventArgs e)
    {
        // Live user must be retrieved from session
        if (liveUser != null)
        {
            if (txtUserName.Text != String.Empty)// && (txtPassword.Text != String.Empty))
            {
                // Try to authenticate user
                UserInfo ui = UserInfoProvider.AuthenticateUser(txtUserName.Text, txtPassword.Text, CMSContext.CurrentSiteName);

                // Check banned IPs
                BannedIPInfoProvider.CheckIPandRedirect(CMSContext.CurrentSiteName, BanControlEnum.Login);

                if (ui != null)
                {
                    // Add liveID token to user
                    ui.UserSettings.WindowsLiveID = liveUser.Id;
                    UserInfoProvider.SetUserInfo(ui);

                    // Remove live user object from session, won't be needed
                    Session.Remove("windowsliveloginuser");

                    // Set authentication cookie and redirect to page
                    SetAuthCookieAndRedirect(ui);
                }
                else // Invalid credentials
                {
                    lblError.Text    = GetString("Login_FailureText");
                    plcError.Visible = true;
                }
            }
            else // User did not fill the form
            {
                lblError.Text    = GetString("mem.liveid.fillloginform");
                plcError.Visible = true;
            }
        }
    }
Пример #6
0
    /// <summary>
    /// Signs in given user.
    /// </summary>
    /// <param name="ui">User that will be signed in.</param>
    /// <param name="facebookUserId">The user's Facebook ID</param>
    /// <param name="facebookAccessToken">The user's access token retrieved from Facebook</param>
    /// <param name="mapFacebookProfile">Indicates whether the user's Facebook profile is mapped to user info or not</param>
    private void SignInUser(UserInfo ui, string facebookUserId, string facebookAccessToken, bool mapFacebookProfile = true)
    {
        // Login existing user
        if (ui.Enabled)
        {
            if (mapFacebookProfile)
            {
                MapFacebookUserProfile(FacebookUserProfileMappingTriggerEnum.Login, ui, facebookUserId, facebookAccessToken);
            }

            // Ban IP addresses which are blocked for login
            BannedIPInfoProvider.CheckIPandRedirect(SiteContext.CurrentSiteName, BanControlEnum.Login);

            // Create authentication cookie
            AuthenticationHelper.SetAuthCookieWithUserData(ui.UserName, true, Session.Timeout, new[] { "facebooklogon" });
            UserInfoProvider.SetPreferredCultures(ui);

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

            // Redirect user
            string returnUrl = QueryHelper.GetString("returnurl", null);
            if (URLHelper.IsLocalUrl(returnUrl))
            {
                URLHelper.Redirect(returnUrl);
            }
            else
            {
                string currentUrl = URLHelper.RemoveParameterFromUrl(RequestContext.CurrentURL, CONFIRMATION_URLPARAMETER);
                URLHelper.Redirect(ResolveUrl(currentUrl));
            }
        }
        else
        {
            // User is disabled
            lblError.Text    = GetString("membership.userdisabled");
            lblError.Visible = true;
        }
    }
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (StopProcessing)
        {
            Visible = false;
        }
        else
        {
            if (QueryHelper.GetInteger("logout", 0) > 0)
            {
                // Sign out from CMS
                CMSContext.LogoutUser();

                CMSContext.CurrentUser = null;
                Response.Cache.SetNoStore();
                URLHelper.Redirect(URLHelper.RemoveParameterFromUrl(URLHelper.CurrentURL, "logout"));
                return;
            }

            string currentSiteName = CMSContext.CurrentSiteName;
            if (!String.IsNullOrEmpty(currentSiteName) && SettingsKeyProvider.GetBoolValue(currentSiteName + ".CMSEnableFacebookConnect"))
            {
                // Check Facebook Connect settings
                if (!FacebookConnectHelper.FacebookIsAvailable(currentSiteName))
                {
                    // Display warning message in "Design mode"
                    if (DisplayMessage())
                    {
                        return;
                    }

                    Visible = false;
                    return;
                }

                // Try to retrieve return URL from query
                string returnUrl = QueryHelper.GetString("returnurl", null);

                // Init Facebook Connect
                if (Page is ContentPage)
                {
                    // Adding XML namespace
                    ((ContentPage)Page).XmlNamespace = FacebookConnectHelper.GetFacebookXmlNamespace();
                }

                // Init FB connect
                string initscr = FacebookConnectHelper.GetFacebookInitScriptForSite(currentSiteName) + " " + FacebookConnectHelper.GetFacebookLoginHandlerScript();
                ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "FBConnectLogon" + ClientID, initscr);
                // Return URL
                string currentUrl       = URLHelper.AddParameterToUrl(URLHelper.CurrentURL, "logout", "1");
                string additionalScript = "window.location.href=" + ScriptHelper.GetString(URLHelper.GetAbsoluteUrl(currentUrl)) + "; return false;";
                // Logout script for FB connect
                string logoutScript = FacebookConnectHelper.GetFacebookLogoutScriptForSignOut(URLHelper.CurrentURL, FacebookConnectHelper.GetFacebookApiKey(currentSiteName), additionalScript);

                // Validate FB access token against FB server
                string facebookUserId       = null;
                bool   facebookCookiesValid = false;
                string confirmToken         = QueryHelper.GetString(CONFIRMATION_URLPARAMETER, null);
                if (!String.IsNullOrEmpty(confirmToken))
                {
                    facebookCookiesValid = FacebookConnectHelper.ValidateFBAccessToken(confirmToken, out facebookUserId);
                }

                // If user is already authenticated
                if (CMSContext.CurrentUser.IsAuthenticated())
                {
                    // Is user logged in using Facebook Connect?
                    if ((CMSContext.CurrentUser.UserSettings != null) && String.IsNullOrEmpty(CMSContext.CurrentUser.UserSettings.UserFacebookID))
                    {
                        // no, user is not logged in by Facebook Connect
                        logoutScript = additionalScript;
                    }

                    // Hide Facebook Connect button
                    plcFBButton.Visible = false;

                    // If signout should be visible and user has FacebookID registered
                    if (ShowSignOut && !String.IsNullOrEmpty(CMSContext.CurrentUser.UserSettings.UserFacebookID))
                    {
                        // If only text is set use text/button link
                        if (!String.IsNullOrEmpty(SignOutText))
                        {
                            // Button link
                            if (ShowAsButton)
                            {
                                btnSignOut.OnClientClick = logoutScript;
                                btnSignOut.Text          = SignOutText;
                                btnSignOut.Visible       = true;
                            }
                            // Text link
                            else
                            {
                                lnkSignOutLink.Text    = SignOutText;
                                lnkSignOutLink.Visible = true;
                                lnkSignOutLink.Attributes.Add("onclick", logoutScript);
                                lnkSignOutLink.Attributes.Add("style", "cursor:pointer;");
                            }
                        }
                        // Image link
                        else
                        {
                            string signOutImageUrl = SignOutImageURL;
                            // Use default image if none is specified
                            if (String.IsNullOrEmpty(signOutImageUrl))
                            {
                                signOutImageUrl = GetImageUrl("Others/FacebookConnect/signout.gif");
                            }
                            imgSignOut.ImageUrl        = ResolveUrl(signOutImageUrl);
                            imgSignOut.Visible         = true;
                            imgSignOut.AlternateText   = GetString("webparts_membership_signoutbutton.signout");
                            lnkSignOutImageBtn.Visible = true;
                            lnkSignOutImageBtn.Attributes.Add("onclick", logoutScript);
                            lnkSignOutImageBtn.Attributes.Add("style", "cursor:pointer;");
                        }
                    }
                    else
                    {
                        Visible = false;
                    }
                }
                // Sign In
                else
                {
                    if (facebookCookiesValid)
                    {
                        if (!String.IsNullOrEmpty(facebookUserId))
                        {
                            UserInfo ui = UserInfoProvider.GetUserInfoByFacebookConnectID(facebookUserId);
                            // Claimed Facebook ID is in DB
                            if (ui != null)
                            {
                                // Login existing user
                                if ((ui != null) && ui.Enabled)
                                {
                                    // Ban IP addresses which are blocked for login
                                    BannedIPInfoProvider.CheckIPandRedirect(currentSiteName, BanControlEnum.Login);

                                    // Create autentification cookie
                                    AuthenticationHelper.SetAuthCookieWithUserData(ui.UserName, true, Session.Timeout, new string[] { "facebooklogon" });
                                    UserInfoProvider.SetPreferredCultures(ui);

                                    int      contactId = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui);
                                    Activity activity  = new ActivityUserLogin(contactId, ui, CMSContext.CurrentDocument, CMSContext.ActivityEnvironmentVariables);
                                    activity.Log();

                                    // Redirect user
                                    if (String.IsNullOrEmpty(returnUrl))
                                    {
                                        returnUrl = URLHelper.RemoveParameterFromUrl(URLHelper.CurrentURL, CONFIRMATION_URLPARAMETER);
                                    }

                                    URLHelper.Redirect(returnUrl);
                                }
                                // Otherwise is user disabled
                                else
                                {
                                    lblError.Text    = GetString("membership.userdisabled");
                                    lblError.Visible = true;
                                }
                            }
                            // Claimed Facebook ID not found  = save new user
                            else
                            {
                                // Check whether additional user info page is set
                                string additionalInfoPage = SettingsKeyProvider.GetStringValue(currentSiteName + ".CMSRequiredFacebookPage").Trim();

                                // No page set, user can be created
                                if (String.IsNullOrEmpty(additionalInfoPage))
                                {
                                    // Register new user
                                    string error = null;
                                    ui = AuthenticationHelper.AuthenticateFacebookConnectUser(facebookUserId, currentSiteName, false, true, ref error);

                                    // If user was found or successfuly created
                                    if (ui != null)
                                    {
                                        // If user is enabled
                                        if (ui.Enabled)
                                        {
                                            // Create authentification cookie
                                            AuthenticationHelper.SetAuthCookieWithUserData(ui.UserName, true, Session.Timeout, new string[] { "facebooklogon" });

                                            int      contactID     = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui);
                                            Activity activityLogin = new ActivityUserLogin(contactID, ui, CMSContext.CurrentDocument, CMSContext.ActivityEnvironmentVariables);
                                            activityLogin.Log();
                                        }

                                        // Send registration e-mails
                                        // E-mail confirmation is not required as user already provided confirmation by successful login using Facebook connect
                                        AuthenticationHelper.SendRegistrationEmails(ui, null, null, false, false);

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

                                        // Log registration into analytics
                                        AuthenticationHelper.TrackUserRegistration(TrackConversionName, ConversionValue, currentSiteName, ui);

                                        Activity activity = new ActivityRegistration(ui, CMSContext.CurrentDocument, CMSContext.ActivityEnvironmentVariables);
                                        if (activity.Data != null)
                                        {
                                            activity.Data.ContactID = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui);
                                            activity.Log();
                                        }
                                    }
                                    // Redirect when authentication was succesfull
                                    if (String.IsNullOrEmpty(error))
                                    {
                                        if (!String.IsNullOrEmpty(returnUrl))
                                        {
                                            URLHelper.Redirect(URLHelper.GetAbsoluteUrl(returnUrl));
                                        }
                                        else
                                        {
                                            URLHelper.Redirect(URLHelper.RemoveParameterFromUrl(URLHelper.CurrentURL, CONFIRMATION_URLPARAMETER));
                                        }
                                    }
                                    // Display error otherwise
                                    else
                                    {
                                        lblError.Text    = error;
                                        lblError.Visible = true;
                                    }
                                }
                                // Additional information page is set
                                else
                                {
                                    // Store user object in session for additional info page
                                    SessionHelper.SetValue(SESSION_NAME_USERDATA, facebookUserId);

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

                                    if (!String.IsNullOrEmpty(returnUrl))
                                    {
                                        // Add return URL to parameter
                                        targetURL = URLHelper.AddParameterToUrl(targetURL, "returnurl", HttpUtility.UrlEncode(returnUrl));
                                    }
                                    URLHelper.Redirect(targetURL);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                // Show warning message in "Design mode"
                Visible = DisplayMessage();
            }
        }
    }