示例#1
0
        public ActionResult LogOn(LogOn logOn, string returnUrl)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    UsuarioService usuarioService = new UsuarioService();

                    if (usuarioService.ValidaUsuario(logOn))
                    {
                        FormsAuthentication.SetAuthCookie(logOn.Login, logOn.RememberMe);
                        if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                            && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                        {
                            return Redirect(returnUrl);
                        }
                        else
                        {
                            return RedirectToAction("Index", "Home");
                        }
                    }
                    else
                    {
                        ViewBag.Error = "Usuário ou Senha inválidos";
                    }
                }
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
            }

            return View(logOn);
        }
示例#2
0
        public bool ValidaUsuario(LogOn logOn)
        {
            string senhaCriptografada = Crypt.Encrypt(logOn.Senha);

            using (Context db = new Context())
            {
                Usuario usuario = (from u in db.Usuario
                                  where u.Senha.Equals(senhaCriptografada)
                                   where u.Login.Equals(logOn.Login)
                                 select u).FirstOrDefault();

                if (usuario != null)
                    return true;

                return false;
            }
        }