// GET: User/Create
 public ActionResult Create(string id)
 {
     USER m;
     if (string.IsNullOrEmpty(id))
         m = new USER();
     else
         m = UserService.instance().GetEnumByID(new Guid(id)).FirstOrDefault();
     return View(m);
 }
 public JsonResult Create(FormCollection form)
 {
     ResultBase_form result = new ResultBase_form();
     USER m = new USER();
     TryUpdateModel<USER>(m, form);
     if (m.ID == Guid.Empty)
         result.status = UserService.instance().Insert(m);
     else
         result.status = UserService.instance().Update(m);
     result.msg = result.status == 0 ? "操作失败" : "操作成功";
     result.ResultURL = "/User/Index";
     return Json(result, JsonRequestBehavior.AllowGet);
 }
        public ActionResult Login(FormCollection form, string ReturnUrl)
        {
            Hashtable json = new Hashtable();
            try
            {
                string url = "/Home/Index";
                if (!string.IsNullOrEmpty(ReturnUrl))
                    url = ReturnUrl;
                string uname = form["userid"];
                if (uname.Trim().Length <= 0)
                {
                    ViewBag.Msg = "请输入登录账号";
                    return View();
                }
                ViewBag.uname = uname;
                string upwd = form["userpass"];
                if (upwd.Trim().Length <= 0)
                {
                    ViewBag.Msg = "请输入登录密码";
                    return View();
                }
                string code = form["verifycode"];
                if (code.Trim().Length <= 0)
                {
                    ViewBag.Msg = "请输入验证码";
                    return View();
                }
                if (!code.ToUpper().Equals(Session["CheckCode"]))
                {
                    ViewBag.Msg = "验证码不正确";
                    return View();
                }

                //string uname = "bj-admin";
                //string upwd = "123456";

                USER u = new USER();
                json = UserService.instance().Login(uname, upwd);
                if (Convert.ToBoolean(json["status"]))
                {

                    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
                        json["uid"].ToString(), DateTime.Now, DateTime.Now.Add(FormsAuthentication.Timeout), false,
                        "");
                    HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket));
                    Guid UID = new Guid(json["uid"].ToString());
                    //初始化ticket
                    USER m = UserService.instance().GetEntityByID(UID);
                    UserDateTicket.Uname = m.Name;
                    UserDateTicket.Company = CompanyService.instance().Single(m.CompanyID);
                    UserDateTicket.wx_config = WX_ConfigService.instance().SingleByCompanyID(m.CompanyID);
                    UserDateTicket.IsSuper = m.Type == 99 ? true : false;
                    var rlist = User_PK_Role_s_Service.instance().GetEnumByUID(UID).Select(x => x.Role_ID.ToString().ToUpper()).ToList();
                    UserDateTicket.IsWeShop = rlist.Contains("4AD50983-426E-4A74-95FA-D4A9FFB147E5");
                    UserDateTicket.MenuHTML = new MenuService(m.ID).Html;

                    //end初始化ticket

                    Response.Cookies.Add(cookie);
                    Response.Redirect(url);
                }
                else
                {
                    ViewBag.Msg = json["error"];
                    return View();
                }
            }
            catch (Exception ex)
            {
                ViewBag.Msg = "未知错误!" + ex.ToString();
            }
            return View();
        }
Example #4
0
        public MenuService(Guid uid)
        {
            //权限菜单          
            user = UserService.instance().GetEntityByID(uid);
            IEnumerable<Role> roles = RoleService.instance().GetEnumByUID(uid);
            List<Authority> Authoritys = new List<Authority>();
            List<Menu> menus = new List<Menu>();
            foreach (var item in roles)
            {
                Authoritys.AddRange(AuthorityService.instance().GetAuthorityListByRole(item.ID));
            }
            foreach (var item in Authoritys.GroupBy(m => new { m.PID }))
            {
                Menu menu = new Menu();
                menu.Name = item.First().ParentAuth.Name;
                menu.Icon = "";
                menu.URL = "";
                menu.Type = 1;
                menu.Childs = new List<Menu>();
                var xx = item.OrderBy(m => m.Sort);
                foreach (var auth in xx)
                {
                    menu.Childs.Add(new Menu()
                    {
                        Name = auth.Name,
                        URL = auth.Description,
                        Icon = ""
                    });
                }
                menus.Add(menu);
            }



            //功能菜单
            IEnumerable<Class> classs = ClassService.instance().GetChildByID(Guid.Empty, user.CompanyID).OrderBy(m => m.Sort);
            foreach (var cl in classs)
            {
                Menu menu = new Menu();
                menu.Name = cl.Title;
                menu.Type = cl.Type;
                menu.Childs = new List<Menu>();
                menu.ID = cl.ID;
                if (cl.Ishaschild)
                {
                    menu.Type = 1;
                    menu.URL = "#";
                    cl.Childs.Each(m =>
                    {
                        menu.Childs.Add(new Menu()
                        {
                            Name = m.Title,
                            Icon = "",
                            Type = m.Type,
                            ID = m.ID
                        });
                    });
                }
                menus.Add(menu);
            }






            VelocityEngine vltEngine = new VelocityEngine();
            vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
            vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, AppDomain.CurrentDomain.BaseDirectory);
            vltEngine.Init();

            var vltContext = new VelocityContext();
            vltContext.Put("MENU", menus);
            Template vltTemplate = vltEngine.GetTemplate("_menu.vm");
            var vltWriter = new System.IO.StringWriter();
            vltTemplate.Merge(vltContext, vltWriter);
            this._html = vltWriter.GetStringBuilder().ToString();
        }