private void BtnAceptar_Click(object sender, EventArgs e)
        {
            if ((txtUsuario.Text == ""))
            {
                MessageBox.Show("Se debe ingresar un usuario.", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if ((txtPass.Text == ""))
            {
                MessageBox.Show("Se debe ingresar una contraseña.", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            var usr = sUsuario.ValidarUsuario(txtUsuario.Text, txtPass.Text);

            if (usr != null)
            {
                UsuarioLogueado = usr.NombreUsuario;
                this.Close();
            }
            else
            {
                txtPass.Text = "";
                txtPass.Focus();
                MessageBox.Show("Debe ingresar usuario y/o contraseña válidos", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #2
0
 public ActionResult Login(LoginViewModel loginViewModel, string returnURL)
 {
     if (ModelState.IsValid)
     {
         MUsuario user = sUsuario.ValidarUsuario(loginViewModel.Username, loginViewModel.Senha);
         if (user == null)
         {
             ModelState.AddModelError("", "Nome ou senha inválido(s).");
         }
         else
         {
             var ticket = FormsAuthentication.Encrypt(new FormsAuthenticationTicket(1, user.ToString(), DateTime.Now, DateTime.Now.AddHours(12), false, sRole.ListRole(user.IdPerfil).Nome));
             var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, ticket);
             Response.Cookies.Add(cookie);
             if (Url.IsLocalUrl(returnURL))
             {
                 return(Redirect(returnURL));
             }
             else
             {
                 return(RedirectToAction("Index", "Home", new { Area = "Home", id = user.ID }));
             }
         }
     }
     return(View(loginViewModel));
 }