Esempio n. 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        this.LanguageSelector1.LanguageChanged += new EventHandler(LanguageSelector_LanguageChanged);

        viewingPerson = Person.FromIdentity(Int32.Parse(HttpContext.Current.User.Identity.Name));
        Authority authority = viewingPerson.GetAuthority();

        RadMenu MainMenu = FindControl("MainMenu") as RadMenu;

        Dictionary <string, bool> enableCache = new Dictionary <string, bool>();

        if (Session["MainMenu-v4_Enabling"] != null &&
            PermissionCacheTimestamp.AddSeconds(10) > DateTime.Now &&
            Authorization.lastReload < PermissionCacheTimestamp)
        {
            enableCache = Session["MainMenu-v4_Enabling"] as Dictionary <string, bool>;
        }
        else
        {
            PermissionCacheTimestamp = DateTime.Now;
        }


        Authorization.flagReload = false;
        RadMenuItemCollection menuItems = MainMenu.Items;

        SetupMenuItemsEnabling(authority, enableCache, menuItems);
        Session["MainMenu-v4_Enabling"] = enableCache;

        if (this.Page is PageV4Base)
        {
            bool CurrentPageAccess = false;
            if (((PageV4Base)this.Page).pagePermissionDefault != null)
            {
                CurrentPageAccess = Authorization.CheckAuthorization(((PageV4Base)this.Page).pagePermissionDefault, -1, -1, authority, Authorization.Flag.AnyGeographyAnyOrganization);
            }

            if ((CurrentPageAccess == false && CurrentPageAllowed == false) || CurrentPageProhibited)
            {
                this.AccessDeniedPanel.Visible = true;
                if (CurrentPageAccess == false)
                {
                    this.LabelFailedPermission.Text = (((PageV4Base)this.Page).pagePermissionDefault).ToString();
                }
                else if (CurrentPageProhibited)
                {
                    this.LabelFailedPermission.Text = "CurrentPageProhibited";
                }

                this.BodyContent.Visible = false;
            }
            else
            {
                this.AccessDeniedPanel.Visible = false;
                this.BodyContent.Visible       = true;
            }
        }
    }
Esempio n. 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // Event subscriptions

            // this.LanguageSelector.LanguageChanged += new EventHandler(LanguageSelector_LanguageChanged);

            // Titles and other page elements

            this.IconPage.ImageUrl   = "/Images/PageIcons/" + this.CurrentPageIcon + "-40px.png";
            this.LabelPageTitle.Text = this.CurrentPageTitle;
            this.Page.Title          = "Swarmops - " + this.CurrentPageTitle;

            this.LiteralSidebarInfo.Text = this.CurrentPageInfoBoxLiteral;

            // Set logo image. If custom image is installed, use it instead.

            this.ImageLogo.ImageUrl = "~/Images/Logo-Stock.png";
            if (File.Exists(Server.MapPath("~/Images/Logo-Custom.png")))
            {
                this.ImageLogo.ImageUrl = "~/Images/Logo-Custom.png";
            }

            // Check for SSL and force it

            // Special case for CloudFlare deployments - there is a case where somebody will get their connections de-SSLed at the server

            string cloudFlareVisitorScheme = Request.Headers["CF-Visitor"];
            bool   cloudFlareSsl           = false;

            if (!string.IsNullOrEmpty(cloudFlareVisitorScheme))
            {
                if (cloudFlareVisitorScheme.Contains("\"scheme\":\"https\""))
                {
                    cloudFlareSsl = true;
                }
            }

            // TODO: Same thing for Pound deployments

            // Rewrite if applicable

            if (Request.Url.ToString().StartsWith("http://") && !cloudFlareSsl) // only check client-side as many server sites de-SSL the connection before reaching the web server
            {
                if (!Request.Url.ToString().StartsWith("http://dev.swarmops.com/") && !Request.Url.ToString().StartsWith("http://sandbox.swarmops.com") && !Request.Url.ToString().StartsWith("http://localhost:") && !Request.Url.ToString().StartsWith("http://swarmops-"))
                {
                    Response.Redirect(Request.Url.ToString().Replace("http:", "https:"));

                    // Only force this if set to force it in database
                    // TODO: Make admin init task
                }
            }

            Localize();

            this.LabelCurrentUserName.Text         = _currentUser.Name;
            this.LabelCurrentOrganizationName.Text = _currentOrganization.Name;

            this.LabelActionPlaceholder1.Text = "Action shortcut 1 (TODO)";
            this.LabelActionPlaceholder2.Text = "Action shortcut 2 (TODO)";
            this.LabelNoTodoItems.Text        = "No Action Items (LOC)";

            // Set up todo items

            DashboardTodos todos = DashboardTodos.ForPerson(_currentUser, _currentOrganization);

            this.RepeaterTodoItems.DataSource = todos;
            this.RepeaterTodoItems.DataBind();
            this.LabelNoTodoItems.Visible = (todos.Count == 0);

            // Set up main menu

            // RadMenu mainMenu = FindControl("MainMenu") as RadMenu;

            Dictionary <string, bool> enableCache = new Dictionary <string, bool>();

            if (Session["MainMenu-v4_Enabling"] != null &&
                PermissionCacheTimestamp.AddSeconds(10) > DateTime.Now &&
                Authorization.lastReload < PermissionCacheTimestamp)
            {
                enableCache = Session["MainMenu-v4_Enabling"] as Dictionary <string, bool>;
            }
            else
            {
                PermissionCacheTimestamp = DateTime.Now;
            }

            SetupMenuItems();

            Authorization.flagReload = false;
            // SetupMenuItemsEnabling(authority, enableCache, menuItems);
            Session["MainMenu-v4_Enabling"] = enableCache;

            this.ImageCultureIndicator.Style[HtmlTextWriterStyle.MarginTop]   = "3px";
            this.ImageCultureIndicator.Style[HtmlTextWriterStyle.MarginRight] = "3px";
            this.ImageCultureIndicator.Style[HtmlTextWriterStyle.Cursor]      = "pointer";

            SetupDropboxes();

            this.ButtonSwitchOrganizations.Attributes.Add("onclick", "$('#" + this.TextSwitchToOrganizationId.ClientID + "').val($('#" + this.DropSwitchOrganizations.ClientID + "').val()); $('#" + this.ButtonActuatorSwitchOrganizations.ClientID + "').click();");

            // Check for message to display

            HttpCookie dashMessage = Request.Cookies["DashboardMessage"];

            if (dashMessage != null && dashMessage.Value.Length > 0)
            {
                this.LiteralDocumentReadyHook.Text = string.Format("alertify.alert(unescape('{0}'.replace(/\\+/g, '%20')));", dashMessage.Value);
                Response.SetCookie(new HttpCookie("DashboardMessage", string.Empty));
                Response.Cookies ["DashboardMessage"].Expires = DateTime.Now.AddYears(-10);
            }
            else
            {
                this.LiteralDocumentReadyHook.Text = string.Empty;
            }
        }