Пример #1
0
 public ActionResult Create(FormCollection collection)
 {
     try
     {
         SysUser model = new SysUser();
         model.UserName = collection["UserName"];
         model.RoleId   = Convert.ToInt32(collection["RoleList"]);
         model.Status   = Convert.ToInt32(collection["ModelState"]);
         model.RealName = collection["RealName"];
         model.Tel      = collection["Tel"];
         model.Email    = collection["Email"];
         if (logic.GetUserInfo(model.UserName) == null)
         {
             logic.AddUser(model);
             return(this.RefreshParent());
         }
         else
         {
             return(this.Back("用户名重复"));
         }
     }
     catch (Exception ex)
     {
         return(this.Back("新增用户发生异常。" + ex.Message));
     }
 }
Пример #2
0
        public ActionResult Login(string username, string password)
        {
            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                ModelState.AddModelError("error", "用户名或密码错误");
                return(View());
            }
            username = username.Trim();
            var loginInfo = logic.GetUserInfo(username);

            if (loginInfo != null && loginInfo.PassWord.Equals(password))
            {
                switch (loginInfo.Status)
                {
                case 0:
                    LoginUserInfo loginUser = new LoginUserInfo()
                    {
                        UserId = loginInfo.UserId, RoleId = loginInfo.RoleId, UserName = loginInfo.UserName, RealName = loginInfo.RealName
                    };
                    string UserData = JinRi.Fx.Utility.JsonHelper.DataContractJsonSerialize <LoginUserInfo>(loginUser).Replace("\0", "").Trim();
                    //保存序列化的用户信息票据
                    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, loginInfo.UserName, DateTime.Now, DateTime.Now.AddHours(1), false, UserData);
                    //将票据加密并存到cookie
                    HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket));
                    //输出到浏览器
                    this.HttpContext.Response.Cookies.Add(cookie);
                    return(RedirectToAction("Index", "Home"));

                case 1:
                    ModelState.AddModelError("error", "登录失败,用户已被禁用。");
                    return(View());

                default:
                    ModelState.AddModelError("error", "无效的用户状态。");
                    return(View());
                }
            }
            else
            {
                ModelState.AddModelError("error", "用户名或密码错误");
                return(View());
            }
        }
Пример #3
0
        public ActionResult ConfigServiceRight(int roleId = -1, int userId = 0)
        {
            //具有国内/国际开发主管角色的登入用户进入该页后,角色下拉列表只列出国内/国际开发主管,
            //否则,列出国内开发主管和国际开发主管两角色:
            SysRoleLogic   roleLogic    = new SysRoleLogic();
            List <SysRole> roleList     = roleLogic.GetRoleList().ToList <SysRole>();
            LoginUserInfo  currentLogin = this.WorkContext.CurrentUser;

            //7表示国内开发主管角色,8表示国际开发主管角色
            if (currentLogin.RoleId == 7 || currentLogin.RoleId == 8)
            {
                roleList = roleList.Where(x => x.RoleId == currentLogin.RoleId).ToList <SysRole>();
            }
            else
            {
                roleList = roleList.Where(x => (x.RoleId == 7 || x.RoleId == 8)).ToList <SysRole>();
            }
            ViewBag.RoleId = new SelectList(roleList, "RoleId", "RoleName");
            if (roleId < 1)
            {
                if (currentLogin.RoleId == 7 || currentLogin.RoleId == 8)
                {
                    ViewBag.CurrentRoleId = currentLogin.RoleId;
                }
                else
                {
                    ViewBag.CurrentRoleId = 7;
                }
            }
            else
            {
                ViewBag.CurrentRoleId = roleId;
            }

            List <SysUser> userList = GetUserList(roleId);

            ViewBag.UserId        = new SelectList(userList, "UserId", "RealName");
            ViewBag.CurrentUserId = userId;

            List <SysRoleRight> roleRightList = new List <SysRoleRight>();

            if (roleId > 0)
            {
                SysApplicationLogic appIdMenuLogic = new SysApplicationLogic();

                //求配置中心权限管理模块的各菜单项:
                List <SysApplicationEntity> appIdMenuList = null;
                SysUserLogic sysUserLogic     = new SysUserLogic();
                SysUser      sysUser          = null;
                int?         selectedUserId   = -1;
                string       selectedUserName = string.Empty;
                switch (roleId)
                {
                case 7:    //国内开发主管角色,目前只求针对国内机票产品线的配置中心权限管理模块的各菜单项:
                    sysUser = sysUserLogic.GetUserInfo(userId);
                    if (sysUser != null)
                    {
                        selectedUserName        = sysUser.RealName;
                        ViewBag.CurrentUserName = selectedUserName;
                    }
                    appIdMenuList = appIdMenuLogic.GetSysApplicationList(-1, -1, "", -1, -1, null, new List <int> {
                        1
                    }, selectedUserName).ToList <SysApplicationEntity>();
                    break;

                case 8:     //国际开发主管角色,目前只求针对国际机票产品线的配置中心权限管理模块的各菜单项:
                    sysUser = sysUserLogic.GetUserInfo(userId);
                    if (sysUser != null)
                    {
                        selectedUserName        = sysUser.RealName;
                        ViewBag.CurrentUserName = selectedUserName;
                    }
                    appIdMenuList = appIdMenuLogic.GetSysApplicationList(-1, -1, "", -1, -1, null, new List <int> {
                        2
                    }, selectedUserName).ToList <SysApplicationEntity>();
                    break;

                default:
                    break;
                }
                ViewBag.AppIdMenuList = appIdMenuList;

                selectedUserId = ViewBag.CurrentUserId as int?;
                roleRightList  = logic.GetRoleRightList(roleId, true, (selectedUserId.HasValue ? Convert.ToInt32(selectedUserId) : -1)).ToList <SysRoleRight>();
            }

            return(View(roleRightList));
        }