Ejemplo n.º 1
0
        public override void ToProlog()
        {
            var effects    = FluentParser.GetConditions(Effects);
            var conditions = FluentParser.GetConditions(Conditions);

            AdeSystem.PrologEngine.AssertFact("causes(" + ActionName.ToLower() + ", epsilon, [" + effects.ToLower() + "], [" + conditions.ToLower() + "])");
        }
Ejemplo n.º 2
0
        private void SaveOrUpdate()
        {
            NoteValidator validator        = new NoteValidator();
            var           validationResult = validator.Validate(Note);

            if (validationResult.IsValid)
            {
                if (ActionName.Equals("Save"))
                {
                    Note note = new Note
                    {
                        Title       = Note.Title,
                        Content     = Note.Content,
                        CreatedDate = DateTime.Now,
                        UpdatedDate = DateTime.Now,
                        UserId      = _loggedInUser.Id
                    };

                    UnitOfWork.Notes.Add(note);
                }
                else
                {
                    Note foundNote = UnitOfWork.Notes.SingleOrDefault(n => n.Id == Note.Id);

                    foundNote.Title       = Note.Title;
                    foundNote.Content     = Note.Content;
                    foundNote.UpdatedDate = DateTime.Now;
                }

                if (UnitOfWork.Complete() > 0)
                {
                    MessageBox.Show($"Note Title: '{Note.Title}' {ActionName.ToLower()}d.", $"Note {ActionName}", MessageBoxButton.OK, MessageBoxImage.Information);
                    NavigateNotesPage();
                }
                else
                {
                    ErrorText = $"Note could not {ActionName.ToLower()}d.";
                }
            }
            else
            {
                // show first error message
                ErrorText = validationResult.Errors[0].ErrorMessage;
            }
        }
Ejemplo n.º 3
0
 public override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     if (string.IsNullOrEmpty(LoginInfo.AdminID))
     {
         string loginUrl = "/account/index";
         filterContext.Result = new RedirectResult(loginUrl);
     }
     else
     {
         if (string.IsNullOrWhiteSpace(ControllerName))
         {
             ControllerName = filterContext.RouteData.Values["controller"].ToString();
         }
         if (string.IsNullOrWhiteSpace(ActionName))
         {
             ActionName = filterContext.RouteData.Values["action"].ToString();
         }
         //判断权限
         string[] columns =
         {
             Sys_Power.Columns.Id,
             Sys_Power.Columns.ModuleOperateID,
             Sys_Power.Columns.RoleID,
             Sys_ModuleOperate.Columns.KeyCode,
             Sys_Module.Columns.EnName
         };
         SqlQuery sq = new Select(columns).From <Sys_Power>().LeftOuterJoin(Sys_ModuleOperate.IdColumn, Sys_Power.ModuleOperateIDColumn)
                       .LeftOuterJoin(Sys_Module.IdColumn, Sys_ModuleOperate.ModuleIDColumn);
         if (ActionName.ToLower() == "index")
         {
             sq.Where(Sys_Module.Columns.EnName).IsEqualTo(ControllerName);
         }
         else
         {
             sq.Where(Sys_Module.Columns.EnName).IsEqualTo(ControllerName);
             sq.AndExpression(Sys_ModuleOperate.Columns.KeyCode).IsEqualTo(ActionName);
         }
         sq.AndExpression(Sys_Power.Columns.RoleID).IsEqualTo(LoginInfo.RoleID);
         if (sq.GetRecordCount() == 0)
         {
             filterContext.Result = new RedirectResult("/account/nopower");
         }
     }
 }
Ejemplo n.º 4
0
        public void ToProlog(List <string> executors)
        {
            var condition = "";

            if (Fluents != null && Fluents.Any())
            {
                condition = FluentParser.GetConditions(Fluents);
            }
            if (ExecutorName != null && ExecutorName.Any())
            {
                AdeSystem.PrologEngine.AssertFact("releases(" + ActionName.ToLower() + ", " + ExecutorName.ToLower() + ", [" +
                                                  Fluent.ToLower() + "], [" + condition.ToLower() + "])");
            }
            else
            {
                foreach (var executor in executors)
                {
                    AdeSystem.PrologEngine.AssertFact("releases(" + ActionName.ToLower() + ", " + executor.ToLower() + ", [" +
                                                      Fluent.ToLower() + "], [" + condition.ToLower() + "])");
                }
            }
        }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            // 如果未登录,则跳转到登录界面
            if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
            {
                filterContext.HttpContext.Response.Redirect("/Account/LogOn");
                return;
            }
            //当前登录用户的用户名
            string userName = filterContext.HttpContext.User.Identity.Name;
            //当前登录用户对象
            User user = SampleData.users.Find(u => u.UserName == userName);

            if (user != null)
            {
                //当前登录用户的角色
                Role role = SampleData.roles.Find(r => r.Id == user.RoleId);

                //获得controller:
                string controllerName = filterContext.RouteData.Values["controller"].ToString().ToLower();
                if (ActionName == null)
                {
                    ActionName = filterContext.RouteData.Values["action"].ToString();
                }


                //查询角色id
                RoleWithControllerAction roleWithControllerAction = SampleData.roleWithControllerAndAction.Find(r => r.ControllerName.ToLower() == controllerName && ActionName.ToLower() == ActionName.ToLower());
                if (roleWithControllerAction != null)
                {
                    //有权限操作当前控制器和Action的角色id
                    this.Roles = roleWithControllerAction.RoleIds;
                }
                if (!string.IsNullOrEmpty(Roles))
                {
                    foreach (string roleid in Roles.Split(','))
                    {
                        if (role.Id.ToString() == roleid)
                        {
                            //return就说明有权限了,后面的代码就不跑了,直接返回视图给浏览器就好
                            return;
                        }
                    }
                }

                filterContext.Result = new ViewResult {
                    ViewName = "Error",
                };
                return;
            }
            else
            {
                filterContext.Result = new EmptyResult();
                filterContext.HttpContext.Response.Redirect("/Account/Logon", true);
                return;
            }
        }
Ejemplo n.º 6
0
        public override void ToProlog()
        {
            var effects = FluentParser.GetConditions(Effects);

            AdeSystem.PrologEngine.AssertFact("causes(" + ActionName.ToLower() + ", " + Executor.ToLower() + ", [" + effects.ToLower() + "], [[]])");
        }
        protected override void Process()
        {
            switch (ActionName.ToLower())
            {
            case "haslogin":
                this.HasLogin();
                break;

            case "childrenusers":    //获取我的下级用户列表
                this.GetChildrenUsers();
                break;

            case "existsusercode":    //是否存在指定用户id
                this.ExistsUser();
                break;

            case "adduser":    //添加用户
                this.AddUser();
                break;

            case "getuser":    //获取单个用户信息
                this.GetUser();
                break;

            case "edituser":    //编辑用户信息
                this.EditUser();
                break;

            case "getquota":    //获取用户配额
                this.GetUserQuota();
                break;

            case "getquotamax":    //获取用户配额,配额值大于0
                this.GetUserQuotaMax();
                break;

            case "updateuserremo":    //修改用户返点
                this.UpdateUserRemo();
                break;

            case "groupuseramt":    //用户团队余额
                this.GroupUserAmt();
                break;

            case "userchildrens":
                this.GetUserChildrens();
                break;

            case "userrembparent":    //获取子用户,父用户的所有返点
                this.GetUserRembParent();
                break;

            case "updateuserquota":    //修改用户配额
                this.UpdateUserQuota();
                break;

            case "recovery":    //回收
                this.Recovery();
                break;

            case "addpoints":    //升点
                AddPoints();
                break;

            case "addpointsattribute":    //获取升点按销售额说明数据
                AppGlobal.RenderResult <List <AddPointsAttribute> >(ApiCode.Success, PointsAttributeHelper.AddPointsAttributes());
                break;

            case "updaterecharge":
                this.UpdateUserRecharge();
                break;

            case "recharge":    //给下级充值
                Recharge();
                break;

            case "quotabill":    //获取配额账变列表
                GetQuotaBill();
                break;

            case "qupotafilter":    //配额查询
                QuotaFilter();
                break;

            case "autosetting":    //自动注册返点设置
                AutoRegistSetting();
                break;

            case "updategreetings":    //修改问候语
                this.UpdateGreetings();
                break;

            case "updadwwdasp":    //修改用户密码
                this.UpdateUserPassword();
                break;

            case "updatezjmpwp":    //修改资金密码
                UpdateUserBalancePassword();
                break;

            case "inintzjp":    //初始化资金密码
                InintUserBalancePassword();
                break;

            case "vdzjp":    //验证资金密码是否正确
                VdUserBalancePassword();
                break;

            case "vdempty":    //验证资金密码是否为空
                VdUserBalanceEmptyPwd();
                break;

            case "updatenickname":    //修改昵称
                UpdateNickName();
                break;

            case "getdailybusinesstransaction":     //获取用户当天消费额
                GetDailyBusinessTransaction();
                return;

            case "fenpei":
                FenPeiQu();
                break;

            case "loginlog":
                GetUserLoginLogs();
                break;

            case "paruser":
                GetParentUserList();    //获取所有上级用户
                break;
            }
        }
Ejemplo n.º 8
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (CurrentUser != null)
            {
                var      tmpControllerName = ControllerName + "Controller";
                object[] arrObjects        = filterContext.ActionDescriptor.GetCustomAttributes(typeof(B_MenuRightsTagAttribute), false);
                if (arrObjects.Length > 0 && CurrentUser.UserName != WeConfig.robot)
                {
                    _MenuRightsTag = arrObjects[0] as B_MenuRightsTagAttribute;
                    if (_MenuRightsTag != null)
                    {
                        //如果不是主菜单则取主菜单方法名
                        string tmpActionName = _MenuRightsTag.IsMainMenu ? ActionName : _MenuRightsTag.MainMethod;
                        B_Menu menu          = B_MenuRights.GetMenu(tmpControllerName, tmpActionName);
                        string errMessage    = string.Empty;
                        if (menu != null && string.IsNullOrWhiteSpace(menu.MenuName) == false)
                        {
                            List <B_MenuRights> mrList = B_MenuRights.GetHashMenuRights(CurrentUser.UserName).FindAll(m => m.CodeOn == tmpControllerName);
                            bool isExists = false;
                            if (_MenuRightsTag.IsMainMenu)
                            {
                                isExists = mrList.Exists(m => m.MethodName == _MenuRightsTag.Name && m.MethodCode.ToLower() == ActionName.ToLower());
                            }
                            else
                            {
                                //继承主方法
                                isExists = mrList.Exists(m => m.MethodName == _MenuRightsTag.Name &&
                                                         (m.MethodCode == _MenuRightsTag.MainMethod || m.MethodCode.ToLower() == ActionName.ToLower() || m.HasInheritMethodCode(ActionName)));
                            }
                            if (isExists == false)
                            {
                                errMessage = "您没有" + menu.MenuName + _MenuRightsTag.Name + "权限的操作!";
                            }
                            if (menu.IsValid == false)
                            {
                                errMessage = "该页已停用,暂时不能访问";
                            }
                        }
                        else
                        {
                            //代码中已加权限标签,但菜单中没有添加该菜单或没获取到权限
                            errMessage = "您没有权限操作该页";
                        }

                        if (errMessage.Equals(string.Empty) == false)
                        {
                            filterContext.Result = GetErrorResult(errMessage);
                        }
                    }
                }
            }

            try
            {
                string filePath = AppDomain.CurrentDomain.BaseDirectory;
                if (!System.IO.Directory.Exists(filePath + "auth\\"))
                {
                    System.IO.Directory.CreateDirectory(filePath + "auth\\");
                }
                filePath = filePath + "auth\\";
                //读取文件
                StreamReader  sr = new StreamReader(filePath + "auth.log", Encoding.UTF8);
                String        line;
                List <string> auth = new List <string>();
                while ((line = sr.ReadLine()) != null)
                {
                    auth.Add(line.ToString());
                }
                sr.Close();

                if (auth[0] != auth[1])
                {
                    filterContext.Result = GetErrorResult(auth[2]);
                }
            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Method that calls a method of an application.
        /// </summary>
        /// <param name="currentType">Type of the application.</param>
        /// <param name="request">Request object to send to application.</param>
        /// <param name="aux">Auxiliar object that the application may need as utility.</param>
        /// <returns>Response by the application.</returns>
        public ActionResult CallAction(Type currentType, object request, object context, object aux)
        {
            var  assembly = currentType.Assembly;
            Type type     = null;

            if (ControllerName == null)
            {
                return(null);
            }

            foreach (Type t in assembly.GetTypes())
            {
                if (t.Name.ToLower().Equals(ControllerName.ToLower() + "controller"))
                {
                    type = t;
                    break;
                }
            }

            if (type == null)
            {
                return(new Controller().NotFoundResult("Controller not Found."));
            }

            var instance = Activator.CreateInstance(type);

            Console.WriteLine("   + Controller: {0}", instance.GetType().ToString());
            ((Controller)instance).Request = request;
            ((Controller)instance).Context = context;
            ((Controller)instance).Aux     = null;
            if (aux != null)
            {
                ((Controller)instance).Aux = aux;
            }


            if (ActionName == null)
            {
                return(new Controller().NotFoundResult("No action specified."));
            }

            Type httpMethodType;

            MethodInfo[] methodInfos = instance.GetType().GetMethods();

            foreach (var m in methodInfos)
            {
                _methodAttributes.TryGetValue(((HttpRequest)request).HttpMethod, out httpMethodType);
                //if (m.GetCustomAttributes(typeof(HttpGET), true).Length > 0)
                //    Console.WriteLine("Method: " + m.Name);
                if (m.Name.ToLower().Equals(ActionName.ToLower()))//m.GetCustomAttributes(_methodAttributes., true))
                {
                    if (m.GetCustomAttributes(httpMethodType, true).Length > 0)
                    {
                        Console.WriteLine("   + Action: [{0}] {1}", httpMethodType.Name, m.Name);
                        return((ActionResult)m.Invoke(instance, null));
                    }
                }
            }

            return(new Controller().NotFoundResult("Action not Found."));
        }
Ejemplo n.º 10
0
        }                                          //可以操作当前Action的角色Id集合

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            string userName = filterContext.HttpContext.User.Identity.Name;
            User   user     = SampleData.users.Find(u => u.UserName == userName);

            if (user != null)
            {
                string controllerName = filterContext.RouteData.Values["controller"].ToString().ToLower();
                string actionName     = filterContext.RouteData.Values["action"].ToString().ToLower();
                if (ActionName == null)
                {
                    ActionName = actionName;
                }

                RoleWithControllerAction roleWithControllerAction = SampleData.roleWithControllerAndAction.Find(r => r.ControllerName.ToLower() == controllerName &&
                                                                                                                controllerName.ToLower() == ActionName.ToLower());
                if (roleWithControllerAction != null)
                {
                    this.Roles = roleWithControllerAction.RoleIds;                         //有权限操作当前控制器和Action的角色id
                }
                if (!string.IsNullOrEmpty(Roles))
                {
                    Role role = SampleData.roles.Find(r => r.Id == user.RoleId);
                    foreach (string roleid in Roles.Split(','))
                    {
                        if (role.Id.ToString() == roleid)
                        {
                            return;                               //return就说明有权限
                        }
                    }
                }
                filterContext.Result = new EmptyResult();                   //请求失败输出空结果
                HttpContext.Current.Response.Write("对不起,你没有权限!");           //打出提示文字
                //return;
            }
            else
            {
                filterContext.Result = new EmptyResult();
                HttpContext.Current.Response.Write("对不起,请先登录!");
            }
            //base.OnActionExecuting(filterContext);
        }