Пример #1
0
        public void Arrange()
        {
            _login = new LoginModel {EmailAddress = _emailAddress, Password = _password};
            _mother = new ObjectMother();
            _account = _mother.GetAccountByEmailAddress(_emailAddress, _password);
            _currentPlayer = new Player
            {
                Account = _account,
                Name = "Player1"
            };

            _accountRepository = new InMemoryRepository<Account>(_account);
            _playerRepository = new InMemoryRepository<Player>(_currentPlayer);

            _formsService = MockRepository.GenerateMock<IFormsService>();

            _controller = new AccountController(_accountRepository, _playerRepository, _formsService);
        }
Пример #2
0
        public ActionResult Login(LoginModel login)
        {
            if (!ModelState.IsValid)
                return View(login);
            Account account = _accountRepository.Get.ByEmailAddress(login.EmailAddress);
            if (account == null)
            {
                ModelState.AddModelErrorFor<LoginModel, string>(m => m.EmailAddress, "Unknown Email Address");
                return View(login);
            }
            if (account.Password != login.Password)
            {
                ModelState.AddModelErrorFor<LoginModel, string>(m => m.Password, "Incorrect Password.");
                return View(login);
            }

            _formsService.SignIn(login.EmailAddress, login.RememberMe);
            var player = _playerRepository.Get.CurrentPlayerFor(account);
            if (player == null || player.Account == null || player.Account != account)
                return this.RedirectToAction<GameController>(m => m.Start());
            return this.RedirectToAction<GameController>(m => m.Index());
        }