Ejemplo n.º 1
0
 public JsonResult Login(string user_id, string password)
 {
     Models.AdminAccount user = AdminAccountService.GetbyUserId(user_id);
     if (user == null)
     {
         return(Json(
                    new
         {
             statusCode = 0,
             msg = "用户未注册!",
         }
                    , JsonRequestBehavior.AllowGet));
     }
     if (user.User_password.Equals(MD5.Get(password).ToLower()) ||
         user.User_password == password)
     {
         //CreateSession(user);
         return(Json(new { statusCode = 200, msg = "登录成功!" }, JsonRequestBehavior.AllowGet));
     }
     return(Json(
                new
     {
         statusCode = -1,
         msg = "未知错误!",
     }
                , JsonRequestBehavior.AllowGet));
 }
Ejemplo n.º 2
0
        public ActionResult Login(Models.AdminAccount adminAccount, string ReturnUrl, string code)
        {
            if (string.IsNullOrEmpty(code) || Session["code"] == null)
            {
                TempData["loginerr"]    = "err";
                TempData["loginerrmsg"] = "验证码已失效";
                return(RedirectToAction("Index", "Login", ViewBag));
            }
            else
            {
                if (code.ToLower() != Session["code"].ToString().ToLower())
                {
                    TempData["loginerr"]    = "err";
                    TempData["loginerrmsg"] = "验证码错误";
                    return(RedirectToAction("Index", "Login", ViewBag));
                }
            }

            Models.AdminAccount user = AdminAccountService.GetbyUserId(adminAccount.User_id);
            if (user == null)
            {
                //登陆失败;
                //ViewBag.err = "err";
                //ViewBag.errmsg = "账号未注册!";
                TempData["loginerr"]    = "err";
                TempData["loginerrmsg"] = "账号未注册";
                return(RedirectToAction("Index", "Login", ViewBag));
            }
            else
            {
                //判断密码;
                if (user.User_password != adminAccount.User_password)
                {
                    //登陆失败
                    TempData["loginerr"]    = "err";
                    TempData["loginerrmsg"] = "密码错误";
                    return(RedirectToAction("Index", "Login", ViewBag));
                }
                else
                {
                    //登陆成功;
                    CreateSession(user);
                    var ggg = Request.UrlReferrer.OriginalString;
                    Session["RegionCode"] = null;
                    //跳转
                    if (string.IsNullOrEmpty(ReturnUrl))
                    {
                        return(RedirectToAction("Index", "Home"));//如果登录成功跳转的页面。
                    }
                    else
                    {
                        return(Redirect(ReturnUrl));
                    }
                }
            }
        }