private void Login1_LoggedIn(object sender, EventArgs e) { // ScreenLock - unlock screen IsScreenLocked = false; // Ensure response cookie CookieHelper.EnsureResponseCookie(FormsAuthentication.FormsCookieName); // Set cookie expiration if (Login1.RememberMeSet) { CookieHelper.ChangeCookieExpiration(FormsAuthentication.FormsCookieName, DateTime.Now.AddYears(1), false); } else { // Extend the expiration of the authentication cookie if required if (!AuthenticationHelper.UseSessionCookies && (HttpContext.Current != null) && (HttpContext.Current.Session != null)) { CookieHelper.ChangeCookieExpiration(FormsAuthentication.FormsCookieName, DateTime.Now.AddMinutes(Session.Timeout), false); } } // Current username string userName = Login1.UserName; // Get info on the authenticated user UserInfo ui = UserInfo.Provider.Get(userName); // Check whether safe user name is required and if so get safe username if (ui == null && AuthenticationMode.IsMixedAuthentication() && UserInfoProvider.UseSafeUserName) { userName = ValidationHelper.GetSafeUserName(userName, SiteContext.CurrentSiteName); AuthenticationHelper.AuthenticateUser(userName, Login1.RememberMeSet); } // Set culture CMSDropDownList drpCulture = (CMSDropDownList)Login1.FindControl("drpCulture"); if (drpCulture != null) { string selectedCulture = drpCulture.SelectedValue; // Not the default culture if (selectedCulture != "") { // Update the user if (ui != null) { ui.PreferredUICultureCode = selectedCulture; UserInfo.Provider.Set(ui); } // Update current user MembershipContext.AuthenticatedUser.PreferredUICultureCode = selectedCulture; } } URLHelper.LocalRedirect(ReturnUrl); }
public string LoginUserinKentico(string username) { string flag = "false"; try { UserInfo userAuth = CMS.Membership.UserInfoProvider.GetUserInfo(username); if (userAuth != null) { if (Membership.ValidateUser(username, username)) { FormsAuthentication.SetAuthCookie(userAuth.UserName, true); CMS.Helpers.RequestStockHelper.Remove(userAuth.UserName); CMS.Helpers.RequestStockHelper.Add(userAuth.UserName, new CurrentUserInfo(userAuth, false)); CMS.Membership.AuthenticationHelper.SetCurrentUser(new CurrentUserInfo(userAuth, false)); CMS.Membership.AuthenticationHelper.AuthenticateUser(userAuth.UserName, true); // Set view mode to live site after login to prevent bar with "Close preview mode" // CMSContext.ViewMode = CMS.PortalEngine.ViewModeEnum.LiveSite; // Ensure response cookie CookieHelper.EnsureResponseCookie(FormsAuthentication.FormsCookieName); CookieHelper.AllowCookies = true; //add cookie to the domain var Cookie = FormsAuthentication.GetAuthCookie(userAuth.UserName, false); //Cookie.Domain = "kentico.networkats.com";//CMSContext.CurrentSiteName; Cookie.Expires = DateTime.Now.AddDays(1); Cookie.HttpOnly = true; HttpContext.Current.Response.Cookies.Add(Cookie); flag = Cookie.Value.ToString(); } } } catch (Exception ex) { EventLogProvider.LogException("LoginUserinKentico", "Get", ex); } return(flag); }
public LoginResult Login(LoginRequest loginRequest) { CookieHelper.EnsureResponseCookie(FormsAuthentication.FormsCookieName); if (loginRequest.KeepLoggedIn) { CookieHelper.ChangeCookieExpiration(FormsAuthentication.FormsCookieName, DateTime.Now.AddYears(1), false); } else { // Extend the expiration of the authentication cookie if required if (!AuthenticationHelper.UseSessionCookies && (HttpContext.Current != null) && (HttpContext.Current.Session != null)) { CookieHelper.ChangeCookieExpiration(FormsAuthentication.FormsCookieName, DateTime.Now.AddMinutes(HttpContext.Current.Session.Timeout), false); } } var user = AuthenticationHelper.AuthenticateUser(loginRequest.LoginEmail, loginRequest.Password, SiteContext.CurrentSiteName); if (user != null) { FormsAuthentication.SetAuthCookie(user.UserName, loginRequest.KeepLoggedIn); MembershipActivityLogger.LogLogin(user.UserName); return(new LoginResult { LogonSuccess = true }); } else { return(new LoginResult { LogonSuccess = false, ErrorPropertyName = "loginEmail", ErrorMessage = ResHelper.GetString("Kadena.Logon.LogonFailed", LocalizationContext.CurrentCulture.CultureCode) }); } }
void Login1_LoggedIn(object sender, EventArgs e) { // Ensure response cookie CookieHelper.EnsureResponseCookie(FormsAuthentication.FormsCookieName); // Set cookie expiration if (Login1.RememberMeSet) { CookieHelper.ChangeCookieExpiration(FormsAuthentication.FormsCookieName, DateTime.Now.AddYears(1), false); } else { // Extend the expiration of the authentication cookie if required if (!UserInfoProvider.UseSessionCookies && (HttpContext.Current != null) && (HttpContext.Current.Session != null)) { CookieHelper.ChangeCookieExpiration(FormsAuthentication.FormsCookieName, DateTime.Now.AddMinutes(Session.Timeout), false); } } // Current username string userName = Login1.UserName; // Get info on the authenticated user UserInfo ui = UserInfoProvider.GetUserInfo(userName); // Check whether safe user name is required and if so get safe username if (RequestHelper.IsMixedAuthentication() && UserInfoProvider.UseSafeUserName && (ui == null)) { userName = ValidationHelper.GetSafeUserName(this.Login1.UserName, CMSContext.CurrentSiteName); CMSContext.AuthenticateUser(userName, this.Login1.RememberMeSet); } // Set culture DropDownList drpCulture = (DropDownList)Login1.FindControl("drpCulture"); if (drpCulture != null) { string selectedCulture = drpCulture.SelectedValue; // Not the default culture if (selectedCulture != "") { // Update the user ui.PreferredUICultureCode = selectedCulture; UserInfoProvider.SetUserInfo(ui); // Update current user CMSContext.CurrentUser.PreferredUICultureCode = selectedCulture; } } // Splash screen handling bool splashScreenEnabled = false; LicenseKeyInfo lki = LicenseKeyInfoProvider.GetLicenseKeyInfo(URLHelper.GetCurrentDomain()); if ((lki != null) && lki.IsTrial && ui.UserSettings.UserShowSplashScreen) { if (lki.ExpirationDate != DateTimeHelper.ZERO_TIME) { // Display splash screen only if using trial license splashScreenEnabled = true; } } // Splash screen string returnUrl = ReturnUrl; // Return url is not specified or is relative path or hash is valid if (string.IsNullOrEmpty(returnUrl) || returnUrl.StartsWith("~") || returnUrl.StartsWith("/") || QueryHelper.ValidateHash("hash")) { if (splashScreenEnabled && ui.UserSettings.UserShowSplashScreen && SettingsKeyProvider.GetBoolValue(CMSContext.CurrentSiteName + ".CMSShowSplashScreen")) { if ((!String.IsNullOrEmpty(CMSContext.CurrentSiteName)) && (returnUrl.Contains("cmsdesk") || IsSiteManager)) { URLHelper.Redirect(ResolveUrl("~/CMSSiteManager/SplashScreen.aspx?continueurl=" + returnUrl)); } } // Destination page URL if (returnUrl.Contains("restorepost")) { // Delete the saved state SavedFormState state = FormStateHelper.GetSavedState(); if (state != null) { state.Delete(); } returnUrl = URLHelper.RemoveParameterFromUrl(returnUrl, "restorepost"); URLHelper.Redirect(ResolveUrl(returnUrl)); } } else { URLHelper.Redirect(ResolveUrl("~/CMSMessages/Error.aspx?title=" + ResHelper.GetString("general.badhashtitle") + "&text=" + ResHelper.GetString("general.badhashtext"))); } }
/// <summary> /// Logged in handler. /// </summary> private void Login1_LoggedIn(object sender, EventArgs e) { // Set view mode to live site after login to prevent bar with "Close preview mode" PortalContext.ViewMode = ViewModeEnum.LiveSite; // Ensure response cookie CookieHelper.EnsureResponseCookie(FormsAuthentication.FormsCookieName); // Set cookie expiration if (Login1.RememberMeSet) { CookieHelper.ChangeCookieExpiration(FormsAuthentication.FormsCookieName, DateTime.Now.AddYears(1), false); } else { // Extend the expiration of the authentication cookie if required if (!AuthenticationHelper.UseSessionCookies && (HttpContext.Current != null) && (HttpContext.Current.Session != null)) { CookieHelper.ChangeCookieExpiration(FormsAuthentication.FormsCookieName, DateTime.Now.AddMinutes(Session.Timeout), false); } } // Current username string userName = Login1.UserName; // Get user name (test site prefix too) UserInfo ui = UserInfoProvider.GetUserInfoForSitePrefix(userName, SiteContext.CurrentSite); // Check whether safe user name is required and if so get safe username if (RequestHelper.IsMixedAuthentication() && UserInfoProvider.UseSafeUserName) { // Get info on the authenticated user if (ui == null) { // User stored with safe name userName = ValidationHelper.GetSafeUserName(Login1.UserName, SiteContext.CurrentSiteName); // Find user by safe name ui = UserInfoProvider.GetUserInfoForSitePrefix(userName, SiteContext.CurrentSite); if (ui != null) { // Authenticate user by site or global safe username AuthenticationHelper.AuthenticateUser(ui.UserName, Login1.RememberMeSet); } } } if (ui != null) { // If user name is site prefixed, authenticate user manually if (UserInfoProvider.IsSitePrefixedUser(ui.UserName)) { AuthenticationHelper.AuthenticateUser(ui.UserName, Login1.RememberMeSet); } // Log activity MembershipActivityLogger.LogLogin(ui.UserName, DocumentContext.CurrentDocument); } // Redirect user to the return URL, or if is not defined redirect to the default target URL var redirectUrl = RequestContext.CurrentURL; string url = QueryHelper.GetString("ReturnURL", String.Empty); if (!String.IsNullOrEmpty(url) && URLHelper.IsLocalUrl(url)) { redirectUrl = url; } else if (!String.IsNullOrEmpty(DefaultTargetUrl)) { redirectUrl = ResolveUrl(DefaultTargetUrl); } URLHelper.Redirect(redirectUrl); }
/// <summary> /// Logged in handler. /// </summary> private void loginElem_LoggedIn(object sender, EventArgs e) { // Set view mode to live site after login to prevent bar with "Close preview mode" PortalContext.ViewMode = ViewModeEnum.LiveSite; // Ensure response cookie CookieHelper.EnsureResponseCookie(FormsAuthentication.FormsCookieName); // Set cookie expiration if (loginElem.RememberMeSet) { CookieHelper.ChangeCookieExpiration(FormsAuthentication.FormsCookieName, DateTime.Now.AddYears(1), false); } else { // Extend the expiration of the authentication cookie if required if (!AuthenticationHelper.UseSessionCookies && (HttpContext.Current != null) && (HttpContext.Current.Session != null)) { CookieHelper.ChangeCookieExpiration(FormsAuthentication.FormsCookieName, DateTime.Now.AddMinutes(Session.Timeout), false); } } // Current username string userName = loginElem.UserName; // Get user name (test site prefix too) UserInfo ui = UserInfoProvider.GetUserInfoForSitePrefix(userName, SiteContext.CurrentSite); // Check whether safe user name is required and if so get safe username if (RequestHelper.IsMixedAuthentication() && UserInfoProvider.UseSafeUserName) { // User stored with safe name userName = ValidationHelper.GetSafeUserName(loginElem.UserName, SiteContext.CurrentSiteName); // Find user by safe name ui = UserInfoProvider.GetUserInfoForSitePrefix(userName, SiteContext.CurrentSite); if (ui != null) { // Authenticate user by site or global safe username AuthenticationHelper.AuthenticateUser(ui.UserName, loginElem.RememberMeSet); } } // Log activity (warning: CMSContext contains info of previous user) if (ui != null) { // If user name is site prefixed, authenticate user manually if (UserInfoProvider.IsSitePrefixedUser(ui.UserName)) { AuthenticationHelper.AuthenticateUser(ui.UserName, loginElem.RememberMeSet); } // Log activity int contactID = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui); Activity activityLogin = new ActivityUserLogin(contactID, ui, DocumentContext.CurrentDocument, AnalyticsContext.ActivityEnvironmentVariables); activityLogin.Log(); } // Redirect user to the return url, or if is not defined redirect to the default target url string url = QueryHelper.GetString("ReturnURL", string.Empty); if (!string.IsNullOrEmpty(url)) { if (url.StartsWithCSafe("~") || url.StartsWithCSafe("/") || QueryHelper.ValidateHash("hash")) { URLHelper.Redirect(ResolveUrl(QueryHelper.GetString("ReturnURL", string.Empty))); } else { URLHelper.Redirect(ResolveUrl("~/CMSMessages/Error.aspx?title=" + ResHelper.GetString("general.badhashtitle") + "&text=" + ResHelper.GetString("general.badhashtext"))); } } else { if (DefaultTargetUrl != "") { URLHelper.Redirect(ResolveUrl(DefaultTargetUrl)); } else { URLHelper.Redirect(RequestContext.CurrentURL); } } }
private void Login1_LoggedIn(object sender, EventArgs e) { // ScreenLock - unlock screen IsScreenLocked = false; // Ensure response cookie CookieHelper.EnsureResponseCookie(FormsAuthentication.FormsCookieName); // Set cookie expiration if (Login1.RememberMeSet) { CookieHelper.ChangeCookieExpiration(FormsAuthentication.FormsCookieName, DateTime.Now.AddYears(1), false); } else { // Extend the expiration of the authentication cookie if required if (!AuthenticationHelper.UseSessionCookies && (HttpContext.Current != null) && (HttpContext.Current.Session != null)) { CookieHelper.ChangeCookieExpiration(FormsAuthentication.FormsCookieName, DateTime.Now.AddMinutes(Session.Timeout), false); } } // Current username string userName = Login1.UserName; // Get info on the authenticated user UserInfo ui = UserInfoProvider.GetUserInfoForSitePrefix(userName, SiteContext.CurrentSite); String siteName = SiteContext.CurrentSiteName; // For site prefix user, authenticate manually if (ui != null) { if (UserInfoProvider.UserNameSitePrefixEnabled(siteName) && UserInfoProvider.IsSitePrefixedUser(ui.UserName)) { AuthenticationHelper.AuthenticateUser(ui.UserName, Login1.RememberMeSet); } } // Check whether safe user name is required and if so get safe username else if (RequestHelper.IsMixedAuthentication() && UserInfoProvider.UseSafeUserName) { userName = ValidationHelper.GetSafeUserName(userName, SiteContext.CurrentSiteName); if (UserInfoProvider.UserNameSitePrefixEnabled(siteName)) { // Check for site prefix ui = UserInfoProvider.GetUserInfoForSitePrefix(userName, SiteContext.CurrentSite); if (ui != null) { userName = ui.UserName; } } AuthenticationHelper.AuthenticateUser(userName, Login1.RememberMeSet); } // Set culture CMSDropDownList drpCulture = (CMSDropDownList)Login1.FindControl("drpCulture"); if (drpCulture != null) { string selectedCulture = drpCulture.SelectedValue; // Not the default culture if (selectedCulture != "") { // Update the user if (ui != null) { ui.PreferredUICultureCode = selectedCulture; UserInfoProvider.SetUserInfo(ui); } // Update current user MembershipContext.AuthenticatedUser.PreferredUICultureCode = selectedCulture; } } string returnUrl = ReturnUrl; // Return url is not specified or is relative path or hash is valid if (!string.IsNullOrEmpty(returnUrl) && !returnUrl.StartsWithCSafe("~") && !returnUrl.StartsWithCSafe("/") && !QueryHelper.ValidateHash("hash")) { URLHelper.Redirect(UIHelper.GetErrorPageUrl("dialogs.badhashtitle", "dialogs.badhashtext")); } }
/// <summary> /// Logged in handler. /// </summary> void loginElem_LoggedIn(object sender, EventArgs e) { // Set view mode to live site after login to prevent bar with "Close preview mode" CMSContext.ViewMode = CMS.PortalEngine.ViewModeEnum.LiveSite; // Ensure response cookie CookieHelper.EnsureResponseCookie(FormsAuthentication.FormsCookieName); // Set cookie expiration if (loginElem.RememberMeSet) { CookieHelper.ChangeCookieExpiration(FormsAuthentication.FormsCookieName, DateTime.Now.AddYears(1), false); } else { // Extend the expiration of the authentication cookie if required if (!UserInfoProvider.UseSessionCookies && (HttpContext.Current != null) && (HttpContext.Current.Session != null)) { CookieHelper.ChangeCookieExpiration(FormsAuthentication.FormsCookieName, DateTime.Now.AddMinutes(Session.Timeout), false); } } // Current username string userName = loginElem.UserName; // Get user name (test site prefix too) UserInfo ui = UserInfoProvider.GetUserInfoForSitePrefix(userName, CMSContext.CurrentSite); // Check whether safe user name is required and if so get safe username if (RequestHelper.IsMixedAuthentication() && UserInfoProvider.UseSafeUserName) { // User stored with safe name userName = ValidationHelper.GetSafeUserName(this.loginElem.UserName, CMSContext.CurrentSiteName); // Find user by safe name ui = UserInfoProvider.GetUserInfoForSitePrefix(userName, CMSContext.CurrentSite); if (ui != null) { // Authenticate user by site or global safe username CMSContext.AuthenticateUser(ui.UserName, this.loginElem.RememberMeSet); } } // Log activity (warning: CMSContext contains info of previous user) if (ui != null) { // If user name is site prefixed, authenticate user manually if (UserInfoProvider.IsSitePrefixedUser(ui.UserName)) { CMSContext.AuthenticateUser(ui.UserName, this.loginElem.RememberMeSet); } // Log activity string siteName = CMSContext.CurrentSiteName; if ((CMSContext.ViewMode == ViewModeEnum.LiveSite) && ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(siteName) && ActivitySettingsHelper.UserLoginEnabled(siteName)) { int contactId = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui); ActivityLogHelper.UpdateContactLastLogon(contactId); if (ActivitySettingsHelper.ActivitiesEnabledForThisUser(ui)) { TreeNode currentDoc = CMSContext.CurrentDocument; ActivityLogProvider.LogLoginActivity(contactId, ui, URLHelper.CurrentRelativePath, (currentDoc != null ? currentDoc.NodeID : 0), CMSContext.CurrentSiteName, CMSContext.Campaign, (currentDoc != null ? currentDoc.DocumentCulture : null)); } } } // Redirect user to the return url, or if is not defined redirect to the default target url string url = QueryHelper.GetString("ReturnURL", string.Empty); if (!string.IsNullOrEmpty(url)) { if (url.StartsWith("~") || url.StartsWith("/") || QueryHelper.ValidateHash("hash")) { URLHelper.Redirect(ResolveUrl(ValidationHelper.GetString(Request.QueryString["ReturnURL"], ""))); } else { URLHelper.Redirect(ResolveUrl("~/CMSMessages/Error.aspx?title=" + ResHelper.GetString("general.badhashtitle") + "&text=" + ResHelper.GetString("general.badhashtext"))); } } else { if (DefaultTargetUrl != "") { URLHelper.Redirect(ResolveUrl(DefaultTargetUrl)); } else { URLHelper.Redirect(URLRewriter.CurrentURL); } } }
/// <summary> /// Logged in handler. /// </summary> private void Login1_LoggedIn(object sender, EventArgs e) { // Set view mode to live site after login to prevent bar with "Close preview mode" PortalContext.ViewMode = ViewModeEnum.LiveSite; // Ensure response cookie CookieHelper.EnsureResponseCookie(FormsAuthentication.FormsCookieName); // Set cookie expiration if (Login1.RememberMeSet) { CookieHelper.ChangeCookieExpiration(FormsAuthentication.FormsCookieName, DateTime.Now.AddYears(1), false); } else { // Extend the expiration of the authentication cookie if required if (!AuthenticationHelper.UseSessionCookies && (HttpContext.Current != null) && (HttpContext.Current.Session != null)) { CookieHelper.ChangeCookieExpiration(FormsAuthentication.FormsCookieName, DateTime.Now.AddMinutes(Session.Timeout), false); } } // Current username string userName = Login1.UserName; // Get user name (test site prefix too) UserInfo ui = UserInfoProvider.GetUserInfoForSitePrefix(userName, SiteContext.CurrentSite); // Check whether safe user name is required and if so get safe username if (RequestHelper.IsMixedAuthentication() && UserInfoProvider.UseSafeUserName) { // Get info on the authenticated user if (ui == null) { // User stored with safe name userName = ValidationHelper.GetSafeUserName(Login1.UserName, SiteContext.CurrentSiteName); // Find user by safe name ui = UserInfoProvider.GetUserInfoForSitePrefix(userName, SiteContext.CurrentSite); if (ui != null) { // Authenticate user by site or global safe username AuthenticationHelper.AuthenticateUser(ui.UserName, Login1.RememberMeSet); } } } if (ui != null) { // If user name is site prefixed, authenticate user manually if (UserInfoProvider.IsSitePrefixedUser(ui.UserName)) { AuthenticationHelper.AuthenticateUser(ui.UserName, Login1.RememberMeSet); } // Log activity int contactID = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui); Activity activityLogin = new ActivityUserLogin(contactID, ui, DocumentContext.CurrentDocument, AnalyticsContext.ActivityEnvironmentVariables); activityLogin.Log(); } // Redirect user to the return URL, or if is not defined redirect to the default target URL var redirectUrl = RequestContext.CurrentURL; string url = ResolveUrl(QueryHelper.GetString("ReturnURL", String.Empty)); string hash = QueryHelper.GetString("hash", String.Empty); if (!String.IsNullOrEmpty(url)) { if (URLHelper.IsLocalUrl(url, RequestContext.CurrentDomain)) { redirectUrl = url; } else if (!String.IsNullOrEmpty(hash)) { if (QueryHelper.ValidateHash("hash", "aliaspath")) { redirectUrl = url; } else { redirectUrl = UIHelper.GetErrorPageUrl("dialogs.badhashtitle", "dialogs.badhashtext"); } } } else if (!String.IsNullOrEmpty(DefaultTargetUrl)) { redirectUrl = ResolveUrl(DefaultTargetUrl); } URLHelper.Redirect(redirectUrl); }