Esempio n. 1
0
        public LoginViewModel Index(LoginViewModel loginModel)
        {
            if ( loginModel.HasCredentials())
            {
                var userId = _securityDataService.AuthenticateForUserId(loginModel.Username, loginModel.Password);

                if (userId.HasValue)
                {
                    _authContext.ThisUserHasBeenAuthenticated(userId.Value.ToString(), loginModel.RememberMeChecked);

                    loginModel.ErrorMessage = null;
                    loginModel.AuthenticationSuccessful = true;

                    var redirectUrl = loginModel.ReturnUrl.IsNotEmpty()
                                          ? loginModel.ReturnUrl
                                          : _resolver.Home();

                    loginModel.ResultOverride = new RedirectResult(redirectUrl);

                    return loginModel;
                }

                loginModel.ErrorMessage = "Invalid username or password";
            }

            return loginModel;
        }
        public void SetUp()
        {
            _security = MockRepository.GenerateStub<ISecurityDataService>();
            _authContext = MockRepository.GenerateMock<IAuthenticationContext>();
            _resolver = MockRepository.GenerateMock<IUrlResolver>();
            _controller = new LoginController(_security, _authContext, _resolver);

            _loginModel = new LoginViewModel();
            _security.Stub(s => s.AuthenticateForUserId("foo", "bar")).Return(null);
        }
        public void SetUp()
        {
            _security = MockRepository.GenerateStub<ISecurityDataService>();
            _authContext = MockRepository.GenerateMock<IAuthenticationContext>();
            _resolver = MockRepository.GenerateMock<IUrlResolver>();
            _controller = new LoginController(_security, _authContext, _resolver);

            _userId = Guid.NewGuid();
            _security.Stub(s => s.AuthenticateForUserId("foo", "bar")).Return(_userId);

            _returnUrl = "TESTRETURN";
            _loginModel = new LoginViewModel {Username = "******", Password = "******", RememberMeChecked = true, ReturnUrl=_returnUrl};

            _result = _controller.Index(_loginModel);
        }