Exemplo n.º 1
0
        public ActionResult EditPlatUserPwd(AccountPasswordChangeModel model)
        {
            JsonModel jm = new JsonModel();

            //如果表单模型验证成功
            if (ModelState.IsValid)
            {
                UserSessionModel sessionModel = (UserSessionModel)Session[ConstantParam.SESSION_USERINFO];
                var id = sessionModel.UserID;

                // 若当前登录用户为平台用户
                IPlatformUserBLL platformUserBll = BLLFactory <IPlatformUserBLL> .GetBLL("PlatformUserBLL");

                T_PlatformUser platformUser = platformUserBll.GetEntity(m => m.Id == model.UserId && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);
                if (platformUser != null)
                {
                    platformUser.Password = PropertyUtils.GetMD5Str(model.Password);
                    // 保存到数据库
                    platformUserBll.Update(platformUser);

                    //日志记录
                    jm.Content = PropertyUtils.ModelToJsonString(model);
                }
                else
                {
                    jm.Msg = "该用户不存在";
                }
            }
            else
            {
                // 保存异常日志
                jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR;
            }
            return(Json(jm, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public ActionResult AddUser(PlatformUserModel model)
        {
            JsonModel jm = new JsonModel();

            //如果表单模型验证成功
            if (ModelState.IsValid)
            {
                IPlatformUserBLL platformUserBll = BLLFactory <IPlatformUserBLL> .GetBLL("PlatformUserBLL");

                T_PlatformUser platformUser = new T_PlatformUser()
                {
                    UserName = model.UserName,
                    TrueName = model.TrueName,
                    Password = PropertyUtils.GetMD5Str(model.Password),
                    Memo     = model.Memo,
                    Tel      = model.Tel,
                    Phone    = model.Phone,
                    Email    = model.Email
                };
                // 保存到数据库
                platformUserBll.Save(platformUser);

                //日志记录
                jm.Content = PropertyUtils.ModelToJsonString(model);
            }
            else
            {
                // 保存异常日志
                jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR;
            }

            return(Json(jm, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 3
0
        public ActionResult ConfigRole(int id)
        {
            // 创建平台用户角色模型
            PlatformUserRoleModel userRoleModel = new PlatformUserRoleModel();

            // 获取指定id的平台用户模型
            IPlatformUserBLL platformUserBll = BLLFactory <IPlatformUserBLL> .GetBLL("PlatformUserBLL");

            T_PlatformUser platformUser = platformUserBll.GetEntity(m => m.Id == id && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);

            userRoleModel.User = new PlatformUserModel()
            {
                UserId   = platformUser.Id,
                UserName = platformUser.UserName,
                TrueName = platformUser.TrueName,
                Tel      = platformUser.Tel,
                Phone    = platformUser.Phone,
                Memo     = platformUser.Memo,
                Email    = platformUser.Email
            };

            // 获取所有平台角色
            IPlatformRoleBLL platformRoleBll = BLLFactory <IPlatformRoleBLL> .GetBLL("PlatformRoleBLL");

            //排序
            var sortModel = this.SettingSorting("Id", false);
            var roleList  = platformRoleBll.GetList(p => p.IsSystem == ConstantParam.USER_ROLE_DEFAULT, sortModel.SortName, sortModel.IsAsc).ToList();

            userRoleModel.RoleList = roleList;

            //获取该用户已分配的角色id的集合
            userRoleModel.RoleIds = platformUser.PlatformUserRoles.Select(m => m.RoleId).ToList();

            return(View(userRoleModel));
        }
Exemplo n.º 4
0
        public ActionResult PlatformLogin(AccountModel model)
        {
            //判断提交模型数据是否正确
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            string code = (string)Session["ValidateCode"];

            if (model.CheckCode != code)
            {
                ModelState.AddModelError("CheckCode", "验证码不正确");
                return(View(model));
            }

            //根据用户名查找用户
            IPlatformUserBLL UserInfoBll = BLLFactory <IPlatformUserBLL> .GetBLL("PlatformUserBLL");

            T_PlatformUser user = UserInfoBll.GetEntity(u => u.UserName == model.UserName.Trim() &&
                                                        u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);

            //1.判断用户名是否正确
            if (user == null)
            {
                ModelState.AddModelError("UserName", "用户名不存在");
                return(View(model));
            }

            //2.判断密码是否正确
            string md5Str = PropertyUtils.GetMD5Str(model.Password);

            if (user.Password != md5Str)
            {
                ModelState.AddModelError("Password", "密码不正确");
                return(View(model));
            }
            //3.如果未设置角色
            if (user.PlatformUserRoles.Count == 0)
            {
                ModelState.AddModelError("UserName", "该用户未设置角色,请联系管理员");
                return(View(model));
            }

            //4.获取用户对象信息(拥有电站,权限菜单,Action等)保存基本信息到session中
            this.SetUserSessiong(user, UserInfoBll);

            //5.判断是否拥有访问首页的权限
            UserSessionModel session = (UserSessionModel)Session[ConstantParam.SESSION_USERINFO];

            if (session.IsMgr == ConstantParam.USER_ROLE_DEFAULT && !session.ActionDic.ContainsKey("/Platform/Index"))
            {
                ModelState.AddModelError("UserName", "该用户无访问权限,请联系管理员");
                return(View(model));
            }
            BreadCrumb.ClearState();
            //6.跳转到
            return(RedirectToAction("Index", "Platform"));
        }
Exemplo n.º 5
0
        public ActionResult SetPlatUserInfo(LoggedInAccountModel model)
        {
            JsonModel jm = new JsonModel();

            //如果表单模型验证成功
            if (ModelState.IsValid)
            {
                // 获取Session Model
                UserSessionModel sessionModel = (UserSessionModel)Session[ConstantParam.SESSION_USERINFO];
                var id = sessionModel.UserID;

                IPlatformUserBLL platformUserBll = BLLFactory <IPlatformUserBLL> .GetBLL("PlatformUserBLL");

                T_PlatformUser platformUser = platformUserBll.GetEntity(m => m.Id == model.UserId && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);
                if (platformUser != null)
                {
                    platformUser.UserName = model.UserName;
                    platformUser.TrueName = model.TrueName;
                    platformUser.Memo     = model.Memo;
                    platformUser.Tel      = model.Tel;
                    platformUser.Phone    = model.Phone;
                    platformUser.Email    = model.Email;
                    // 保存到数据库
                    platformUserBll.Update(platformUser);

                    //更新SessionModel中的最新个人信息
                    sessionModel.TrueName = model.TrueName;

                    //日志记录
                    jm.Content = PropertyUtils.ModelToJsonString(model);
                }
                else
                {
                    jm.Msg = "该用户不存在";
                }
            }
            else
            {
                // 保存异常日志
                jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR;
            }
            return(Json(jm, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 6
0
        public ActionResult ConfigRole(UserConfigRoleModel model)
        {
            JsonModel jm = new JsonModel();

            IPlatformUserBLL platformUserBll = BLLFactory <IPlatformUserBLL> .GetBLL("PlatformUserBLL");

            //获取要分配角色的平台用户
            T_PlatformUser user = platformUserBll.GetEntity(m => m.Id == model.userId && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);

            // 新建用户角色关联表
            List <R_PlatformUserRole> roles = new List <R_PlatformUserRole>();

            if (model.ids != null)
            {
                //没有设置任何角色 则不执行循环操作
                foreach (var id in model.ids)
                {
                    R_PlatformUserRole item = new R_PlatformUserRole()
                    {
                        UserId = model.userId, RoleId = id
                    };
                    roles.Add(item);
                }
            }

            //修改平台用户对应的角色集合
            if (platformUserBll.ConfigRole(user, roles))
            {
                jm.Content = "平台用户 " + user.TrueName + " 分配角色";
            }
            else
            {
                jm.Msg = "分配角色失败";
            }
            return(Json(jm, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 7
0
        /// <summary>
        /// 保存用户的session信息
        /// </summary>
        /// <param name="user"></param>
        private void SetUserSessiong(T_PlatformUser user, IPlatformUserBLL bll)
        {
            //用户session模型
            UserSessionModel sessionInfo = new UserSessionModel();

            //设置基本信息
            sessionInfo.UserID   = user.Id;
            sessionInfo.UserName = user.UserName;
            sessionInfo.TrueName = user.TrueName;
            sessionInfo.IsMgr    = user.IsMgr;
            sessionInfo.UserType = ConstantParam.USER_TYPE_PLATFORM;
            sessionInfo.HeadPath = user.HeadPath;

            //构造菜单业务对象
            IMenuBLL menuBll = BLLFactory <IMenuBLL> .GetBLL("MenuBLL");


            #region 设置平台用户菜单以及权限
            //平台管理员
            if (user.IsMgr == ConstantParam.USER_ROLE_MGR)
            {
                //获取菜单
                var list = menuBll.GetList(m => m.MenuFlag == ConstantParam.MENU_LEFT &&
                                           m.IsPlatform == ConstantParam.USER_TYPE_PLATFORM).Select(m => new MenuModel
                {
                    MenuId     = m.Id,
                    MenuName   = m.MenuName,
                    MenuCode   = m.MenuCode,
                    MenuUrl    = m.Href,
                    MenuFlag   = m.MenuFlag,
                    MenuCss    = m.IconClass,
                    ParentId   = m.ParentId,
                    Order      = m.Order,
                    IsPlatform = m.IsPlatform
                }).ToList();

                //设置左边菜单
                sessionInfo.MenuList = list;
            }
            else
            {
                //获取平台用户对应的角色权限表
                var roleActions = user.PlatformUserRoles.Select(ur => ur.PlatformRole.PlatformRoleActions);

                //菜单字典
                Dictionary <string, MenuModel> menuDic   = new Dictionary <string, MenuModel>();
                Dictionary <string, string>    actionDic = new Dictionary <string, string>();

                foreach (var item in roleActions)
                {
                    var actions = item.Select(obj => obj.Action);
                    foreach (var action in actions)
                    {
                        //添加权限
                        if (!actionDic.ContainsKey(action.Href))
                        {
                            actionDic.Add(action.Href, action.ActionName);
                        }

                        foreach (var li in action.ActionItems)
                        {
                            //添加权限
                            if (!actionDic.ContainsKey(li.Href))
                            {
                                actionDic.Add(li.Href, li.ItemName);
                            }
                        }

                        var menu = action.Menu;
                        if (menu.ParentId != null)
                        {
                            if (!menuDic.ContainsKey(menu.ParentMenu.MenuCode))
                            {
                                menuDic.Add(menu.ParentMenu.MenuCode, GetMenuModel(menu.ParentMenu));
                            }
                        }
                        if (!menuDic.ContainsKey(menu.MenuCode))
                        {
                            menuDic.Add(menu.MenuCode, GetMenuModel(menu));
                        }
                    }
                }

                //设置菜单和权限
                sessionInfo.MenuList.AddRange(menuDic.Values.ToList());
                sessionInfo.ActionDic = actionDic;
            }
            #endregion

            //设置session信息
            Session[ConstantParam.SESSION_USERINFO] = sessionInfo;
        }