public static bool AnyRolesOrClaims <TUser, TKey>(this SmartUser <TUser, TKey> self, string Roles, List <Claim> Claims)
            where TKey : IEquatable <TKey>
            where TUser : IdentityUser <TKey>
        {
            var roles = Roles.Split(',');

            for (var i = 0; i < roles.Count(); i++)
            {
                roles[i] = roles[i].Trim(' ');
            }
            foreach (var r in roles)
            {
                if (self.IsInRole(r))
                {
                    return(true);
                }
            }
            foreach (var c in Claims)
            {
                if (self.HasClaim(c.Type, c.Value))
                {
                    return(true);
                }
            }
            return(false);
        }
示例#2
0
        /// <summary>
        /// Private method that converts the form data to XML
        /// </summary>
        /// <param name="vm"></param>
        /// <returns>An <see cref="XElement"/></returns>
        private XElement ViewModelToXML(PAFFormViewModel vm)
        {
            XElement root = new XElement("SmartPAF");

            PropertyInfo[] properties = typeof(PAFFormViewModel).GetProperties();
            foreach (PropertyInfo property in properties)
            {
                if (property.Name != "Components" && property.Name != "job" && property.Name != "JobList" && property.Name != "Users" && property.Name != "DocumentId" && property.Name != "PAFTypeChoices")
                {
                    root.Add(new XElement(property.Name, property.GetValue(vm), new XAttribute("id", property.Name)));
                }
            }
            SmartUser      author   = _repository.Users.FirstOrDefault(x => x.UserId == vm.AuthorUserId);
            SmartJob       smartJob = _repository.Jobs.FirstOrDefault(x => x.JobId == vm.JobId);
            JobDescription job      = new JobDescription(smartJob);

            root.Add(new XElement("AuthorName", author?.DisplayName ?? "Unknown", new XAttribute("AuthorName", author?.DisplayName ?? "Unknown")));
            XElement xJob = new XElement("JobDescription");

            xJob.Add(new XElement("ClassTitle", job.ClassTitle, new XAttribute("id", "ClassTitle")));
            xJob.Add(new XElement("WorkingTitle", job.WorkingTitle, new XAttribute("id", "WorkingTitle")));
            xJob.Add(new XElement("Grade", job.Grade, new XAttribute("id", "Grade")));
            xJob.Add(new XElement("WorkingHours", job.WorkingHours, new XAttribute("id", "WorkingHours")));
            xJob.Add(new XElement("JobId", job.SmartJobId, new XAttribute("id", "JobId")));
            root.Add(xJob);
            return(root);
        }
 public ContestExecutorFactory(OnlineJudgeContext db, SmartUser <User, Guid> user, ManagementServiceClient mgmt, IConfiguration config)
 {
     this._db     = db;
     this._user   = user;
     this._mgmt   = mgmt;
     this._config = config;
 }
示例#4
0
        /// <summary>
        /// Private method that converts the user-provided form data into the XML field of the <see cref="SmartDocument"/>.
        /// </summary>
        /// <param name="vm"></param>
        /// <returns>An <see cref="XElement"/></returns>
        private XElement ViewModelToXML(SmartAwardViewModel vm)
        {
            XElement root = new XElement("SmartAward");

            PropertyInfo[] properties;
            switch (vm.SelectedAward)
            {
            case 1:
                properties = typeof(GoodConductAwardViewModel).GetProperties();
                break;

            case 2:
                properties = typeof(OutstandingPerformanceAwardViewModel).GetProperties();
                break;

            default:
                throw new NotImplementedException("The Viewmodel has an unrecognized SelectedAwardType");
            }

            root.Add(new XElement("DocumentId", awardForm?.DocumentId ?? vm.DocumentId, new XAttribute("DocumentId", awardForm?.DocumentId ?? vm.DocumentId)));
            foreach (PropertyInfo property in properties)
            {
                if (property.Name != "DocumentId" && property.Name != "Components" && property.Name != "Users" && property.Name != "AwardList" && property.Name != "Components" && property.Name != "Users" && property.Name != "AwardTypes")
                {
                    root.Add(new XElement(property.Name, property.GetValue(vm), new XAttribute("id", property.Name)));
                }
            }
            SmartUser author = _repository.Users.FirstOrDefault(x => x.UserId == vm.AuthorUserId);

            root.Add(new XElement("AuthorName", author?.DisplayName ?? "Unknown", new XAttribute("AuthorName", author?.DisplayName ?? "Unknown")));
            XElement award = new XElement("AwardType");

            return(root);
        }
        public IActionResult Create([Bind("UserId,BlueDeckId,LogonName,DisplayName")] SmartUser smartUser)
        {
            // check if POSTed data is valid
            if (ModelState.IsValid)
            {
                _repo.SaveUser(smartUser);

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Title"] = "Create User: Error";
            return(View(smartUser));
        }
        public static bool AnyRolesOrClaims <TUser, TKey>(this SmartUser <TUser, TKey> self, string Roles, string Types, string Value)
            where TKey : IEquatable <TKey>
            where TUser : IdentityUser <TKey>
        {
            var tmp    = Types.Split(',');
            var claims = new List <Claim>();

            foreach (var c in tmp)
            {
                claims.Add(new Claim(c.Trim(' '), Value));
            }
            return(self.AnyRolesOrClaims(Roles, claims));
        }
示例#7
0
        /// <summary>
        /// Private method that converts the form data to XML
        /// </summary>
        /// <param name="vm"></param>
        /// <returns>An <see cref="XElement"/></returns>
        private XElement ViewModelToXML(PPAFormViewModel vm)
        {
            XElement root = new XElement("SmartPPA");

            PropertyInfo[] properties = typeof(PPAFormViewModel).GetProperties();
            foreach (PropertyInfo property in properties)
            {
                if (property.Name != "Categories" && property.Name != "Components" && property.Name != "job" && property.Name != "JobList" && property.Name != "Users" && property.Name != "DocumentId")
                {
                    root.Add(new XElement(property.Name, property.GetValue(vm), new XAttribute("id", property.Name)));
                }
            }
            SmartUser author = _repository.Users.FirstOrDefault(x => x.UserId == vm.AuthorUserId);

            root.Add(new XElement("AuthorName", author?.DisplayName ?? "Unknown", new XAttribute("AuthorName", author?.DisplayName ?? "Unknown")));
            XElement job = new XElement("JobDescription");

            job.Add(new XElement("ClassTitle", vm.Job.ClassTitle, new XAttribute("id", "ClassTitle")));
            job.Add(new XElement("WorkingTitle", vm.Job.WorkingTitle, new XAttribute("id", "WorkingTitle")));
            job.Add(new XElement("Grade", vm.Job.Grade, new XAttribute("id", "Grade")));
            job.Add(new XElement("WorkingHours", vm.Job.WorkingHours, new XAttribute("id", "WorkingHours")));
            job.Add(new XElement("JobId", vm.Job.SmartJobId, new XAttribute("id", "JobId")));


            XElement categories = new XElement("Categories", new XAttribute("id", "Categories"));

            foreach (JobDescriptionCategory c in vm.Job.Categories)
            {
                XElement category = new XElement("Category", new XAttribute("id", "Category"));
                category.Add(new XElement("Letter", c.Letter, new XAttribute("id", "Letter")));
                category.Add(new XElement("Weight", c.Weight, new XAttribute("id", "Weight")));
                category.Add(new XElement("Title", c.Title, new XAttribute("id", "Title")));
                category.Add(new XElement("SelectedScore", c.SelectedScore, new XAttribute("id", "SelectedScore")));
                XElement positionDescriptionFields = new XElement("PositionDescriptionFields", new XAttribute("id", "PositionDescriptionFields"));
                foreach (PositionDescriptionItem p in c.PositionDescriptionItems)
                {
                    positionDescriptionFields.Add(new XElement("PositionDescriptionItem", p.Detail));
                }
                category.Add(positionDescriptionFields);
                XElement performanceStandardFields = new XElement("PerformanceStandardFields", new XAttribute("id", "PerformanceStandardFields"));
                foreach (PerformanceStandardItem p in c.PerformanceStandardItems)
                {
                    performanceStandardFields.Add(new XElement("PerformanceStandardItem", p.Detail, new XAttribute("initial", p.Initial)));
                }
                category.Add(performanceStandardFields);
                categories.Add(category);
            }
            job.Add(categories);
            root.Add(job);
            return(root);
        }
        public IActionResult Edit(int id)
        {
            // retrieve the SmartUser from the repo
            SmartUser smartUser = _repo.Users.FirstOrDefault(x => x.UserId == id);

            if (smartUser == null)
            {
                // no SmartUser with the given id exists in the repo
                return(NotFound());
            }
            // return the view
            ViewData["Title"] = "Edit User";
            ViewData["ActiveNavBarMenuLink"] = "Edit User";
            return(View(smartUser));
        }
        public IActionResult Edit(int id, [Bind("UserId,DisplayName")] SmartUser smartUser)
        {
            // if querystring id doesn't match the POSTed form UserId
            if (id != smartUser.UserId)
            {
                return(NotFound());
            }

            // validate model state
            if (ModelState.IsValid)
            {
                // invoke the repo method to save the user
                _repo.SaveUser(smartUser);
                return(RedirectToAction("Choices", "Home"));
            }
            // modelstate invalid, return the view with the VM with validation errors showing
            ViewData["Title"] = "Edit User: Error";
            ViewData["ActiveNavBarMenuLink"] = "Edit User";
            return(View(smartUser));
        }
示例#10
0
        //需要调用窗体名称
        System.Windows.Forms.Control INetUserControl.CreateControl(UFSoft.U8.Framework.Login.UI.clsLogin login, string MenuID, string Paramters)
        {
            //UFSoft.U8.Framework.LoginContext.UserData LoginInfo = new UFSoft.U8.Framework.LoginContext.UserData();
            //LoginInfo = login.GetLoginInfo();
            //string conn = LoginInfo.ConnString;
            //conn = Utils.ConvertConn(conn);
            //DbHelperSQL.connectionString = conn;

            //string sLogUserid = LoginInfo.UserId;
            //string sLogUserName = LoginInfo.UserName;
            //string sLogDate = LoginInfo.operDate;
            //string sAccID = LoginInfo.AccID;

            UFSoft.U8.Framework.LoginContext.UserData LoginInfo = new UFSoft.U8.Framework.LoginContext.UserData();
            LoginInfo = login.GetLoginInfo();
            string conn = LoginInfo.ConnString;

            conn = Utils.ConvertConn(conn);
            DbHelperSQL.connectionString = conn;

            string sLogUserid   = LoginInfo.UserId;
            string sLogUserName = LoginInfo.UserName;
            string sLogDate     = LoginInfo.operDate;
            string sAccID       = LoginInfo.AccID;

            bool bRight = false;

            if (sLogUserid.ToLower() == "demo")
            {
                bRight = true;
            }
            else
            {
                string    sSQL = "select * from _UserRight where UserID = '" + sLogUserid + "' and FormID = '1000'";
                DataTable dt   = DbHelperSQL.Query(sSQL);
                if (dt != null && dt.Rows.Count > 0 && dt.Rows[0][0].ToString().Trim() != "")
                {
                    bRight = true;
                }
            }

            if (!bRight)
            {
                throw new Exception("没有权限");
                //return null;
            }
            else
            {
                SmartUser fm = new SmartUser();

                fm.Conn      = conn;
                fm.sUserID   = sLogUserid;
                fm.sUserName = sLogUserName;
                fm.sLogDate  = sLogDate;



                this._Title = "采集器操作员设置";

                return(fm);
            }
        }
示例#11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:SmartDocs.Models.Types.UserListItem"/> class.
 /// </summary>
 /// <remarks>
 /// Constructor that takes a <see cref="T:SmartDocs.Models.SmartUser"/> parameter.
 /// </remarks>
 /// <param name="user">The user.</param>
 public UserListItem(SmartUser user)
 {
     UserId      = user.UserId;
     DisplayName = user.DisplayName;
 }
示例#12
0
 public OnlineJudgeHub(SmartUser <User, Guid> user)
 {
     _user = user;
 }