protected void Page_PreInit(object sender, EventArgs e) { //check if cookie from this portal if (SecurityContext.CurrentAccount is IUserAccount && ((IUserAccount)SecurityContext.CurrentAccount).Tenant != CoreContext.TenantManager.GetCurrentTenant().TenantId) { SecurityContext.Logout(); Response.Redirect("~/"); } var currentUser = CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID); if (currentUser == Constants.LostUser || currentUser.Status != EmployeeStatus.Active) { SecurityContext.Logout(); Response.Redirect("~/"); } ProcessSecureFilter(); var wizardSettings = SettingsManager.Instance.LoadSettings <WizardSettings>(TenantProvider.CurrentTenantID); if (Request["first"] == "1" && !string.IsNullOrEmpty(Request["id"]) && wizardSettings.Completed) { // wizardSettings.Completed - open source, Request["first"] - cloud wizardSettings.Completed = false; SettingsManager.Instance.SaveSettings(wizardSettings, TenantProvider.CurrentTenantID); } var smsAuthSettings = SettingsManager.Instance.LoadSettings <StudioSmsNotificationSettings>(TenantProvider.CurrentTenantID); if (!wizardSettings.Completed && !(this is confirm)) { var successAuth = SecurityContext.IsAuthenticated; if (!successAuth) { var cookie = Request["id"] ?? CookiesManager.GetCookies(CookiesType.AuthKey); if (!string.IsNullOrEmpty(cookie)) { successAuth = AuthByCookies(cookie); } if (!successAuth) { try { cookie = SecurityContext.AuthenticateMe(UserManagerWrapper.AdminID.ToString(), "admin"); successAuth = true; } catch (System.Security.SecurityException) { } } if (successAuth) { CookiesManager.SetCookies(CookiesType.AuthKey, cookie); WebItemManager.Instance.ItemGlobalHandlers.Login(SecurityContext.CurrentAccount.ID); } } if (!successAuth && !(this is Auth)) { Response.Redirect("~/auth.aspx"); } if (successAuth && !(this is Wizard)) { Response.Redirect("~/wizard.aspx"); } } else if (smsAuthSettings.Enable && Session["UserTransferData"] != null && !(this is confirm)) { Response.Redirect(String.Format("~/Confirm.aspx?type={0}", ((UserTransferData)Session["UserTransferData"]).MobilePhoneActivationStatus == MobilePhoneActivationStatus.NotActivated ? ConfirmType.PhoneActivation : ConfirmType.PhoneAuth)); } else if (!SecurityContext.IsAuthenticated && wizardSettings.Completed && !(this is confirm)) { //for demo if (SetupInfo.WorkMode == WorkMode.Promo) { if (AutoAuthByPromo()) { UserOnlineManager.Instance.RegistryOnlineUser(SecurityContext.CurrentAccount.ID); Response.Redirect("~/"); return; } } if (this is Auth && Session["refererURL"] == null && !string.IsNullOrEmpty(HttpContext.Current.Request.Params["id"])) { var authCookie = HttpContext.Current.Request.Params["id"]; if (AuthByCookies(authCookie)) { CookiesManager.SetCookies(CookiesType.AuthKey, authCookie); var first = Request["first"] == "1"; if (first) { try { var tenant = CoreContext.TenantManager.GetCurrentTenant(false); tenant.Name = Resources.Resource.StudioWelcomeHeader; CoreContext.TenantManager.SaveTenant(tenant); } catch { } } Response.Redirect(VirtualPathUtility.ToAbsolute("~/") + (first ? "?first=1" : "")); return; } } if (!(this is Auth)) { var refererURL = Request.Url.AbsoluteUri; if (!ValidateRefererUrl(refererURL)) { refererURL = (string)Session["refererURL"]; } if (!AutoAuthByCookies() && !CoreContext.TenantManager.GetCurrentTenant().Public) { Session["refererURL"] = refererURL; Response.Redirect("~/auth.aspx"); return; } } } else if (SecurityContext.IsAuthenticated && this is Auth && !this.IsLogout) { Response.Redirect("~/"); return; } else if (this is Wizard && wizardSettings.Completed) { Response.Redirect("~/"); return; } //check disable and public var webitem = CommonLinkUtility.GetWebItemByUrl(Request.Url.ToString()); if (webitem != null && webitem.IsDisabled()) { Response.Redirect("~/"); return; } if (SecurityContext.IsAuthenticated) { UserOnlineManager.Instance.RegistryOnlineUser(SecurityContext.CurrentAccount.ID); try { StatisticManager.SaveUserVisit(TenantProvider.CurrentTenantID, SecurityContext.CurrentAccount.ID, CommonLinkUtility.GetProductID()); } catch (Exception exc) { Log.Error("failed save user visit", exc); } } CurrentSkin = WebSkin.GetUserSkin(); Theme = CurrentSkin.ASPTheme; #region Init common javascript resources var commonJavascriptResources = "CommonJavascriptResources"; if (!Page.ClientScript.IsClientScriptBlockRegistered(commonJavascriptResources)) { var script = string.Format(@" var CommonJavascriptResources = {{ CancelConfirmMessage : '{0}' }};", Resources.Resource.CancelConfirmMessage.ReplaceSingleQuote()); Page.ClientScript.RegisterClientScriptBlock(typeof(string), commonJavascriptResources, script, true); } #endregion PersonalHelper.TransferRequest(this); }
protected void Page_PreInit(object sender, EventArgs e) { ProcessSecureFilter(); var wizardSettings = SettingsManager.Instance.LoadSettings <WizardSettings>(TenantProvider.CurrentTenantID); if (Request["first"] == "1" && !string.IsNullOrEmpty(Request["id"]) && wizardSettings.Completed) { // wizardSettings.Completed - open source, Request["first"] - cloud wizardSettings.Completed = false; SettingsManager.Instance.SaveSettings(wizardSettings, TenantProvider.CurrentTenantID); } var authCookie = Request["id"] ?? CookiesManager.GetCookies(CookiesType.AuthKey); if (!wizardSettings.Completed && !(this is confirm)) { var successAuth = SecurityContext.IsAuthenticated; if (!successAuth) { successAuth = AuthByCookies(authCookie); if (successAuth) { CookiesManager.SetCookies(CookiesType.AuthKey, authCookie); } else { try { authCookie = SecurityContext.AuthenticateMe(UserManagerWrapper.AdminID.ToString(), "admin"); successAuth = true; } catch (System.Security.Authentication.InvalidCredentialException) { } catch (System.Security.SecurityException) { } } } if (!successAuth && !(this is Auth)) { Response.Redirect("~/auth.aspx"); } if (successAuth && !(this is Wizard)) { Response.Redirect("~/wizard.aspx"); } } else if (!SecurityContext.IsAuthenticated && wizardSettings.Completed && !(this is confirm)) { if (this is Auth && Session["refererURL"] == null && !string.IsNullOrEmpty(Request["id"])) { if (AuthByCookies(authCookie)) { CookiesManager.SetCookies(CookiesType.AuthKey, authCookie); var first = Request["first"] == "1"; if (first) { try { var tenant = CoreContext.TenantManager.GetCurrentTenant(false); tenant.Name = Resources.Resource.StudioWelcomeHeader; CoreContext.TenantManager.SaveTenant(tenant); } catch { } } Response.Redirect(VirtualPathUtility.ToAbsolute("~/") + (first ? "?first=1" : "")); return; } } //for redirect into one of the projects after creating new tenant else if (Session["refererURL"] == null && !string.IsNullOrEmpty(Request["id"])) { if (AuthByCookies(authCookie)) { CookiesManager.SetCookies(CookiesType.AuthKey, authCookie); try { var tenant = CoreContext.TenantManager.GetCurrentTenant(false); tenant.Name = Resources.Resource.StudioWelcomeHeader; CoreContext.TenantManager.SaveTenant(tenant); } catch { Log.Error("Can't set current tenant in MainPage"); } var refererURL = GetRefererUrl(); if (String.IsNullOrEmpty(refererURL)) { Response.Redirect("~/auth.aspx"); } else { var currentUser = CoreContext.UserManager.GetUsers(CoreContext.TenantManager.GetCurrentTenant().OwnerId); if (!currentUser.IsOwner()) { Response.Redirect("~/auth.aspx"); } SecurityContext.AuthenticateMe(CoreContext.Authentication.GetAccountByID(currentUser.ID)); FirstTimeTenantSettings.SetDefaultTenantSettings(); FirstTimeTenantSettings.SendInstallInfo(currentUser); Response.Redirect(refererURL); } } } if (!(this is Auth) && !AutoAuthByCookies() && !ExclusivePage()) { var refererURL = GetRefererUrl(); Session["refererURL"] = refererURL; Response.Redirect("~/auth.aspx"); return; } } if (TenantStatisticsProvider.IsNotPaid() && !(this is Auth || this is Tariffs || this is confirm)) { Response.Redirect(TenantExtra.GetTariffPageLink(), true); } else if (SecurityContext.IsAuthenticated && StudioSmsNotificationSettings.IsVisibleSettings && StudioSmsNotificationSettings.Enable && !(this is confirm || this is Auth)) { var user = CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID); if (!CoreContext.UserManager.IsUserInGroup(SecurityContext.CurrentAccount.ID, Constants.GroupAdmin.ID) && (string.IsNullOrEmpty(user.MobilePhone) || user.MobilePhoneActivationStatus == MobilePhoneActivationStatus.NotActivated)) { Response.Redirect(StudioNotifyService.GenerateConfirmUrl(user.Email, ConfirmType.PhoneActivation)); } } //check disable and public var webitem = CommonLinkUtility.GetWebItemByUrl(Request.Url.ToString()); var parentIsDisabled = false; if (webitem != null && webitem.IsSubItem()) { var parentItemID = WebItemManager.Instance.GetParentItemID(webitem.ID); parentIsDisabled = WebItemManager.Instance[parentItemID].IsDisabled(); } if (webitem != null && (webitem.IsDisabled() || parentIsDisabled) && !ExclusivePage()) { if (webitem.ID == new Guid("{F4D98AFD-D336-4332-8778-3C6945C81EA0}") && string.Equals(GetType().BaseType.FullName, "ASC.Web.People.Profile")) { Response.Redirect("~/my.aspx"); return; } Response.Redirect("~/"); return; } if (SecurityContext.IsAuthenticated) { try { StatisticManager.SaveUserVisit(TenantProvider.CurrentTenantID, SecurityContext.CurrentAccount.ID, CommonLinkUtility.GetProductID()); } catch (Exception exc) { Log.Error("failed save user visit", exc); } } PersonalHelper.TransferRequest(this); }