Пример #1
0
 //[AuthEscape]
 //[Authorize]
 public ActionResult Login(string Account, string Pwd, string Code)
 {
     try
     {
         if (Account == null || Pwd == null || Code == null)
         {
             return(Json(new { state = false, msg = "非法请求" }));
         }
     }
     catch (Exception)
     {
         return(Json(new { state = false, msg = "非法请求" }));
     }
     if (Session["Code"] == null)
     {
         return(Json(new { state = false, msg = "验证码已经过期" }));
     }
     if (Code.ToUpper() != Session["Code"].ToString().ToUpper())
     {
         return(Json(new { state = false, msg = "验证码错误" }));
     }
     try
     {
         user = unitof.CreateRespository <User>().GetEntityFirst(a => a.Account == Account && a.Pwd == Pwd);
     }
     catch (Exception)
     {
         return(Json(new { state = false, msg = "发生了未知错误" }));
     }
     if (user != null)
     {
         Session["User"] = user;
         Session.Timeout = 10;
         string userstr = Newtonsoft.Json.JsonConvert.SerializeObject(user);
         //身份验证一天过期
         FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, user.Account, DateTime.Now, DateTime.Now.AddDays(1)
                                                                          , true, userstr, FormsAuthentication.FormsCookiePath);
         HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket));
         Response.Cookies.Add(cookie);
         return(Json(new { state = true, msg = "登录成功" }));
     }
     else
     {
         return(Json(new { state = false, msg = "账号或密码错误" }));
     }
     //return Json(new {Account=Account,Pwd=Pwd },JsonRequestBehavior.AllowGet);
 }
Пример #2
0
        public ActionResult getstudent(int page, int limit)
        {
            var students = unitof.CreateRespository <Student>().GetEntityListByPage(pageindex: page, pageSize: limit)
                           .Select(m => new { m.Id, m.Name, m.Phone, m.Sex, m.CardId, m.EnrollmentDate, m.Address })
                           .ToList();
            int count = unitof.CreateRespository <Student>().Getcount();

            return(Json(new { code = 0, msg = "", count = count, data = students }, JsonRequestBehavior.AllowGet));
        }