Beispiel #1
0
 public ActionResult GetMenu()
 {
     try
     {
         BLL.Organize.Action action = new BLL.Organize.Action();
         string userId = User.Identity.Name.Split('|')[0];
         Dictionary <string, object> dicts = new Dictionary <string, object>();
         dicts.Add("menus", action.GetMenu("0", userId));
         return(this.Json(dicts));
     }
     catch (Exception e)
     {
         Dictionary <string, string> dict = new Dictionary <string, string>();
         dict.Add("InfoID", "0");
         dict.Add("InfoMessage", e.Message);
         return(this.Json(dict));
     }
 }
Beispiel #2
0
        public ActionResult Login(string userName, string passWord, string validateCode)
        {
            BLL.Organize.Worker bllWorker = new BLL.Organize.Worker();
            BLL.Organize.Action action    = new BLL.Organize.Action();

            if (ModelState.IsValid)
            {
                //检查登录失败次数
                if (FailCount >= FailedLogin)
                {
                    return(Json(new { IsSuccess = false, Message = string.Format("您登录失败{0}次,{1}分钟内不能再登陆!",
                                                                                 FailedLogin,
                                                                                 NoLoginTime) },
                                "text/html", JsonRequestBehavior.AllowGet));
                }

                //检查验证码
                if (Session["ValidateCode"] != null && validateCode != Session["ValidateCode"].ToString())
                {
                    FailCount++;
                    return(Json(new { IsSuccess = false, Message = "验证码错误!" }, "text/html", JsonRequestBehavior.AllowGet));
                }

                //B_WORKER worker = bllWorker.Login(HttpUtility.UrlDecode(userName), HttpUtility.UrlDecode(passWord));
                B_WORKER worker = bllWorker.Login(userName, passWord);

                if (worker != null)
                {
                    if (FailCount > 0)
                    {
                        FailCount = 0;
                    }

                    //判断登陆者有无权限
                    List <C_MENU_TREE> isAuth = action.GetMenu("0", worker.ID.ToString());
                    if (isAuth == null)
                    {
                        return(Json(new { IsSuccess = false, Message = "您没有任何权限,请联系管理员!" }));
                    }

                    //判断是否是Internet访问并且允许此人Internet访问
                    //bool isInternetAccess = Convert.ToBoolean(ConfigurationManager.AppSettings["IsInternetAccess"]);

                    //if (isInternetAccess && worker.IsAllowInternetAccess.ToUpper() == "N")
                    //{
                    //    return Json(new { IsSuccess = false, Message = "您没有Internet访问权限,请联系管理员!" }, "text/html", JsonRequestBehavior.AllowGet);
                    //}

                    //写登录日志
                    BLL.Organize.Worker w = new BLL.Organize.Worker();

                    B_LOGIN_LOG log = new B_LOGIN_LOG();
                    log.Name      = userName;
                    log.IP        = Request.UserHostAddress;
                    log.LoginTime = DateTime.Now;

                    w.LoginLog(log);

                    //登录成功,写cookie
                    FormsAuthentication.SetAuthCookie(worker.ID.ToString() + "|" + worker.Name + "|" + userName, true);

                    Session.Remove("ValidateCode");

                    return(Json(new { IsSuccess = true, Message = "登录成功" }, "text/html", JsonRequestBehavior.AllowGet));
                }
                else
                {
                    FailCount++;
                    return(Json(new { IsSuccess = false, Message = "账号或密码错误,请联系管理员!" }, "text/html", JsonRequestBehavior.AllowGet));
                }
            }

            return(View());
        }