Example #1
0
        public ActionResult Login(string ReturnUrl = "", int Status = 0, string name = "", int BindAccountType = 0)
        {
            if (Session["ClientManager"] != null)
            {
                return(Redirect("/Default/Index"));
            }

            ViewBag.Status          = Status;
            ViewBag.BindAccountType = BindAccountType;
            ViewBag.ReturnUrl       = ReturnUrl.Replace("&", "%26") + (string.IsNullOrEmpty(name) ? "" : "%26name=" + name).Replace("&", "%26") ?? string.Empty;

            HttpCookie cook = Request.Cookies["owzx_user"];

            if (cook != null)
            {
                if (cook["status"] == "1")
                {
                    string operateip = Common.Common.GetRequestIP();
                    int    result;
                    OWZXEntity.Manage.M_Users model = M_UsersBusiness.GetM_UserByProUserName(cook["username"], cook["pwd"], operateip, out result);;
                    if (model != null)
                    {
                        Session["ClientManager"] = model;
                        return(Redirect("/Default/Index"));
                    }
                }
                else
                {
                    ViewBag.UserName = cook["username"];
                }
            }
            ViewBag.IsMobileDevice = OWZXManage.Common.Common.IsMobileDevice();

            return(View());
        }
Example #2
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public JsonResult UserLogin(string userName, string pwd, string remember = "")
        {
            Dictionary <string, object> JsonDictionary = new Dictionary <string, object>();
            string operateip = Common.Common.GetRequestIP();;
            int    result    = 0;
            string msg       = "";

            Common.PwdErrorUserEntity pwdErrorUser = null;

            if (Common.Common.CachePwdErrorUsers.ContainsKey(userName))
            {
                pwdErrorUser = Common.Common.CachePwdErrorUsers[userName];
            }

            if (pwdErrorUser == null || (pwdErrorUser.ErrorCount < 10 && pwdErrorUser.ForbidTime < DateTime.Now))
            {
                M_Users tempmodel = M_UsersBusiness.GetM_UserByUserName(userName);
                if (tempmodel != null)
                {
                    if (tempmodel.IsFreeZe == 0)
                    {
                        var pswd = OWZXTool.Encrypt.MD5(pwd + tempmodel.Salt);
                        if (pswd == tempmodel.Password)
                        {
                            M_Users model = M_UsersBusiness.GetM_UserByProUserName(userName, pswd, operateip, out result);

                            if (model != null)
                            {
                                HttpCookie cook = new HttpCookie("owzx_user");
                                cook["username"] = userName;
                                cook["pwd"]      = pwd;
                                if (remember == "1")
                                {
                                    cook["status"] = remember;
                                }
                                cook.Expires = DateTime.Now.AddDays(7);
                                Response.Cookies.Add(cook);
                                Session["ClientManager"] = model;
                                result = 1;
                            }
                            else
                            {
                                msg = result == 3 ? "用户已被禁闭,请联系管理员" : "用户名或密码错误!";
                            }
                        }
                        else
                        {
                            result = 3;
                            msg    = "用户密码错误!";
                        }
                    }
                    else
                    {
                        result = 4;
                        msg    = "用户已被禁闭,请联系管理员";
                    }
                }
                else
                {
                    result = 4;
                    msg    = "用户名不存在";
                }
                if (!string.IsNullOrEmpty(msg) && result != 4)
                {
                    if (pwdErrorUser == null)
                    {
                        pwdErrorUser = new Common.PwdErrorUserEntity();
                    }
                    else
                    {
                        if (pwdErrorUser.ErrorCount > 9)
                        {
                            pwdErrorUser.ErrorCount = 0;
                        }
                    }

                    pwdErrorUser.ErrorCount++;
                    if (pwdErrorUser.ErrorCount > 6)
                    {
                        pwdErrorUser.ForbidTime = DateTime.Now.AddHours(2);
                        result = 2;
                    }
                    else
                    {
                        JsonDictionary.Add("errorCount", pwdErrorUser.ErrorCount);
                        result = 3;
                    }

                    Common.Common.CachePwdErrorUsers[userName] = pwdErrorUser;
                }
            }
            else
            {
                int forbidTime = (int)(pwdErrorUser.ForbidTime - DateTime.Now).TotalMinutes;
                JsonDictionary.Add("forbidTime", forbidTime);
                result = -1;
            }
            JsonDictionary.Add("result", result);
            JsonDictionary.Add("errorinfo", msg);
            return(new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }