Beispiel #1
0
        public void SetFirstTimeTenantSettings()
        {
            var currentUser = CoreContext.UserManager.GetUsers(CurrentUser);

            if (!currentUser.IsOwner())
            {
                throw new NotSupportedException("Access Denied.");
            }

            FirstTimeTenantSettings.SetDefaultTenantSettings();
            FirstTimeTenantSettings.SendInstallInfo(currentUser);
        }
Beispiel #2
0
        private void AuthRedirect(UserInfo user, bool first, string module, string fileUri)
        {
            var wizardSettings = SettingsManager.Instance.LoadSettings <WizardSettings>(TenantProvider.CurrentTenantID);

            if (first && wizardSettings.Completed)
            {
                // wizardSettings.Completed - open source, Request["first"] - cloud
                wizardSettings.Completed = false;
                SettingsManager.Instance.SaveSettings(wizardSettings, TenantProvider.CurrentTenantID);
            }

            if (wizardSettings.Completed)
            {
                if (string.IsNullOrEmpty(module))
                {
                    Response.Redirect(CommonLinkUtility.GetDefault(), true);
                }
                else
                {
                    SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);

                    FirstTimeTenantSettings.SetDefaultTenantSettings();
                    FirstTimeTenantSettings.SendInstallInfo(user);

                    if (!string.IsNullOrEmpty(fileUri))
                    {
                        UserHelpTourHelper.IsNewUser = true;

                        var fileExt   = FileUtility.GetInternalExtension(Path.GetFileName(HttpUtility.UrlDecode(fileUri)));
                        var createUrl = FilesLinkUtility.GetFileWebEditorExternalUrl(fileUri, "Demo" + fileExt, true);
                        Response.Redirect(createUrl, true);
                    }

                    var welcomeUrl = "~/welcome.aspx?module=" + module;
                    Response.Redirect(welcomeUrl, true);
                }
            }
            else
            {
                Response.Redirect(SecurityContext.IsAuthenticated ? "~/wizard.aspx" : "~/auth.aspx", true);
            }
        }
Beispiel #3
0
        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);
        }