Exemplo n.º 1
0
        public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            if (membershipManagementService.LogIn(model))
            {
                return RedirectToLocal(returnUrl);
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            return View(model);
        }
Exemplo n.º 2
0
        public void ValidUserTryLogIn_UserLogIn()
        {
            // Setup
            var user = new LoginViewModel() { Email = "Matthew", Password = "******" };
            var formsAuthentication = new Mock<IFormsAuthenticationService>();

            var userService = new Mock<IUserService>();
            userService.Setup(f => f.ValidateUser(user.Email, user.Password)).Returns(true);

            IMembershipManagementService membershipManagementService = new MembershipManagementService(userService.Object, formsAuthentication.Object, new Mock<IEUniversityUow>().Object,
                new Mock<IAuthorizationService>().Object, new Mock<IRoleService>().Object, new Mock<IStudentProfileService>().Object);
            // Action
            var isLogIn = membershipManagementService.LogIn(user);
            // Verify the result
            formsAuthentication.Verify(x => x.SetAuthCookie(It.IsAny<string>(), false), Times.Once());
            Assert.IsTrue(isLogIn);
        }
 /// <summary>
 /// Logs the in.
 /// </summary>
 /// <param name="loginViewModel"></param>
 /// <returns> true if the supplied user name and password are valid; otherwise, false. </returns>
 public bool LogIn(LoginViewModel loginViewModel)
 {
     if (userService.ValidateUser(loginViewModel.Email, loginViewModel.Password))
     {
         formsAuthenticationService.SetAuthCookie(loginViewModel.Email, false);
         return true;
     }
     return false;
 }