/// <summary> /// SignOut handler. /// </summary> protected void btnSignOut_Click(object sender, CommandEventArgs e) { if (StopProcessing) { // Do not process } else { if (CMSContext.CurrentUser.IsAuthenticated()) { // Sign out from CMS FormsAuthentication.SignOut(); CMSContext.CurrentUser = null; CMSContext.ClearShoppingCart(); Response.Cache.SetNoStore(); if (Session != null) { // Store info about logout request, for validation logout request SessionHelper.SetValue("liveidlogout", DateTime.Now); } } // Clear session parameter Session.Remove("liveidlogout"); // Redirect to LiveID logout URLHelper.Redirect(e.CommandArgument.ToString()); } }
/// <summary> /// Sign out button event. /// </summary> protected void btnSignOut_Click(object sender, EventArgs e) { if (CMSContext.CurrentUser.IsAuthenticated()) { // Sign out from CMS FormsAuthentication.SignOut(); CMSContext.CurrentUser = null; CMSContext.ClearShoppingCart(); Response.Cache.SetNoStore(); // Clear used session SessionHelper.Remove(SESSION_NAME_USERDATA); // Redirect to return URL string returnUrl = QueryHelper.GetString("returnurl", URLHelper.CurrentURL); URLHelper.Redirect(URLHelper.GetAbsoluteUrl(HttpUtility.UrlDecode(returnUrl))); } }
/// <summary> /// SignOut click event handler. /// </summary> protected void btnSignOut_Click(object sender, EventArgs e) { if (currentUser == null) { currentUser = CMSContext.CurrentUser; } if (CMSContext.CurrentUser.IsAuthenticated()) { FormsAuthentication.SignOut(); CMSContext.ClearShoppingCart(); string redirectUrl = SignOutPath != "" ? GetUrl(SignOutPath) : URLHelper.CurrentURL; // If the user is Windows Live user if (!string.IsNullOrEmpty(currentUser.UserSettings.WindowsLiveID)) { string siteName = CMSContext.CurrentSiteName; // Get LiveID settings string appId = SettingsKeyProvider.GetStringValue(siteName + ".CMSApplicationID"); string secret = SettingsKeyProvider.GetStringValue(siteName + ".CMSApplicationSecret"); // Check valid Windows LiveID parameters if ((appId != string.Empty) && (secret != string.Empty)) { WindowsLiveLogin wll = new WindowsLiveLogin(appId, secret); // Redirect to Windows Live redirectUrl = wll.GetLogoutUrl(); } } CMSContext.CurrentUser = null; Response.Cache.SetNoStore(); URLHelper.Redirect(redirectUrl); } }
/// <summary> /// Initializes the control properties. /// </summary> protected void SetupControl() { if (StopProcessing) { // Do not process } else { // Facebook Connect sign out if (CMSContext.CurrentUser.IsAuthenticated()) { if (QueryHelper.GetInteger("logout", 0) > 0) { // Sign out from CMS // Remove Facebook user object from session SessionHelper.Remove(SESSION_NAME_USERDATA); FormsAuthentication.SignOut(); CMSContext.ClearShoppingCart(); CMSContext.CurrentUser = null; Response.Cache.SetNoStore(); URLHelper.Redirect(URLHelper.RemoveParameterFromUrl(URLHelper.CurrentURL, "logout")); return; } } // Show only desired button btnSignOut.Visible = !ShowAsLink; btnSignOutLink.Visible = ShowAsLink; if (!CMSContext.CurrentUser.IsPublic()) { // Hide for windows authentication if (RequestHelper.IsWindowsAuthentication()) { Visible = false; } else { // Set signout text btnSignOutLink.Text = SignOutText; btnSignOut.Text = SignOutText; } } else { // Set signin text btnSignOutLink.Text = SignInText; btnSignOut.Text = SignInText; } // Facebook Connect initialization btnSignOut.OnClientClick = FacebookConnectHelper.FacebookConnectInitForSignOut(CMSContext.CurrentSiteName, ltlScript); } if (!StandAlone && (PageCycle < PageCycleEnum.Initialized) && (ValidationHelper.GetString(Page.StyleSheetTheme, "") == "")) { btnSignOut.SkinID = SkinID; } // if user is not authenticated and ShowOnlyWhenAuthenticated is set if (CMSContext.CurrentUser.IsPublic() && ShowOnlyWhenAuthenticated) { Visible = false; } }
/// <summary> /// SignOut handler. /// </summary> protected void btnSignOut_Click(object sender, EventArgs e) { if (StopProcessing) { // Do not process } else { if (CMSContext.CurrentUser.IsAuthenticated()) { FormsAuthentication.SignOut(); CMSContext.ClearShoppingCart(); string redirectUrl = RedirectToUrl; // If the user has registered Windows Live ID if (!String.IsNullOrEmpty(CMSContext.CurrentUser.UserSettings.WindowsLiveID)) { // Get data from auth cookie string[] userData = UserInfoProvider.GetUserDataFromAuthCookie(); // If user has logged in using Windows Live ID, then sign him out from Live too if ((userData != null) && (Array.IndexOf(userData, "liveidlogin") >= 0)) { string siteName = CMSContext.CurrentSiteName; // Get LiveID settings string appId = SettingsKeyProvider.GetStringValue(siteName + ".CMSApplicationID"); string secret = SettingsKeyProvider.GetStringValue(siteName + ".CMSApplicationSecret"); // Check valid Windows LiveID parameters if ((appId != string.Empty) && (secret != string.Empty)) { WindowsLiveLogin wll = new WindowsLiveLogin(appId, secret); // Store info about logout request, for validation logout request SessionHelper.SetValue("liveidlogout", DateTime.Now); // Redirect to Windows Live redirectUrl = wll.GetLogoutUrl(); } } } CMSContext.ViewMode = ViewModeEnum.LiveSite; CMSContext.CurrentUser = null; Response.Cache.SetNoStore(); URLHelper.Redirect(redirectUrl); } else { string returnUrl = null; string signInUrl = null; if (SignInUrl != "") { signInUrl = ResolveUrl(CMSContext.GetUrl(CMSContext.ResolveCurrentPath(SignInUrl))); } else { signInUrl = SettingsKeyProvider.GetStringValue(CMSContext.CurrentSiteName + ".CMSSecuredAreasLogonPage"); } if (ReturnPath != "") { returnUrl = ResolveUrl(CMSContext.GetUrl(CMSContext.ResolveCurrentPath(ReturnPath))); } else { returnUrl = URLHelper.CurrentURL; } if (signInUrl != "") { // Prevent multiple returnUrl parameter returnUrl = URLHelper.RemoveParameterFromUrl(returnUrl, "returnUrl"); URLHelper.Redirect(URLHelper.AddParameterToUrl(signInUrl, "returnurl", returnUrl)); } } } }
/// <summary> /// Initializes the control properties. /// </summary> protected void SetupControl() { if (StopProcessing) { this.Visible = false; } else { if (QueryHelper.GetInteger("logout", 0) > 0) { // Sign out from CMS FormsAuthentication.SignOut(); CMSContext.ClearShoppingCart(); 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; } this.Visible = false; return; } // Try to retrieve return URL from query string returnUrl = QueryHelper.GetString("returnurl", null); // Init Facebook Connect if (this.Page is ContentPage) { // Adding XML namespace ((ContentPage)this.Page).XmlNamespace = FacebookConnectHelper.GetFacebookXmlNamespace(); } // Init FB connect ltlScript.Text = FacebookConnectHelper.GetFacebookInitScriptForSite(currentSiteName); // 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); string facebookUserId = ""; bool facebookCookiesValid = FacebookConnectHelper.GetFacebookSessionInfo(currentSiteName, out facebookUserId) == FacebookValidationEnum.ValidSignature; // If user is already authenticated if (CMSContext.CurrentUser.IsAuthenticated()) { // Is user logged in using Facebook Connect? if (!facebookCookiesValid || ((CMSContext.CurrentUser.UserSettings != null) && (CMSContext.CurrentUser.UserSettings.UserFacebookID != facebookUserId))) { // 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 ((QueryHelper.GetInteger(CONFIRMATION_URLPARAMETER, 0) > 0) && 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 UserInfoProvider.SetAuthCookieWithUserData(ui.UserName, true, Session.Timeout, new string[] { "facebooklogon" }); UserInfoProvider.SetPreferredCultures(ui); // Log activity if ((CMSContext.ViewMode == ViewModeEnum.LiveSite) && ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(currentSiteName) && ActivitySettingsHelper.UserLoginEnabled(currentSiteName)) { int contactId = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui); ActivityLogHelper.UpdateContactLastLogon(contactId); if (ActivitySettingsHelper.ActivitiesEnabledForThisUser(ui)) { TreeNode currDoc = CMSContext.CurrentDocument; ActivityLogProvider.LogLoginActivity(contactId, ui, URLHelper.CurrentRelativePath, currDoc.NodeID, currentSiteName, CMSContext.Campaign, currDoc.DocumentCulture); } } // 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 = UserInfoProvider.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 UserInfoProvider.SetAuthCookieWithUserData(ui.UserName, true, Session.Timeout, new string[] { "facebooklogon" }); // Log activity if ((CMSContext.ViewMode == ViewModeEnum.LiveSite) && ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(currentSiteName) && ActivitySettingsHelper.UserLoginEnabled(currentSiteName)) { int contactId = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui); ActivityLogHelper.UpdateContactLastLogon(contactId); if (ActivitySettingsHelper.ActivitiesEnabledForThisUser(ui)) { TreeNode currDoc = CMSContext.CurrentDocument; ActivityLogProvider.LogLoginActivity(contactId, ui, URLHelper.CurrentRelativePath, currDoc.NodeID, currentSiteName, CMSContext.Campaign, currDoc.DocumentCulture); } } } // Send registration e-mails // E-mail confirmation is not required as user already provided confirmation by successful login using Facebook connect UserInfoProvider.SendRegistrationEmails(ui, null, null, false, false); // Notify administrator if (this.NotifyAdministrator && !String.IsNullOrEmpty(this.FromAddress) && !String.IsNullOrEmpty(this.ToAddress)) { UserInfoProvider.NotifyAdministrator(ui, this.FromAddress, this.ToAddress); } // Log registration into analytics UserInfoProvider.TrackUserRegistration(this.TrackConversionName, this.ConversionValue, currentSiteName, ui); // Log activity if ((CMSContext.ViewMode == ViewModeEnum.LiveSite) && ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(currentSiteName) && ActivitySettingsHelper.ActivitiesEnabledForThisUser(ui) && ActivitySettingsHelper.UserRegistrationEnabled(currentSiteName)) { int contactId = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui); ModuleCommands.OnlineMarketingUpdateContactFromExternalData(ui, contactId); TreeNode currDoc = CMSContext.CurrentDocument; ActivityLogProvider.LogRegistrationActivity(contactId, ui, URLHelper.CurrentRelativePath, currDoc.NodeID, currentSiteName, CMSContext.Campaign, currDoc.DocumentCulture); } } // 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" this.Visible = DisplayMessage(); } } }