Ejemplo n.º 1
0
        public ActionResult Login(LoginModel model)
        {
            if (model.IsValid())
            {
                return Redirect("/user/apps");
            }

            model.Msg = "bir sorun oluştu";
            return View(model);
        }
Ejemplo n.º 2
0
        public ActionResult Login()
        {
            var model = new LoginModel()
            {
                Email = "*****@*****.**",
                Password = "******"
            };

            return View(model);
        }
Ejemplo n.º 3
0
        public async Task<ActionResult> Login(LoginModel model)
        {
            if (!model.IsValid())
            {
                model.Msg = "bir sorun oluştu";
                return View(model);
            }

            var authenticated = await _userService.Authenticate(model.Email, model.Password);
            if (!authenticated)
            {
                model.Msg = "bir sorun oluştu";
                return View(model);
            }

            var user = await _userService.GetByEmail(model.Email);
            _formsAuthenticationService.SignIn(string.Format("{0}|{1}", user.Id, user.Name), true);

            return Redirect("/user/apps");
        }
Ejemplo n.º 4
0
        public ActionResult Login()
        {
            var model = new LoginModel();

            return View(model);
        }
Ejemplo n.º 5
0
        public async void login_should_return_with_login_model_if_model_is_invalid()
        {
            //arrange
            var invalidModel = new LoginModel { Email = "*****@*****.**" };

            //act
            var sut = new UserControllerBuilder().Build(); ;
            var view = await sut.Login(invalidModel) as ViewResult;

            //assert
            Assert.NotNull(view);
            var model = view.Model;
            Assert.NotNull(model);
            Assert.IsAssignableFrom(typeof(LoginModel), model);

            sut.AssertPostAndAntiForgeryTokenAttribute("Login", new[] { typeof(LoginModel) });
            sut.AssertAllowAnonymousAttribute("Login", new[] { typeof(LoginModel) });
        }
Ejemplo n.º 6
0
        public async void login_should_redirect_if_model_is_valid()
        {
            //arrange   
            const int id = 1;
            const string email = "*****@*****.**";
            const string name = "test";
            var validModel = new LoginModel { Email = email, Password = "******" };

            var userService = new Mock<IUserService>();
            userService.Setup(x => x.Authenticate(validModel.Email, validModel.Password)).Returns(() => Task.FromResult(true));
            userService.Setup(x => x.GetByEmail(validModel.Email))
                                    .Returns(() => Task.FromResult(new User
                                                                    {
                                                                        Id = id,
                                                                        Name = name,
                                                                        Email = email
                                                                    }));

            var formsAuthenticationService = new Mock<IFormsAuthenticationService>();
            formsAuthenticationService.Setup(x => x.SignIn(string.Format("{0}|{1}|{2}", id, name, email), true));

            //act
            var sut = new UserControllerBuilder().WithUserService(userService.Object)
                                                 .WithFormsAuthenticationService(formsAuthenticationService.Object)
                                                 .Build();
            var view = await sut.Login(validModel) as RedirectResult;

            //assert
            Assert.NotNull(view);
            Assert.AreEqual(view.Url, "/user/apps");
            userService.Verify(x => x.Authenticate(validModel.Email, validModel.Password), Times.Once);

            sut.AssertPostAndAntiForgeryTokenAttribute("Login", new[] { typeof(LoginModel) });
            sut.AssertAllowAnonymousAttribute("Login", new[] { typeof(LoginModel) });
        }