コード例 #1
0
ファイル: UserControlBase.cs プロジェクト: kenstammjr/SPA
        protected virtual void Page_Load(object sender, EventArgs e)
        {
            try {
                if (Context.User.Identity.Name != null)
                {
                    CurrentUser           = new SPA.User(Context.User.Identity.Name);
                    CurrentUserWithDomain = CurrentUser.UserName; // string.Format("{0}\\{1}", CurrentUser.Domain.StripClaim(), CurrentUser.UserName);
                    IsAdmin   = CurrentUser.InRole(RoleType.Administrator.ToString());
                    IsManager = CurrentUser.InRole(RoleType.Manager.ToString());
                }
                else
                {
                    IsAnonymous = true;
                }

                ReadParameters();

                if (!IsAnonymous)
                {
                    SPA.User user = new SPA.User(CurrentUserWithDomain);
                }
            } catch (Exception ex) {
                SPA.Error.WriteError(ex);
            }
        }
コード例 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            this.TopNavigationMenu.Visible = false;
            try {
                SPA.User user    = new SPA.User(Context.User.Identity.Name);
                bool     IsAdmin = user.InRole(RoleType.Administrator.ToString());
                DataSet  ds      = new DataSet();
                if (IsAdmin)
                {
                    ds = Tab.ActiveItems(true);
                }
                else
                {
                    ds = Tab.ActiveItems(false);
                }

                DataView dv = new DataView();
                dv.Table     = ds.Tables[0];
                dv.Sort      = "DisplayIndex";
                dv.RowFilter = "ParentID = 0";
                foreach (DataRowView drv in dv)
                {
                    MenuItem menuItem = new MenuItem();
                    menuItem.Text        = drv["Name"].ToString();
                    menuItem.Value       = drv["ID"].ToString();
                    menuItem.NavigateUrl = drv["URL"].ToString();
                    this.TopNavigationMenu.Items.Add(menuItem);
                    this.TopNavigationMenu.Attributes.Add("padding-right", "15px");
                    AddChildItems(ds.Tables[0], menuItem);
                }
                this.TopNavigationMenu.Visible = true;
            } catch (Exception ex) {
                SPA.Error.WriteError(ex);
            }
        }
コード例 #3
0
        public static DataTable Items(int CurrentUserID)
        {
            //Action.Write(string.Format("TrngModule CurrentUserID: {0}", CurrentUserID), "debug");

            DataTable dt = new DataTable();

            SPA.User user              = new SPA.User(CurrentUserID);
            bool     IsTrngAdmin       = user.InRole("TrngAdmin");
            bool     IsOrgAdmin        = User.HasOrgRole("Administrator", user.ID);
            bool     IsTrngOrgAdmin    = User.HasOrgRole("TrngAdmin", user.ID);
            bool     IsTrngCourseAdmin = TrngCourseAdmin.IsAdmin(user.ID);

            using (new Impersonator()) {
                SqlConnection conn = DataSource.Conn();
                try {
                    string sql = string.Empty;

                    if (IsTrngAdmin)
                    {
                        sql = "SELECT * FROM dbo.TrngModules order by displayindex, name ";
                    }
                    else if (IsTrngOrgAdmin || IsOrgAdmin)
                    {
                        sql = "SELECT * FROM dbo.TrngModules where OrgAdmin = 1 or admin = 0 order by displayindex, name ";
                    }
                    else if (IsTrngCourseAdmin)
                    {
                        sql = "SELECT * FROM dbo.TrngModules where CourseAdmin = 1  or admin = 0 order by displayindex, name ";
                    }
                    else if (IsTrngOrgAdmin && IsTrngCourseAdmin)
                    {
                        sql = "SELECT * FROM dbo.TrngModules where CourseAdmin = 1  or OrgAdmin = 1 or admin = 0 order by displayindex, name ";
                    }
                    else
                    {
                        sql = "SELECT * FROM dbo.TrngModules where admin = 0 order by displayindex, name ";
                    }


                    SqlCommand     cmd = new SqlCommand(sql, conn);
                    SqlDataAdapter da  = new SqlDataAdapter(cmd);
                    da.Fill(dt);
                } catch (SqlException sqlex) {
                    Error.WriteError(sqlex);
                } catch (Exception ex) {
                    Error.WriteError(ex);
                } finally {
                    if (conn.State != ConnectionState.Closed)
                    {
                        conn.Close();
                    }
                }
            }
            return(dt);
        }
コード例 #4
0
ファイル: Errors.cs プロジェクト: kenstammjr/SPA
        public static bool ShowError(string ContextUserIdentityName)
        {
            bool show = false;

            SPA.User user = new SPA.User(ContextUserIdentityName);
            if (user.InRole(RoleType.Manager.ToString()))
            {
                show = true;
            }
            return(show);
        }
コード例 #5
0
        /// <summary>
        /// Handles page load and initializes ViewState variables
        /// </summary>
        protected virtual void Page_Load(object sender, EventArgs e)
        {
            try {
                if (Context.User.Identity.Name != null)
                {
                    CurrentUser           = new SPA.User(Context.User.Identity.Name);
                    CurrentUserADUserID   = CurrentUser.ADObjectGuid;
                    CurrentUserWithDomain = CurrentUser.UserName;
                    IsAdmin             = CurrentUser.InRole(RoleType.Administrator.ToString());
                    IsManager           = CurrentUser.InRole(RoleType.Manager.ToString());
                    IsUserAdmin         = CurrentUser.InRole(RoleType.UserAdmin.ToString());
                    IsTrngAdmin         = CurrentUser.InRole(RoleType.TrngAdmin.ToString());
                    IsMonitoringAdmin   = CurrentUser.InRole("MonitoringAdmin");
                    IsMonitoringAuditor = CurrentUser.InRole("MonitoringAuditor");
                }
                else
                {
                    IsAnonymous = true;
                }
                //if (IsManager) {
                if (!IsPostBack && !new Framework().IsDatabaseCurrent)
                {
                    Response.Redirect(string.Format("{0}/{1}", this.Web.Url, Pages.DBUtility.PAGE_URL), false);
                    return;
                }
                //}

                ReadParameters();
            } catch (Exception ex) {
                SPA.Error.WriteError(ex);
            }
        }
コード例 #6
0
ファイル: Data.cs プロジェクト: kenstammjr/SPA
        public List <TreeViewNode> Nodes(string root)
        {
            CurrentUser = new SPA.User(Context.User.Identity.Name);
            bool IsAdmin = CurrentUser.InRole(Role.RoleType.Administrator.ToString());

            // on first load, root will be 0. on subsequent requests, root will be the id of the selected tree node
            int nodeId = (root == "source") ? 0 : Int32.Parse(root.ToString());
            int menuId = int.Parse(HttpContext.Current.Request.QueryString["menuid"].ToString());

            // everything
            string URL    = HttpContext.Current.Request.Url.ToString();
            string RawURL = HttpContext.Current.Request.RawUrl;

            RawURL = RawURL.Replace("/~", "");
            URL    = URL.Replace(RawURL, "");

            DataSet  dsItems = new DataSet();
            MenuNode node    = null;

            // on first load, get root (parent) nodes. On subsequet requests, get children nodes
            dsItems = nodeId == 0 ? MenuNode.Items(menuId, nodeId, true) : MenuNode.Items(menuId, nodeId, true);

            List <TreeViewNode> nodes = new List <TreeViewNode>();

            foreach (DataRow child in dsItems.Tables[0].Rows)
            {
                node = new MenuNode(int.Parse(child["ID"].ToString()));
                bool   leaf     = !node.HasChildren;
                string editLink = string.Format("{0}/_layouts/spa/pages/menunodeitem.aspx?View=Edit&ID={1}&MenuID={2}&ParentID={3}", URL, node.ID.ToString(), menuId.ToString(), node.ParentID.ToString());
                string treeText = string.Format("<a href=\"{0}\" class=\"navmenulink\" title=\"{1}\" onmouseover=\"mopen('n{2}')\" onmouseout=\"mclosetime()\">{3}</a>&nbsp;&nbsp;<a id=\"n{4}\" title='Click to report as a bad link' onmouseover=\"mcancelclosetime()\" onmouseout=\"mclosetime()\" class=\"navmenunodeedit\" href=\"javascript:ModalOpen('{5}', 'Report Node', true);\">[report]</a>", node.URL, node.Description, node.ID.ToString(), node.Name, node.ID.ToString(), editLink);
                if (IsAdmin)
                {
                    treeText = string.Format("<a href=\"{0}\" class=\"navmenulink\" title=\"{1}\" onmouseover=\"mopen('n{2}')\" onmouseout=\"mclosetime()\">{3}</a>&nbsp;&nbsp;<a id=\"n{4}\" title='Edit item' onmouseover=\"mcancelclosetime()\" onmouseout=\"mclosetime()\" class=\"navmenunodeedit\" href=\"javascript:ModalOpen('{5}', 'Edit Node', true);\">[edit]</a>", node.URL, node.Description, node.ID.ToString(), node.Name, node.ID.ToString(), editLink);
                }
                nodes.Add(new TreeViewNode()
                {
                    id          = node.ID.ToString(),
                    url         = node.URL,
                    text        = treeText,
                    hasChildren = node.HasChildren,
                    target      = node.Target,
                    classes     = leaf ? "file" : "folder",
                });
            }
            return(nodes);
        }
コード例 #7
0
        protected override void Fill()
        {
            try {
                tblList.Visible = true;
                tblItem.Visible = false;

                // determine the user identity
                SPA.User user = new SPA.User(Context.User.Identity.Name);
                UserID = user.ID;

                // determine user role
                if (user.InRole("Manager"))
                {
                    // do something
                }

                // determine if new drive was clicked from server item ribbon
                if (Request["addcert"] != null)
                {
                    hfItemID.Value    = "0";
                    btnDelete.Visible = false;
                    FillItem("Edit", 0);
                }

                DataView dv = new DataView(Certificate.Items(ServerID).Tables[0]);
                gvData.EmptyDataText = "No certificates to display";
                gvData.DataSource    = dv;
                gvData.DataBind();
                gvData.Width = Unit.Percentage(50);
            } catch (Exception ex) {
                SPA.Error.WriteError(ex);
                if (ShowDebug)
                {
                    lblErrorMessage.Text = ex.ToString();
                }
            }
        }
コード例 #8
0
ファイル: Debug.aspx.cs プロジェクト: kenstammjr/SPA
        /// <summary>
        /// Builds and adds values we need
        /// </summary>
        protected override void Fill()
        {
            Label lblBanner = (Label)this.FindControl("lblBanner");

            lblBanner.Text = "Test";
            //using (new Impersonator()) {
            //    SPSecurity.RunWithElevatedPrivileges(delegate () {
            //        SPFarm farm = SPFarm.Local;

            //        foreach (SPService objService in farm.Services) {
            //            if (objService is SPWebService) {
            //                SPWebService oWebService = (SPWebService)objService;
            //                foreach (SPWebApplication webApp in oWebService.WebApplications) {
            //                    foreach (SPSite site in webApp.Sites) {
            //                        foreach (SPWeb web in site.AllWebs) {
            //                            test.Text += string.Format("{0}<br>", web.Url);
            //                            web.Dispose();
            //                        }
            //                        site.Dispose();
            //                    }
            //                }
            //            }
            //        }
            //    });
            //}


            valuesToNote = new List <string>();

            valuesToNote.Add("DateTime.Now = " + DateTime.Now);
            valuesToNote.Add("DateTime.UtcNow = " + DateTime.UtcNow);
            valuesToNote.Add("SPContext.Current.Web.Url = " + SPContext.Current.Web.Url);
            valuesToNote.Add("SPContext.Current.Site.Url = " + SPContext.Current.Site.Url);
            valuesToNote.Add("ServerName = " + System.Environment.MachineName);

            HttpContext context = HttpContext.Current;

            valuesToNote.Add("HttpContext.Current.Request.Url.Scheme = " + context.Request.Url.Scheme);
            valuesToNote.Add("HttpContext.Current.Request.Url.Host = " + context.Request.Url.Host);
            valuesToNote.Add("HttpContext.Current.Request.ApplicationPath = " + context.Request.ApplicationPath);
            valuesToNote.Add("HttpContext.Current.Request.Browser.Version = " + context.Request.Browser.Version);
            valuesToNote.Add("HttpContext.Current.Request.Browser.Browser = " + context.Request.Browser.Browser);
            valuesToNote.Add("HttpContext.Current.Request.RawUrl = " + context.Request.RawUrl);
            valuesToNote.Add("HttpContext.Current.Request.AbsoluteUri = " + context.Request.Url.AbsoluteUri);
            valuesToNote.Add("HttpContext.Current.Request.AbsolutePath = " + context.Request.Url.AbsolutePath);
            valuesToNote.Add("HttpContext.Current.User.Identity.Name = " + HttpContext.Current.User.Identity.Name);

            string CleanIdentity = HttpContext.Current.User.Identity.Name.Replace("i:0#.w|", "").Replace("0#.w|", "");

            valuesToNote.Add("Clean Identity Name from HttpContext.Current.User.Identity.Name = " + CleanIdentity);

            valuesToNote.Add("SPContext.Current.Web.CurrentUser.LoginName = " + SPContext.Current.Web.CurrentUser.LoginName);
            valuesToNote.Add("SPContext.Current.Web.CurrentUser.Email = " + SPContext.Current.Web.CurrentUser.Email);
            valuesToNote.Add("SPContext.Current.Web.CurrentUser.ID = " + SPContext.Current.Web.CurrentUser.ID);
            valuesToNote.Add("SPContext.Current.Web.CurrentUser.Name = " + SPContext.Current.Web.CurrentUser.Name);
            valuesToNote.Add("SPContext.Current.Web.CurrentUser.Sid = " + SPContext.Current.Web.CurrentUser.Sid);

            try {
                valuesToNote.Add("--- SPA User Object ---");
                SPA.User currentUser = new SPA.User(Context.User.Identity.Name);
                valuesToNote.Add("User.ID = " + currentUser.ID.ToString());
                valuesToNote.Add("User.ADUserID = " + currentUser.ADObjectGuid);
                valuesToNote.Add("User.UserName = "******"User.Roles = " + currentUser.Roles);
                valuesToNote.Add("Role (Administrator) = " + currentUser.InRole("Administrator").ToString());
                valuesToNote.Add("Role (TrngAdmin) = " + currentUser.InRole("TrngAdmin").ToString());
                valuesToNote.Add("Role (Administrator, 2) orggroup 2 = " + currentUser.InRole("Administrator", 2).ToString());
                valuesToNote.Add("Role (TrngAdmin, 2) orggroup 2 = " + currentUser.InRole("TrngAdmin", 2).ToString());
                valuesToNote.Add("***************************");
                valuesToNote.Add("***************************");
            } catch (Exception ex) {
                valuesToNote.Add("Error Occcured: " + ex.Message);
            }

            //Person Picker results will be at the bottom
            if (spePickUser.ResolvedEntities.Count > 0)
            {
                foreach (PickerEntity entity in spePickUser.ResolvedEntities)
                {
                    valuesToNote.Add("--- SPA User Object ---");
                    valuesToNote.Add("entity.DisplayText = " + entity.DisplayText);
                    valuesToNote.Add("entity.Description = " + entity.Description);
                    valuesToNote.Add("entity.EntityType = " + entity.EntityType);
                    valuesToNote.Add("entity.IsResolved.ToString() = " + entity.IsResolved.ToString());
                    valuesToNote.Add("entity.Key = " + entity.Key);
                    valuesToNote.Add("entity.ProviderName = " + entity.ProviderName);
                    valuesToNote.Add("entity.Claim.Value = " + entity.Claim.Value);
                    valuesToNote.Add("entity.Claim.Value.Substring(0, entity.Claim.Value.LastIndexOf(@\"\\\")) = " + entity.Claim.Value.Substring(0, entity.Claim.Value.LastIndexOf(@"\")));
                    valuesToNote.Add("entity.Claim.Value.Substring((entity.Claim.Value.LastIndexOf(@\"\\\") + 1))) = " + entity.Claim.Value.Substring((entity.Claim.Value.LastIndexOf(@"\") + 1)));
                    SPA.User lookupUser = new SPA.User(entity.Claim.Value);
                    valuesToNote.Add("User.ID = " + lookupUser.ID.ToString());
                    valuesToNote.Add("User.ADUserID = " + lookupUser.ADObjectGuid);
                    valuesToNote.Add("User.UserName = "******"User.Roles = " + lookupUser.Roles);
                    valuesToNote.Add("Role (Administrator) = " + lookupUser.InRole("Administrator").ToString());
                    valuesToNote.Add("Role (TrngAdmin) = " + lookupUser.InRole("TrngAdmin").ToString());
                    valuesToNote.Add("Role (MonitoringAdmin) = " + lookupUser.InRole("MonitoringAdmin").ToString());
                    valuesToNote.Add("Role (MonitoringAuditor) = " + lookupUser.InRole("MonitoringAuditor").ToString());
                    valuesToNote.Add("Role (Administrator, 2) orggroup 2 = " + lookupUser.InRole("Administrator", 2).ToString());
                    valuesToNote.Add("Role (TrngAdmin, 2) orggroup 2 = " + lookupUser.InRole("TrngAdmin", 2).ToString());
                    valuesToNote.Add(string.Format("HasOrgRole(`Administrator`, {0}) = {1}", lookupUser.ID, SPA.User.HasOrgRole("Administrator", lookupUser.ID)));
                    valuesToNote.Add(string.Format("HasOrgRole(`TrngAdmin`, {0}) = {1}", lookupUser.ID, SPA.User.HasOrgRole("TrngAdmin", lookupUser.ID)));



                    //valuesToNote.Add("lookupUser.InRole(`TrngAdmin`) = " + lookupUser.InRole("TrngAdmin").ToString());
                    //valuesToNote.Add("SPA.User.InRole(`TrngAdmin`, lookupUser.ID) = " + lookupUser.InRole("TrngAdmin", lookupUser.ID).ToString());
                    //valuesToNote.Add("SPA.User.InRole(`Administrator`, lookupUser.ID) = " + lookupUser.InRole("Administrator").ToString());
                    //valuesToNote.Add("TrngCourseAdmin.IsAdmin(lookupUser.ID)= " + TrngCourseAdmin.IsAdmin(lookupUser.ID).ToString());

                    valuesToNote.Add("***************************");
                }
            }
        }
コード例 #9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int RecordID = 0;

            SPA.User currentUser = new SPA.User(Context.User.Identity.Name);
            bool     IsTrngAdmin = currentUser.InRole(RoleType.TrngAdmin.ToString());

            foreach (string name in Request.QueryString.AllKeys)
            {
                string value = Request.QueryString[name].ToString();
                if (!string.IsNullOrEmpty(value))
                {
                    switch (name.ToLower())
                    {
                    case "recordid":
                        RecordID = int.Parse(value);
                        break;
                    }
                }
            }
            if (RecordID > 0)
            {
                SPA.TrngRecord selectedRecord = new SPA.TrngRecord(RecordID);
                if (selectedRecord.ID != 0)
                {
                    // you must be a training administrator to print another users certificate
                    if (selectedRecord.UserID == currentUser.ID || IsTrngAdmin)
                    {
                        SPA.User         selectedUser     = new SPA.User(selectedRecord.UserID);
                        SPA.TrngCourse   selectedCourse   = new SPA.TrngCourse(selectedRecord.CourseID);
                        SPA.TrngCategory selectedCategory = new TrngCategory(selectedCourse.TrngCategoryID);

                        lblUserName.Text      = selectedUser.DisplayName;
                        lblCourseName.Text    = selectedCourse.Name;
                        lblDateCompleted.Text = selectedRecord.DateCompleted.ToLongDateString();

                        if (selectedCategory.Name.ToLower() == "sap")
                        {
                            imgSAPCertTop.Visible = true;
                        }
                        else
                        {
                            imgCertTop.Visible = true;
                        }
                    }
                    else
                    {
                        contentarea.Visible  = false;
                        lblErrorMessage.Text = "You are not authorized to print this user certificate!";
                    }
                }
                else
                {
                    contentarea.Visible  = false;
                    lblErrorMessage.Text = "Training record not found!";
                }
            }
            else
            {
                contentarea.Visible  = false;
                lblErrorMessage.Text = "Training record not found!";
            }
        }