Exemple #1
0
        //删除ActionRule
        public ActionResult DeleteActionRule(Guid id)
        {
            ActionRule rule = MyRedisDB.GetSet <ActionRule>(MyRedisKeys.ActionRules).Where(r => r.ID == id).FirstOrDefault();

            MyRedisDB.SetRemove(MyRedisKeys.ActionRules, rule);
            return(RedirectToAction("Manage"));
        }
Exemple #2
0
        public ActionResult DeleteManager(Guid id)
        {
            Manager manager = MyRedisDB.GetSet <Manager>(MyRedisKeys.Managers).Where(r => r.ID == id).FirstOrDefault();

            MyRedisDB.SetRemove(MyRedisKeys.Managers, manager);
            return(RedirectToAction("Manage"));
        }
Exemple #3
0
        public ActionResult AddActionRule(string controller, string action, int aType, string allowRoles)
        {
            IEnumerable <ActionRule> ARules = MyRedisDB.GetSet <ActionRule>(MyRedisKeys.ActionRules);
            ActionRule rule = ARules.Where(a => a.Controller == controller && a.Action == action).FirstOrDefault();

            if (rule != null)
            {
                MyRedisDB.SetRemove(MyRedisKeys.ActionRules, rule);
                rule.ActionType = aType;
                if (!string.IsNullOrEmpty(allowRoles))
                {
                    rule.AllowRoles = allowRoles.Split(',').Select(r => int.Parse(r)).ToArray();
                }
                else
                {
                    rule.AllowRoles = null;
                }
            }
            else
            {
                rule            = new ActionRule();
                rule.Controller = controller;
                rule.Action     = action;
                rule.ActionType = aType;
                if (!string.IsNullOrEmpty(allowRoles))
                {
                    rule.AllowRoles = allowRoles.Split(',').Select(r => int.Parse(r)).ToArray();
                }
            }
            MyRedisDB.SetAdd(MyRedisKeys.ActionRules, rule);
            return(RedirectToAction("Manage"));
        }
Exemple #4
0
        //一键生成ActionRule
        public ActionResult OnkeyRules()
        {
            IEnumerable <ActionRule>            ARules    = MyRedisDB.GetSet <ActionRule>(MyRedisKeys.ActionRules);
            Dictionary <string, List <string> > actionDic = new Dictionary <string, List <string> >();//当前的所有action
            Assembly mvcweb = Assembly.GetExecutingAssembly();

            foreach (Type type in mvcweb.GetTypes())
            {
                if (type.Name.EndsWith("Controller"))
                {
                    string controller = type.Name.Replace("Controller", "");
                    actionDic.Add(controller, new List <string>());

                    int actionType = (int)EnumActionType.前台;
                    if (controller == "Manager")
                    {
                        actionType = (int)EnumActionType.Manager;
                    }
                    foreach (MethodInfo method in type.GetMethods())
                    {
                        if (method.ReturnType == typeof(ActionResult))
                        {
                            string action = method.Name;
                            actionDic[controller].Add(action);

                            ActionRule rule = ARules.Where(a => a.Controller == controller && a.Action == action).FirstOrDefault();
                            if (rule == null)//没有添加
                            {
                                rule            = new ActionRule();
                                rule.Controller = controller;
                                rule.Action     = action;
                                rule.ActionType = actionType;
                                MyRedisDB.SetAdd(MyRedisKeys.ActionRules, rule);
                            }
                        }
                    }
                }
            }
            foreach (ActionRule rule in ARules)//多余删除
            {
                if (!actionDic.Keys.Contains(rule.Controller) || !actionDic[rule.Controller].Contains(rule.Action))
                {
                    MyRedisDB.SetRemove(MyRedisKeys.ActionRules, rule);
                }
            }

            return(RedirectToAction("Manage"));
        }
Exemple #5
0
        public ActionResult UserOperate(string type, Guid uid, int objectType, int days = 0)
        {
            if (type == "启")
            {
                DisabledUser du = MyRedisDB.GetSet <DisabledUser>(MyRedisKeys.DisabledUsers).Where(d => d.UserID == uid && d.ObjectType == objectType).FirstOrDefault();
                MyRedisDB.SetRemove(MyRedisKeys.DisabledUsers, du);
                SysMsg msg = new SysMsg();
                msg.Date  = DateTime.Now;
                msg.Title = "你的账号已解封";
                msg.Msg   = "你的账号在" + Enum.GetName(typeof(EnumObjectType), objectType) + "版块中已解封";
                string key = MyRedisKeys.Pre_SysMsg + uid;
                MyRedisDB.SetAdd(key, msg);
            }
            else
            {
                DisabledUser du = MyRedisDB.GetSet <DisabledUser>(MyRedisKeys.DisabledUsers).Where(d => d.UserID == uid && d.ObjectType == objectType).FirstOrDefault();
                if (du == null)
                {
                    du            = new DisabledUser();
                    du.UserID     = uid;
                    du.ObjectType = objectType;
                    du.AbleDate   = DateTime.Now.AddDays(days);
                    MyRedisDB.SetAdd(MyRedisKeys.DisabledUsers, du);
                }
                else
                {
                    MyRedisDB.SetRemove(MyRedisKeys.DisabledUsers, du);
                    du.AbleDate = DateTime.Now.AddDays(days);
                    MyRedisDB.SetAdd(MyRedisKeys.DisabledUsers, du);
                }

                SysMsg msg = new SysMsg();
                msg.Date  = DateTime.Now;
                msg.Title = "你的账号被封禁";
                msg.Msg   = "你在" + Enum.GetName(typeof(EnumObjectType), objectType) + "版块被封禁至" + du.AbleDate.ToString("yyyy-MM-dd HH:mm");
                string key = MyRedisKeys.Pre_SysMsg + uid;
                MyRedisDB.SetAdd(key, msg);
            }
            return(Json(new { msg = "done" }));
        }