예제 #1
0
        public ActionResult Login(string Name, string Pw)
        {
            HandleResult hr = new HandleResult();

            if (string.IsNullOrEmpty(Name) || Commons.IsIncludeSqlInjection(Name))
            {
                hr.StatsCode = 103;
                hr.Message   = "姓名不合法";
                return(Content(JsonConvert.SerializeObject(hr)));
            }

            if (string.IsNullOrEmpty(Pw) || Commons.IsIncludeSqlInjection(Pw))
            {
                hr.StatsCode = 104;
                hr.Message   = "密码不合法";
                return(Content(JsonConvert.SerializeObject(hr)));
            }

            AdminUserEntity model = AdminUserBLL.GetLoginByName(Name);

            if (model != null)
            {
                if (model.PassWord == Commons.GetMD5Hash(Pw))
                {
                    Authentication.SetAuthCookie(model.Id, HttpUtility.UrlEncode(model.UserName, Encoding.GetEncoding("UTF-8")));
                    hr.StatsCode = 200;
                    hr.Message   = "登陆成功";
                    return(Content(JsonConvert.SerializeObject(hr)));
                }
                hr.Message = "用户不存在或密码错误";
                return(Content(JsonConvert.SerializeObject(hr)));
            }
            hr.Message = "用户不存在或密码错误";
            return(Content(JsonConvert.SerializeObject(hr)));
        }