/// <summary> /// Manages some actions, after user authorized and page postbacked /// </summary> /// <param name="sender">Sender</param> /// <param name="e">Args</param> protected void btnHidden_Click(object sender, EventArgs e) { string arg = Request[Page.postEventArgumentID]; switch (arg.ToLowerCSafe()) { case "redirecttoadditionalpage": // Get additional page string additionalInfoPage = SettingsKeyInfoProvider.GetValue(SiteContext.CurrentSiteName + ".CMSLiveIDRequiredUserDataPage"); if (!String.IsNullOrEmpty(additionalInfoPage)) { // Redirect to additional info page URLHelper.Redirect(UrlResolver.ResolveUrl(additionalInfoPage)); } break; case "clearcookieandredirect": WindowsLiveLogin.ClearCookieAndRedirect(logonPage); break; default: string returnUrl = QueryHelper.GetString("returnUrl", null); if (URLHelper.IsLocalUrl(returnUrl)) { URLHelper.Redirect(returnUrl); } else { URLHelper.Redirect(RequestContext.CurrentURL); } break; } }
/// <summary> /// Manages some actions, after user authorized and page postbacked /// </summary> /// <param name="sender">Sender</param> /// <param name="e">Args</param> protected void btnHidden_Click(object sender, EventArgs e) { string arg = Request[Page.postEventArgumentID]; switch (arg.ToLowerCSafe()) { case "redirecttoadditionalpage": // Get additional page string additionalInfoPage = SettingsKeyInfoProvider.GetStringValue(SiteContext.CurrentSiteName + ".CMSLiveIDRequiredUserDataPage"); if (!String.IsNullOrEmpty(additionalInfoPage)) { // Redirect to additional info page URLHelper.Redirect(URLHelper.ResolveUrl(additionalInfoPage)); } break; case "clearcookieandredirect": WindowsLiveLogin.ClearCookieAndRedirect(LOGON_PAGE_SETTINGS_KEY); break; } }
/// <summary> /// Manages some actions, after user authorized and page postbacked /// </summary> /// <param name="sender">Sender</param> /// <param name="e">Args</param> protected void btnHidden_Click(object sender, EventArgs e) { string arg = Request["__EVENTARGUMENT"]; switch (arg.ToLower()) { case "redirecttoadditionalpage": // Get additional page string additionalInfoPage = SettingsKeyProvider.GetStringValue(CMSContext.CurrentSiteName + ".CMSLiveIDRequiredUserDataPage"); if (!String.IsNullOrEmpty(additionalInfoPage)) { // Redirect to additional info page URLHelper.Redirect(URLHelper.ResolveUrl(additionalInfoPage)); } break; case "clearcookieandredirect": WindowsLiveLogin.ClearCookieAndRedirect(loginPage); break; } }
/// <summary> /// Get user information and logs user (register if no user found) /// </summary> private void ProcessLiveIDLogin() { // Get authorization code from URL String code = QueryHelper.GetString("code", String.Empty); // Additional info page for login string additionalInfoPage = SettingsKeyInfoProvider.GetValue(siteName + ".CMSLiveIDRequiredUserDataPage"); // Create windows login object WindowsLiveLogin wwl = new WindowsLiveLogin(siteName); // Windows live User WindowsLiveLogin.User liveUser = null; if (!WindowsLiveLogin.UseServerSideAuthorization) { if (!RequestHelper.IsPostBack()) { // If client authentication, get token displayed in url after # from window.location String script = ControlsHelper.GetPostBackEventReference(this, "#").Replace("'#'", "window.location"); ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "PostbackScript", ScriptHelper.GetScript(script)); } else { // Try to get full url from event argument string fullurl = Request[postEventArgumentID]; // Authentication token - use to get uid String token = ParseToken(fullurl, @"authentication_token=([\w\d.-]+)&"); // User token - this token is used in server auth. scenario. It's stored in user object (for possible further use) so parse it too and store it String accessToken = ParseToken(fullurl, @"access_token=([%\w\d.-/]+)&"); if (token != String.Empty) { // Return context from session GetLoginInformation(); // Authenticate user by found token liveUser = wwl.AuthenticateClientToken(token, relativeURL, accessToken); if (liveUser != null) { // Set info to refresh to parent page ScriptHelper.RegisterWOpenerScript(Page); CreateCloseScript(""); } } } } else { GetLoginInformation(); // Process login via Live ID liveUser = wwl.ProcessLogin(code, relativeURL); } // Authorization successful if (liveUser != null) { // Find user by ID UserInfo winUser = UserInfoProvider.GetUserInfoByWindowsLiveID(liveUser.Id); string error = String.Empty; // Register new user if (winUser == null) { // Check whether additional user info page is set // No page set, user can be created/sign if (additionalInfoPage == String.Empty) { // Create new user UserInfo ui = AuthenticationHelper.AuthenticateWindowsLiveUser(liveUser.Id, siteName, true, ref error); // Remove live user object from session, won't be needed Session.Remove("windowsliveloginuser"); // If user was found or successfully created if ((ui != null) && (ui.Enabled)) { double resolvedConversionValue = ValidationHelper.GetDouble(MacroResolver.Resolve(conversionValue), 0); // Log user registration into the web analytics and track conversion if set AnalyticsHelper.TrackUserRegistration(siteName, ui, conversionName, resolvedConversionValue); MembershipActivityLogger.LogRegistration(ui.UserName, DocumentContext.CurrentDocument); SetAuthCookieAndRedirect(ui); } // User not created else { if (WindowsLiveLogin.UseServerSideAuthorization) { WindowsLiveLogin.ClearCookieAndRedirect(loginPage); } else { CreateCloseScript("clearcookieandredirect"); } } } // Required data page exists else { // Store user object in session for additional info page SessionHelper.SetValue("windowsliveloginuser", liveUser); if (WindowsLiveLogin.UseServerSideAuthorization) { // Redirect to additional info page URLHelper.Redirect(UrlResolver.ResolveUrl(additionalInfoPage)); } else { CreateCloseScript("redirectToAdditionalPage"); } } } else { UserInfo ui = AuthenticationHelper.AuthenticateWindowsLiveUser(liveUser.Id, siteName, true, ref error); // If user was found if ((ui != null) && (ui.Enabled)) { SetAuthCookieAndRedirect(ui); } } } }
/// <summary> /// Get user information and logs user (register if no user found) /// </summary> private void ProcessLiveIDLogin() { // Get authorization code from URL String code = QueryHelper.GetString("code", String.Empty); // Additional info page for login string additionalInfoPage = SettingsKeyProvider.GetStringValue(siteName + ".CMSLiveIDRequiredUserDataPage"); // Create windows login object WindowsLiveLogin wwl = new WindowsLiveLogin(siteName); // Windows live User WindowsLiveLogin.User liveUser = null; if (!WindowsLiveLogin.UseServerSideAuthorization) { if (!RequestHelper.IsPostBack()) { // If client authentication, get token displayed in url after # from window.location String script = ControlsHelper.GetPostBackEventReference(this, "#").Replace("'#'", "window.location"); ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "PostbackScript", ScriptHelper.GetScript(script)); } else { // Try to get full url from event argument string fullurl = Request["__EVENTARGUMENT"]; // Authentication token - use to get uid String token = ParseToken(fullurl, @"authentication_token=([\w\d.-]+)&"); // User token - this token is used in server auth. scenario. It's stored in user object (for possible further use) so parse it too and store it String accessToken = ParseToken(fullurl, @"access_token=([%\w\d.-]+)&"); if (token != String.Empty) { // Return context from session GetLoginInformation(); // Authenticate user by found token liveUser = wwl.AuthenticateClientToken(token, relativeURL, accessToken); if (liveUser != null) { // Set info to refresh to parent page ScriptHelper.RegisterWOpenerScript(Page); CreateCloseScript(""); } } } } else { GetLoginInformation(); // Process login via Live ID liveUser = wwl.ProcessLogin(code, relativeURL); } // Authorization sucesfull if (liveUser != null) { // Find user by ID UserInfo winUser = UserInfoProvider.GetUserInfoByWindowsLiveID(liveUser.Id); string error = String.Empty; // Register new user if (winUser == null) { // Check whether additional user info page is set // No page set, user can be created/sign if (additionalInfoPage == String.Empty) { // Create new user user UserInfo ui = UserInfoProvider.AuthenticateWindowsLiveUser(liveUser.Id, siteName, true, ref error); // Remove live user object from session, won't be needed Session.Remove("windowsliveloginuser"); // If user was found or successfuly created if ((ui != null) && (ui.Enabled)) { // Send registration e-mails // E-mail confirmation is not required as user already provided confirmation by successful login using LiveID UserInfoProvider.SendRegistrationEmails(ui, null, null, false, false); // Track registration into analytics double val = ValidationHelper.GetDouble(CMSContext.CurrentResolver.ResolveMacros(conversionValue), 0); UserInfoProvider.TrackUserRegistration(conversionName, val, siteName, ui); // Log registration activity if ((CMSContext.ViewMode == ViewModeEnum.LiveSite) && ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(siteName) && ActivitySettingsHelper.ActivitiesEnabledForThisUser(CMSContext.CurrentUser) && ActivitySettingsHelper.UserRegistrationEnabled(siteName)) { int contactId = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui); TreeNode currentDoc = CMSContext.CurrentDocument; ActivityLogProvider.LogRegistrationActivity(contactId, ui, URLHelper.CurrentRelativePath, (currentDoc != null ? currentDoc.NodeID : 0), siteName, CMSContext.Campaign, (currentDoc != null ? currentDoc.DocumentCulture : null)); } SetAuthCookieAndRedirect(ui); } // User not created else { if (WindowsLiveLogin.UseServerSideAuthorization) { WindowsLiveLogin.ClearCookieAndRedirect(loginPage); } else { CreateCloseScript("clearcookieandredirect"); } } } // Required data page exists else { // Store user object in session for additional info page SessionHelper.SetValue("windowsliveloginuser", liveUser); if (WindowsLiveLogin.UseServerSideAuthorization) { // Redirect to additional info page URLHelper.Redirect(URLHelper.ResolveUrl(additionalInfoPage)); } else { CreateCloseScript("redirectToAdditionalPage"); } } } else { UserInfo ui = UserInfoProvider.AuthenticateWindowsLiveUser(liveUser.Id, siteName, true, ref error); // If user was found if ((ui != null) && (ui.Enabled)) { SetAuthCookieAndRedirect(ui); } } } }