Beispiel #1
0
        public IActionResult UpdatePassword()
        {
            //展示页面
            if (!Request.Method.ToUpper().Equals("POST", StringComparison.OrdinalIgnoreCase) || !Request.HasFormContentType)
            {
                // 权限和菜单
                UpdatePasswordModel model = new UpdatePasswordModel();
                var layoutModel           = this.GetLayoutModel();
                if (layoutModel != null)
                {
                    layoutModel.ToT(ref model);
                }

                return(View(model));
            }
            else
            {
                //修改密码
                var msg = new Message(10, "修改密码失败!");

                string oldPassword = Request.Form["oldPassword"];
                string password    = Request.Form["password"];
                string rePassword  = Request.Form["rePassword"];

                var adminToken = CMSAdminCookie.GetAdiminCookie();
                var admin      = CMSAdminBO.GetAdminByUserName(adminToken.UserName);
                if (admin != null || admin.ID > 0)
                {
                    msg = CMSAdminBO.UpdatePasswordByID(admin.ID, oldPassword, password, rePassword);
                }

                return(new JsonResult(msg));
            }
        }
Beispiel #2
0
        //删除角色
        public ActionResult <Message> DeleteRole()
        {
            string[] idsStr = Request.Form["ids"];

            var msg    = new Message(10, "删除失败");
            var idsInt = new List <int>();

            if (idsStr != null && idsStr.Count() > 0)
            {
                foreach (var id in idsStr)
                {
                    if (Validator.IsNumbers(id))
                    {
                        idsInt.Add(int.Parse(id));
                    }
                }

                msg = CMSAdminBO.DeleteRole(idsInt);
            }
            else
            {
                msg.Code = 101;
                msg.Msg  = "请选择要删除的角色";
            }

            return(new JsonResult(msg));
        }
Beispiel #3
0
        public IActionResult LoginInfo()
        {
            // 权限和菜单
            IndexModel model       = new IndexModel();
            var        layoutModel = this.GetLayoutModel();

            if (layoutModel != null)
            {
                layoutModel.ToT(ref model);
            }

            var admin = CMSAdminBO.GetAdminByUserName(model.UserName);

            if (admin != null && !string.IsNullOrEmpty(admin.UserName))
            {
                model.LastLogonIP   = admin.LastLogonIP;
                model.LastLogonTime = DateTimeUtils.UnixTimeStampToDateTime(admin.LastLogonTime);
            }
            else
            {
                model.LastLogonIP   = "本机IP";
                model.LastLogonTime = DateTime.Now;
            }

            return(View("./Index", model));
        }
Beispiel #4
0
        //角色管理
        public IActionResult RoleList(string id)
        {
            if (id == null || !id.ToUpper().Equals("DATA", StringComparison.OrdinalIgnoreCase))
            {
                // 权限和菜单
                RoleListModel model       = new RoleListModel();
                var           layoutModel = this.GetLayoutModel();
                if (layoutModel != null)
                {
                    layoutModel.ToT(ref model);
                }

                return(View(model));
            }
            else
            {
                //取角色列表
                string titleFilter = Request.Query["title"];

                int pageIndex = 0;
                int.TryParse(Request.Query["page"], out pageIndex);

                int pageLimit = Consts.Page_Limit;
                int totCount  = CMSAdminBO.GetRoleCount(titleFilter);
                int pageCount = (int)Math.Ceiling(totCount / (float)pageLimit);
                var roles     = new List <Role>();
                if (totCount > 0)
                {
                    IEnumerable <Role> roleIE = CMSAdminBO.GetRoles(titleFilter, pageLimit, pageIndex);
                    if (roleIE != null)
                    {
                        roles = roleIE.ToList();
                    }
                }

                dynamic model = new ExpandoObject();

                model.code  = 0;
                model.msg   = "";
                model.count = totCount;
                model.data  = roles.Select(s => new
                {
                    id    = s.ID,
                    title = s.Title,
                    state = s.State
                });

                return(new JsonResult(model));
            }
        }
Beispiel #5
0
        public ActionResult <Message> DoLogin()
        {
            string userName   = Request.Form["userName"];
            string password   = Request.Form["password"];
            string verifyCode = Request.Form["verifyCode"];

            var admin = new AdminLogin
            {
                UserName   = userName,
                Password   = password,
                VerifyCode = verifyCode
            };

            var msg = CMSAdminBO.AdminLogin(admin);

            if (msg.Success)
            {
                msg.Msg = Consts.Url_ManageIndex;
            }

            return(new JsonResult(msg));
        }
Beispiel #6
0
        //禁启用角色
        public ActionResult <Message> UpdateRoleState()
        {
            string[] idsStr   = Request.Form["ids"];
            string   stateStr = Request.Form["state"];
            byte     state    = 1;

            if (Validator.IsNumbers(stateStr))
            {
                state = byte.Parse(stateStr);
            }

            var stateDes = state == 1 ? "启用" : "禁用";

            var msg    = new Message(10, $"{stateDes}失败");
            var idsInt = new List <int>();

            if (idsStr != null && idsStr.Count() > 0)
            {
                foreach (var id in idsStr)
                {
                    if (Validator.IsNumbers(id))
                    {
                        idsInt.Add(int.Parse(id));
                    }
                }

                msg = CMSAdminBO.UpdateRoleState(idsInt, state);
            }
            else
            {
                msg.Code = 101;
                msg.Msg  = $"请选择要{stateDes}的角色";
            }

            return(new JsonResult(msg));
        }
Beispiel #7
0
        //添加权限
        public IActionResult ModifyRoleRight()
        {
            //展示页面
            if (!Request.Method.ToUpper().Equals("POST", StringComparison.OrdinalIgnoreCase) || !Request.HasFormContentType)
            {
                // 权限和菜单
                ModifyRoleRightModel model = new ModifyRoleRightModel();
                var layoutModel            = this.GetLayoutModel();
                if (layoutModel != null)
                {
                    layoutModel.ToT(ref model);
                }

                int id = 0;
                int.TryParse(Request.Query["id"], out id);

                if (id > 0)
                {
                    var role = CMSAdminBO.GetRoleByID(id);
                    if (role != null && role.ID > 0)
                    {
                        model.Role = role;

                        var modules = CMSAdminBO.GetModules(1);
                        if (modules != null)
                        {
                            model.Modules = modules.ToList();
                        }

                        var roleRights = CMSAdminBO.GetRoleRights(role.ID);
                        if (roleRights != null)
                        {
                            model.RoleModuleIDs = roleRights.Select(s => s.ModuleID).ToList();
                        }
                    }
                }

                return(View(model));
            }
            else
            {
                var msg = new Message(10, "分配失败!");

                int roleID = 0;
                int.TryParse(Request.Form["roleID"], out roleID);

                string[] moduleIDsStr = Request.Form["moduleIDs"];
                var      moduleIDsInt = new List <int>();
                if (moduleIDsStr != null && moduleIDsStr.Count() > 0)
                {
                    foreach (var moduleID in moduleIDsStr)
                    {
                        if (Validator.IsNumbers(moduleID))
                        {
                            moduleIDsInt.Add(int.Parse(moduleID));
                        }
                    }
                }

                if (roleID > 0 && moduleIDsInt != null && moduleIDsInt.Count() > 0)
                {
                    msg = CMSAdminBO.CreateRoleRight(roleID, moduleIDsInt);
                }

                return(new JsonResult(msg));
            }
        }
Beispiel #8
0
        //添加修改角色
        public IActionResult ModifyRole()
        {
            //展示页面
            if (!Request.Method.ToUpper().Equals("POST", StringComparison.OrdinalIgnoreCase) || !Request.HasFormContentType)
            {
                // 权限和菜单
                ModifyRoleModel model       = new ModifyRoleModel();
                var             layoutModel = this.GetLayoutModel();
                if (layoutModel != null)
                {
                    layoutModel.ToT(ref model);
                }

                int id = 0;
                int.TryParse(Request.Query["id"], out id);

                if (id > 0)
                {
                    model.PageTitle = "修改角色";
                    var role = CMSAdminBO.GetRoleByID(id);
                    if (role != null && role.ID > 0)
                    {
                        model.Role = role;
                    }
                }
                else
                {
                    model.PageTitle = "添加角色";
                }

                return(View(model));
            }
            else
            {
                var msg = new Message(10, "修改失败!");

                int id = 0;
                int.TryParse(Request.Form["id"], out id);
                string title = Request.Form["title"];
                byte   state = 1;
                byte.TryParse(Request.Form["state"], out state);

                var role = new Role()
                {
                    ID    = id,
                    Title = title,
                    State = state
                };

                if (role.ID > 0)
                {
                    msg = CMSAdminBO.UpdateRole(role);
                }
                else
                {
                    msg = CMSAdminBO.CreateRole(role);
                }

                return(new JsonResult(msg));
            }
        }
Beispiel #9
0
        //账号管理
        public IActionResult AdminList(string id)
        {
            if (id == null || !id.ToUpper().Equals("DATA", StringComparison.OrdinalIgnoreCase))
            {
                // 权限和菜单
                AdminListModel model       = new AdminListModel();
                var            layoutModel = this.GetLayoutModel();
                if (layoutModel != null)
                {
                    layoutModel.ToT(ref model);
                }

                var roles = CMSAdminBO.GetRoles(0);
                if (roles != null)
                {
                    model.Roles = roles.ToList();
                }

                return(View(model));
            }
            else
            {
                //取账号列表
                string userNameFilter = Request.Query["userName"];

                int roleIDFilter = 0;
                int.TryParse(Request.Query["roleID"], out roleIDFilter);

                int pageIndex = 0;
                int.TryParse(Request.Query["page"], out pageIndex);

                int pageLimit = Consts.Page_Limit;
                int totCount  = CMSAdminBO.GetAdminCount(userNameFilter, roleIDFilter);
                int pageCount = (int)Math.Ceiling(totCount / (float)pageLimit);
                var admins    = new List <Admin>();
                if (totCount > 0)
                {
                    IEnumerable <Admin> adminIE = CMSAdminBO.GetAdmins(userNameFilter, roleIDFilter, pageLimit, pageIndex);
                    if (adminIE != null)
                    {
                        admins = adminIE.ToList();
                    }
                }

                dynamic model = new ExpandoObject();

                model.code  = 0;
                model.msg   = "";
                model.count = totCount;
                model.data  = admins.Select(s => new
                {
                    id        = s.ID,
                    userName  = s.UserName,
                    roleTitle = s.RoleTitle,
                    state     = s.State,
                    lockState = s.LockState
                });

                return(new JsonResult(model));
            }
        }
Beispiel #10
0
        //添加修改菜单
        public IActionResult ModifyModule()
        {
            //展示页面
            if (!Request.Method.ToUpper().Equals("POST", StringComparison.OrdinalIgnoreCase) || !Request.HasFormContentType)
            {
                // 权限和菜单
                ModifyModuleModel model = new ModifyModuleModel();
                var layoutModel         = this.GetLayoutModel();
                if (layoutModel != null)
                {
                    layoutModel.ToT(ref model);
                }

                var modules = CMSAdminBO.GetModules(0);
                if (modules != null)
                {
                    model.Modules = modules.ToList();
                }

                int id = 0;
                int.TryParse(Request.Query["id"], out id);

                if (id > 0)
                {
                    model.PageTitle = "修改菜单";
                    var module = CMSAdminBO.GetModule(id);
                    if (module != null && module.ID > 0)
                    {
                        model.Module = module;
                    }
                }
                else
                {
                    model.PageTitle = "添加菜单";
                }

                return(View(model));
            }
            else
            {
                var msg = new Message(10, "修改失败!");

                int id = 0;
                int.TryParse(Request.Form["id"], out id);
                int parentID = 0;
                int.TryParse(Request.Form["parentID"], out parentID);
                string title      = Request.Form["title"];
                string controller = Request.Form["controller"];
                string action     = Request.Form["action"];
                int    sort       = 0;
                int.TryParse(Request.Form["sort"], out sort);
                byte state = 1;
                byte.TryParse(Request.Form["state"], out state);

                var module = new Module()
                {
                    ID         = id,
                    ParentID   = parentID,
                    Title      = title,
                    Controller = controller,
                    Action     = action,
                    Sort       = sort,
                    State      = state
                };

                if (module.ID > 0)
                {
                    msg = CMSAdminBO.UpdateModule(module);
                }
                else
                {
                    msg = CMSAdminBO.CreateModule(module);
                }

                return(new JsonResult(msg));
            }
        }
Beispiel #11
0
        //添加修改账号
        public IActionResult ModifyAdmin()
        {
            //展示页面
            if (!Request.Method.ToUpper().Equals("POST", StringComparison.OrdinalIgnoreCase) || !Request.HasFormContentType)
            {
                // 权限和菜单
                ModifyAdminModel model = new ModifyAdminModel();
                var layoutModel        = this.GetLayoutModel();
                if (layoutModel != null)
                {
                    layoutModel.ToT(ref model);
                }

                var roles = CMSAdminBO.GetRoles(0);
                if (roles != null)
                {
                    model.Roles = roles.ToList();
                }

                int id = 0;
                int.TryParse(Request.Query["id"], out id);

                if (id > 0)
                {
                    model.PageTitle = "修改账号";
                    var admin = CMSAdminBO.GetAdminByID(id);
                    if (admin != null && admin.ID > 0)
                    {
                        model.Admin = admin;
                    }
                }
                else
                {
                    model.PageTitle = "添加账号";
                }

                return(View(model));
            }
            else
            {
                var msg = new Message(10, "修改失败!");

                int id = 0;
                int.TryParse(Request.Form["id"], out id);
                string userName   = Request.Form["userName"];
                string password   = Request.Form["password"];
                string rePassword = Request.Form["rePassword"];
                int    roleID     = 0;
                int.TryParse(Request.Form["roleID"], out roleID);
                byte state = 1;
                byte.TryParse(Request.Form["state"], out state);

                var admin = new Admin()
                {
                    ID         = id,
                    UserName   = userName,
                    Password   = password,
                    RePassword = rePassword,
                    RoleID     = roleID,
                    State      = state
                };

                if (admin.ID > 0)
                {
                    msg = CMSAdminBO.UpdateAdminByID(admin);
                }
                else
                {
                    msg = CMSAdminBO.CreateAdmin(admin);
                }

                return(new JsonResult(msg));
            }
        }
Beispiel #12
0
        public IActionResult AdminLogout()
        {
            CMSAdminBO.AdminLogout();

            return(Redirect(Consts.Url_AdminLogin));
        }