public ActionResult AutenticarUsuario(UsuarioModelLogin model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    UsuarioDal d = new UsuarioDal();
                    Usuario u = d.Find(model.Login, Criptografia.EncriptarMD5(model.Senha));

                    if (u != null)
                    {
                        FormsAuthentication.SetAuthCookie(u.Login, false);

                        Session.Add("usuario", u);

                        return RedirectToAction("Home", "UsuarioAutenticado");

                    }
                    else
                    {
                        ViewBag.Mensagem = "Acesso Negado. Tente Novamente.";
                    }
                }

            }
            catch (Exception ex)
            {
                ViewBag.Mensagem = ex.Message;
            }

            return View("Login");
        }
Example #2
0
        protected void btnAcesso_Click(object sender, EventArgs e)
        {
            try
            {

                string login = txtLogin.Text;
                string senha = txtSenha.Text;

                UsuarioDal d = new UsuarioDal();
                Usuario u = d.Find(login, Criptografia.Encriptar(senha));

                if (u!= null)
                {
                    FormsAuthentication.SetAuthCookie(login, false);

                    Response.Redirect("/Pages/Produto.aspx");
                }

            }
            catch (Exception ex)
            {

                lblMensagem.Text = ex.Message;
            }
        }
        public ActionResult CadastrarUsuario(UsuarioModelCadastro model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (model.Senha.Equals(model.SenhaConfirm))
                    {
                        UsuarioDal d = new UsuarioDal();

                        if(! d.HasLogin(model.Login))
                        {
                            Usuario u = new Usuario();
                            u.Nome = model.Nome;
                            u.Login = model.Login;
                            u.Senha =  Criptografia.EncriptarMD5(model.Senha);

                            d.Inserir(u);

                            ViewBag.Mensagem = "Usuário "+ u.Nome + ", cadastrado com sucesso.";

                            ModelState.Clear();
                        }
                        else
                        {
                            throw new Exception("Erro. Login indisponivel. Tente outro");
                        }

                    }
                    else
                    {
                        throw new Exception("Erro. Informe as senhas corretamente.");
                    }
                }
            }
            catch (Exception ex)
            {

                 ViewBag.Mensagem = ex.Message;
            }

            return View("Cadastro");
        }
Example #4
0
        protected void btnCadastro_Click(object sender, EventArgs e)
        {
            try
            {
                string senha1 = txtSenhaAcesso.Text;
                string senha2 = txtSenhaConfirm.Text;

                if (senha1.Equals(senha2))
                {
                    Usuario u = new Usuario();

                    u.Nome = txtNome.Text;
                    u.Email = txtEmail.Text;
                    u.Login = txtLoginAcesso.Text;
                    u.Senha = Criptografia.Encriptar(senha1);
                    u.DataCadastro = DateTime.Now;

                    UsuarioDal d = new UsuarioDal();
                    d.Insert(u);

                    lblMensagem.Text = "O usuario " + u.Nome + ", cadastrado com sucesso.";

                    txtNome.Text = string.Empty;
                    txtEmail.Text = string.Empty;
                    txtLoginAcesso.Text = string.Empty;
                }
                else
                {
                    lblMensagem.Text = "ERRO. Confirme sua senha corretamente";
                }

            }
            catch (Exception ex)
            {

                lblMensagem.Text="Erro ao cadastrar usuario " + ex.Message;
            }
        }