Beispiel #1
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            //if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
            //{
            //    return RedirectToLocal(returnUrl);
            //}
            if (Session["admin_User"] != null)
            {
                LoginModel m = Session["admin_User"] as LoginModel;
                if (m != null && m.UserName == "admin")
                {
                    RedirectToRoute(new { controller = "ProductType", action = "Index", area = "Admin" });
                }
            }
            object pwd = BUsers.ExecuteSql("select password from Users where userName='******'");

            if (pwd == null)
            {
                return(View());
            }
            string inputPwd = MyEncrypt.MD5Encrypt(model.Password);

            if (inputPwd == pwd.ToString())
            {
                Session["admin_User"] = model;
                return(RedirectToRoute(new { controller = "ProductType", action = "Index", area = "Admin" }));
            }
            else
            {
                // 如果我们进行到这一步时某个地方出错,则重新显示表单
                ModelState.AddModelError("", "提供的用户名或密码不正确。");
            }
            return(View(model));
        }