public void AuthenticateUserFailTest()
        {
            var ctx     = GetContext();
            var userBus = new UserBusiness(ctx, WeblogConfiguration.Current);

            bool result = userBus.AuthenticateUser("*****@*****.**", "Bogus");

            Assert.IsFalse(result, userBus.ErrorMessage);

            result = userBus.AuthenticateUser("*****@*****.**", "");
            Assert.IsFalse(result, userBus.ErrorMessage);

            result = userBus.AuthenticateUser("*****@*****.**", null);
            Assert.IsFalse(result, userBus.ErrorMessage);

            result = userBus.AuthenticateUser(null, "testing");
            Assert.IsFalse(result, userBus.ErrorMessage);
        }
Example #2
0
        public GTUser AuthenticateAndGetUser(string login, string password)
        {
            GTUser user = null;

            using (UserBusiness ub = new UserBusiness())
            {
                if (ub.AuthenticateUser(login, password))
                {
                    user = ub.GetUserByLogin(login);
                }
            }

            return(user);
        }
Example #3
0
        public ActionResult SignIn(UserLoginCredentials model, string returnUrl)
        {
            ViewBag.LoginError = false;
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            using (UserBusiness userBusiness = new UserBusiness())
            {
                GTUser user = null;
                if (userBusiness.AuthenticateUser(model.Login, model.Password))
                {
                    user = userBusiness.GetUserByLogin(model.Login);
                }

                //Checa por erros de domínio
                if (this.CheckForDomainErrors(userBusiness))
                {
                    ViewBag.LoginError = true;
                    return(View(model));
                }

                //Salva o estado do usuário em sessão
                this.SetGTUser(user);
            }
            //Cria um cookie de autenticação para manter a sessão do usuário
            FormsAuthentication.SetAuthCookie(model.Login, false);

            if (!String.IsNullOrWhiteSpace(returnUrl))
            {
                return(Redirect(returnUrl));
            }

            return(RedirectToAction("Index", "Home"));
        }