Beispiel #1
0
        public void Dont_Auth_Correct_User_With_Invalid_Captcha_1()
        {
            // Arrange
            LoginViewModel userData = new LoginViewModel
            {
                Login    = "******",
                Password = "******",
                Captcha  = "bad"
            };
            string            storedPasswordHash = Convert.ToBase64String(HashPassword.HashPass(userData.Password.ToCharArray(), new byte[0]));
            IAuthProvider     authProv           = new FormsAuthProvider(userData.Login, storedPasswordHash, "");
            AccountController target             = new AccountController(authProv);
            SessionStorage    storage            = SessionStorage.Current;
            string            captcha            = "54asd#213_54WQExz";

            storage.CaptchaCode = captcha;

            // Act
            ActionResult result = target.Login(userData, "#true", storage);

            // Assert
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            Assert.IsFalse(((ViewResult)result).ViewData.ModelState.IsValid);
            Assert.IsTrue(storage.UnsucLoginAttempts == 1);
        }
Beispiel #2
0
        public void AuthenticateTest()
        {
            string inputPwdHash = FormsAuthProvider.HashMD5("pwd");

            Debug.WriteLine("\n\n************************CompletedTest***************************\n\n");
            Debug.WriteLine(inputPwdHash);
            Debug.WriteLine("\n\n*************************CompletedTest**************************\n\n");
        }
Beispiel #3
0
 public static void InitializeConnection(bool EF)
 {
     if (EF)
     {
         FormsAuthProvider formsAuthProvider = new FormsAuthProvider();
         Connections.Add(formsAuthProvider);
     }
 }
Beispiel #4
0
        public ActionResult Login(BuyerInfoViewModel buyer, string returnUrl)
        {
            ViewBag.ReturnUrl = returnUrl;

            IAuthProvider authProvider = new FormsAuthProvider();

            if (ModelState.IsValid)
            {
                string msg;
                var    user = BuyerInfoBll.GetModelByLoginName(buyer.LoginName, out msg);
                if (user != null)
                {
                    if (user.Password.Equals(buyer.Password))
                    {
                        Session["User"]    = user;
                        Session["IsGuest"] = false;
                        authProvider.AuthSuccess();


                        var sellerList = BuyerInfoBll.GetSellerList(user.BuyerId, out msg);

                        if (sellerList.Count > 1)
                        {
                            return(RedirectToAction("ListView", "Seller"));
                        }
                        else if (sellerList.Count == 1)
                        {
                            Session["SellerId"] = sellerList[0].SellerId;
                            return(RedirectToAction("List", "Goods", new { sellerId = sellerList[0].SellerId }));
                        }

                        return(RedirectToAction("NoSeller", "Seller"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "密码不正确请重新输入");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "登录失败:用户不存在" + msg);
                }
            }
            else
            {
                ModelState.AddModelError("", "输入信息有误,请重新输入");
            }

            authProvider.AuthFailed();
            return(View());
        }
Beispiel #5
0
        public void Dont_Pass_Remind_To_Invalid_Email()
        {
            // Arrange
            PassReminderViewModel model = new PassReminderViewModel
            {
                Email = "invalid",
            };
            IAuthProvider     authProv = new FormsAuthProvider("", "", "correct");
            AccountController target   = new AccountController(authProv);

            // Act
            ActionResult result = target.PassReminder(model, "#true", SessionStorage.Current);

            // Assert
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
Beispiel #6
0
        public ActionResult LoginAsGuest()
        {
            JsonResponseData response = new JsonResponseData()
            {
                IsSuccess = true, Msg = "登录成功"
            };

            IAuthProvider authProvider = new FormsAuthProvider();

            authProvider.AuthSuccess();

            string msg;
            var    guest = BuyerInfoBll.GetModel(1000031, out msg);

            if (guest == null)
            {
                response.IsSuccess = false;
                response.Msg       = "游客身份获取失败";
                return(Json(response));
            }



            Session["User"]    = guest;
            Session["IsGuest"] = true;


            var sellerList = BuyerInfoBll.GetSellerList(guest.BuyerId, out msg);

            if (sellerList.Count >= 1)
            {
                Session["SellerId"] = sellerList[0].SellerId;
            }

            else
            {
                Session["SellerId"] = 0;
                response.IsSuccess  = false;
                response.Msg        = "没有为体验用户指定卖家~";
                return(Json(response));
            }


            return(Json(response));
        }
Beispiel #7
0
        public void Dont_Auth_Incorrect_User()
        {
            // Arrange
            LoginViewModel userData = new LoginViewModel
            {
                Login    = "******",
                Password = "******"
            };
            string            storedPasswordHash = Convert.ToBase64String(HashPassword.HashPass("pass".ToCharArray(), new byte[0]));
            IAuthProvider     authProv           = new FormsAuthProvider(userData.Login, storedPasswordHash, "");
            AccountController target             = new AccountController(authProv);

            // Act
            ActionResult result = target.Login(userData, "#true", SessionStorage.Current);

            // Assert
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            Assert.IsFalse(((ViewResult)result).ViewData.ModelState.IsValid);
        }
Beispiel #8
0
        public ActionResult ExitLogin()
        {
            //JsonResponseData response = new JsonResponseData() { IsSuccess = true, Msg = "退出登录" };

            IAuthProvider authProvider = new FormsAuthProvider();

            authProvider.AuthFailed();


            Session["User"]     = null;
            Session["SellerId"] = 0;
            Session["IsGuest"]  = false;

            return(RedirectToAction("Login", new
            {
                isAutoLogin = false
            }
                                    ));
        }
Beispiel #9
0
        public void Dont_Pass_Remind_To_Correct_Email_With_Invalid_Captcha_3()
        {
            // Arrange
            PassReminderViewModel model = new PassReminderViewModel
            {
                Email = "correct"
            };
            IAuthProvider     authProv = new FormsAuthProvider("", "", model.Email);
            AccountController target   = new AccountController(authProv);
            SessionStorage    storage  = SessionStorage.Current;

            storage.CaptchaCode = "correct";

            // Act
            ActionResult result = target.PassReminder(model, "#true", storage);

            // Assert
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            Assert.IsTrue(storage.UnsucLoginAttempts == 1);
        }
Beispiel #10
0
        public void Auth_Correct_User()
        {
            // Arrange
            LoginViewModel userData = new LoginViewModel
            {
                Login    = "******",
                Password = "******"
            };
            string            storedPasswordHash = Convert.ToBase64String(HashPassword.HashPass(userData.Password.ToCharArray(), new byte[0]));
            IAuthProvider     authProv           = new FormsAuthProvider(userData.Login, storedPasswordHash, "");
            AccountController target             = new AccountController(authProv);
            SessionStorage    storage            = SessionStorage.Current;

            // Act
            ActionResult result = target.Login(userData, "#true", storage);

            // Assert
            Assert.IsInstanceOfType(result, typeof(RedirectResult));
            Assert.IsTrue(((RedirectResult)result).Url.Contains("#true"));
        }
Beispiel #11
0
        public ActionResult Login(bool isAutoLogin = true)
        {
            ViewBag.AppName = "趣订货电子商务有限公司";


            if (isAutoLogin && Request.Cookies["name"] != null && Request.Cookies["pwd"] != null)
            {
                string msg;
                string name = Request.Cookies["name"].Value;
                string pwd  = Request.Cookies["pwd"].Value;

                var user = BuyerInfoBll.GetModelByLoginName(name, out msg);
                if (user != null)
                {
                    if (user.Password.Equals(pwd))
                    {
                        Session["User"]    = user;
                        Session["IsGuest"] = false;
                        IAuthProvider authProvider = new FormsAuthProvider();
                        authProvider.AuthSuccess();

                        var sellerList = BuyerInfoBll.GetSellerList(user.BuyerId, out msg);
                        if (sellerList.Count > 1)
                        {
                            return(RedirectToAction("ListView", "Seller"));
                        }
                        else if (sellerList.Count == 1)
                        {
                            Session["SellerId"] = sellerList[0].SellerId;
                            return(RedirectToAction("List", "Goods", new { sellerId = sellerList[0].SellerId }));
                        }

                        return(RedirectToAction("NoSeller", "Seller"));
                    }
                }
            }

            return(View());
        }
Beispiel #12
0
        public ActionResult Login(BuyerInfoViewModel buyer, string returnUrl)
        {
            ViewBag.ReturnUrl = returnUrl;

            IAuthProvider authProvider = new FormsAuthProvider();

            if (ModelState.IsValid)
            {
                string msg;
                var    user = BuyerInfoBll.GetModelByLoginName(buyer.LoginName, out msg);
                if (user != null)
                {
                    if (user.Password.Equals(buyer.Password))
                    {
                        Session["User"] = user;
                        authProvider.AuthSuccess();
                        return(Redirect(returnUrl ?? Url.Action("MainView", "Product", new { area = "Product" })));
                    }
                    else
                    {
                        ModelState.AddModelError("", "密码不正确请重新输入");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "登录失败:" + msg);
                }
            }
            else
            {
                ModelState.AddModelError("", "输入信息有误,请重新输入");
            }

            authProvider.AuthFailed();
            return(View());
        }
Beispiel #13
0
 public AccountController()
 {
     authProv     = new FormsAuthProvider();
     authProvider = authProv;
 }