コード例 #1
0
        public void CanLoginSuccessfullyWithCorrcectUserNameAndPassword()
        {
            var request = new LoginRequest {Username = Username, Password = Password};
            SetupMockUserRepo();
            var handler = new LoginRequestHandle(_mockUserRepo.Object);

            var response = handler.Handle(request);

            Assert.That(response.Status, Is.EqualTo(ResponseCodes.Success));
        }
コード例 #2
0
        public void ReturnsFailureCodeIfAUserCouldNotBeFoundWithCredentials()
        {
            var request = new LoginRequest { Username = "******", Password = Password };
            SetupMockUserRepo();
            var handler = new LoginRequestHandle(_mockUserRepo.Object);

            var response = handler.Handle(request);

            Assert.That(response.Status, Is.EqualTo(ResponseCodes.LoginAndPasswordMismatch));
        }
コード例 #3
0
        public ActionResult LogIn(LogOnModel model)
        {
            var handler = new LoginRequestHandle(new UserRepository());

            var request = new LoginRequest { Password = model.Password, Username = model.UserName };

            var response = handler.Handle(request);

            if (response.Status == ResponseCodes.Success)
            {
                FormsAuthentication.SetAuthCookie(model.UserName, false);

                return RedirectToAction("ChooseProfile", "Profile");
            }

            var errorMessage = response.Status.GetMessage();
            ModelState.AddModelError("", errorMessage);

            return View(model);
        }