示例#1
0
        public ActionResult Index()
        {
            var op = new I.MES.Library.UserOP();

            //DAL.MenuOP op = new DAL.MenuOP();
            //var menuList = op.GetList().OrderBy(p => p.OrderNum).ToList();
            ViewBag.CompanyName = Session["CompanyName"];
            ViewBag.FactoryCode = Session["FactoryCode"];
            ViewBag.userAccount = Session["UserID"];
            List <SYS_RPTMenu> menuList = new List <SYS_RPTMenu>();

            if (Session["UserID"] == null)
            {
                Redirect("~/Account/Login");
            }
            else
            {
                if (Session["UserID"].ToString().ToLower().Equals("admin"))
                {
                    menuList = op.GetAllMenu().OrderBy(p => p.OrderNum).ToList();
                }
                else
                {
                    if (Session["Permission"] != null)
                    {
                        menuList = (Session["Permission"] as List <SYS_RPTMenu>).OrderBy(p => p.OrderNum).ToList();
                    }
                }
            }

            return(View(menuList));
        }
示例#2
0
        public string Login(string userAccount, string userPassword, string systemId, string factory, string returnUrl)
        {
            try
            {
                if (Session["UserID"] != null && Session["FactoryCode"] != null)
                {
                    if (Session["UserID"].ToString() != userAccount ||
                        Session["FactoryCode"].ToString() != factory)
                    {
                        return(JsonHelper.ToJson(new ReturnResult()
                        {
                            Result = -2,
                            Message = "Existing user login, please close browser and login again!",
                        }));
                    }
                }
                //company = company.Equals("TEST") ? "PD" : company;
                var company = new MES.Library.ComPanyOP().GetCompanyList().FirstOrDefault();
                //DAL.RPT_Company company = new DAL.RptCompanyOP().GetData(systemId);
                FormsAuthentication.SetAuthCookie(userAccount, false);
                //检查账号密码
                var mesUser = new MES.Library.UserOP().GetUser(userAccount);
                List <SYS_Factory> mesFactory = new MES.Library.UserOP().GetUserAvailFactories(userAccount);
                int         num         = 0;
                SYS_Factory factoryname = new MES.Library.UserOP().GetFactory(factory);
                string      name        = "";
                if (factoryname != null)
                {
                    name = factoryname.FactoryName;
                }
                foreach (var item in mesFactory)
                {
                    if (factory == item.FactoryCode)
                    {
                        num = 1;
                    }
                }
                if (mesUser == null)
                {
                    return(JsonHelper.ToJson(new ReturnResult()
                    {
                        Result = 0,
                        Message = string.Format("No such user({0})", userAccount),
                    }));
                }
                if (mesUser.Password != userPassword)
                {
                    return(JsonHelper.ToJson(new ReturnResult()
                    {
                        Result = 0,
                        Message = "Password error",
                    }));
                }
                if (num == 0)
                {
                    return(JsonHelper.ToJson(new ReturnResult()
                    {
                        Result = 0,
                        Message = string.Format("The user ({0}) does not have ({1}) permissions", userAccount, name),
                    }));
                }
                //Report菜单权限
                //Session["Permission"] = (new I.Report.DAL.UserOP()).GetUserPermission(userAccount);
                Session["Permission"] = new I.MES.Library.UserOP().GetUserMenuPrivs(userAccount);
                Session["UserID"]     = userAccount;
                //Session["SystemID"] = systemId;
                Session["CompanyCode"] = company.CompanyCode;
                Session["CompanyName"] = company.CompanyName;
                Session["FactoryCode"] = factory;
                Session["UserName"]    = mesUser.UserName;

                //return RedirectToAction("Index", "Home");
                return(JsonHelper.ToJson(new ReturnResult()
                {
                    Result = 1
                }));
            }
            catch (Exception ex)
            {
                return(JsonHelper.ToJson(new ReturnResult()
                {
                    Result = 0,
                    Message = ex.Message
                }));
            }
        }