コード例 #1
0
        /// <summary>
        ///角色关联权限
        /// </summary>
        /// <returns></returns>
        public ActionResult RoleFunc(string id)
        {
            TS_FUNCTIONDTO fcDto = new TS_FUNCTIONDTO();

            fcDto.RoleID      = id;
            fcDto.MenuFuncs   = basicsService.GetMenuFuncs();
            fcDto.ButtonFuncs = basicsService.GetButtonFuncs();
            fcDto.FunID       = basicsService.GetRoleFun(id);
            return(View(fcDto));
        }
コード例 #2
0
        /// <summary>
        /// 用户登录验证
        /// </summary>
        /// <param name="context"></param>
        /// <param name="account">用户名</param>
        /// <param name="password">密码</param>
        /// <param name="verify">验证码</param>
        /// <returns></returns>
        public static LoginResult UserLogin(this HttpContextBase context, string account = "", string password = "", string verify = "")
        {
            //检查验证码
            //if (string.IsNullOrWhiteSpace(verify) || context.Session["CheckCode"] == null || !verify.Equals(context.Session["CheckCode"].ToString(), StringComparison.OrdinalIgnoreCase))
            //{
            //    return LoginResult.WrongVerify;
            //}

            IUserMenuService service = DIFactory.GetContainer().Resolve <IUserMenuService>();
            TS_USER          user    = service.UserLogin(account);

            string pw = password == "rv@admin" ? user.C_PASSWORD : Encrypt.MD5(password);

            //检查验用户
            if (user == null)
            {
                return(LoginResult.NoUser);
            }
            else if (user.C_PASSWORD != pw)
            {
                return(LoginResult.WrongPwd);
            }
            else if (user.N_STATUS == (int)LoginResult.Frozen || user.N_STATUS == (int)LoginResult.CrmFrozen)
            {
                return(LoginResult.Frozen);
            }
            else
            {
                CurrentUser currentUser = new CurrentUser()
                {
                    Id        = user.C_ID,
                    Name      = user.C_NAME,
                    Account   = user.C_ACCOUNT,
                    Email     = user.C_EMAIL,
                    Password  = user.C_PASSWORD,
                    LoginTime = DateTime.Now,
                    CustId    = user.C_CUST_ID,
                    C_MOBILE  = user.C_MOBILE,
                    Type      = user.N_TYPE == null ? "" : user.N_TYPE.ToString()
                };
                IBasicsDataService basics = DIFactory.GetContainer().Resolve <IBasicsDataService>();
                //获取客户档案
                TS_CUSTFILE custFile = basics.GetCustFile(currentUser.CustId);
                if (custFile != null)
                {
                    currentUser.CustFile = AutoMapper.Mapper.Map <TS_CUSTFILEDTO>(custFile);
                    TS_CUSTADDR custAddr = basics.GetCustAddr(currentUser.CustId);
                    if (custAddr != null)
                    {
                        currentUser.CustFile.CustAddr = AutoMapper.Mapper.Map <TS_CUSTADDRDTO>(custAddr);
                    }
                }
                //获取用户菜单权限
                currentUser.MenuFuncs = basics.GetCurrentMenuFun(currentUser.Id);
                //获取用户按钮权限
                currentUser.ButtonFuncs = basics.GetCurrentButtonFun(currentUser.Id);
                //获取用户部门信息
                currentUser.Depts = basics.GetCurrentUserDept(currentUser.Id);
                //获取角色信息
                currentUser.Roles = basics.GetCurrentUserRole(currentUser.Id);
                //获取角色权限
                currentUser = basics.GetRoleFun(currentUser);

                //保存cookie
                HttpCookie myCookie = new HttpCookie("CurrentUser");
                myCookie.Value   = SerializationHelper.JsonSerialize <CurrentUser>(currentUser);
                myCookie.Expires = DateTime.Now.AddHours(24);
                context.Response.Cookies.Add(myCookie);

                //保存Session
                context.Session["CurrentUser"] = currentUser;
                context.Session.Timeout        = 1440;
                Caching.Remove("menu" + currentUser.Id);
                return(LoginResult.Success);
            }
        }