Exemple #1
0
    public void btnSalva(TextBox Nome, TextBox CPF, TextBox CEP, TextBox Email, TextBox Usuario, TextBox Senha, FileUpload FileUpload1, Label titleErro, Label msgErro, HtmlGenericControl modal, HtmlGenericControl modalback, HtmlGenericControl overflow, Label lblNome, Label lblCPF, Label lblCEP, Label lblEmail, Label lblUsuario)
    {
        string novosValores = "";
        bool   first = false, IsImageUpload = false, userChanged = false, passChanged = false;

        if (!FileUpload1.HasFile)
        {
            HttpContext.Current.Session["novosValores"] = "";
        }
        else if (!(FileUpload1.PostedFile.ContentType == "image/jpg" ||
                   FileUpload1.PostedFile.ContentType == "image/png" ||
                   FileUpload1.PostedFile.ContentType == "image/bmp" ||
                   FileUpload1.PostedFile.ContentType == "image/tiff" ||
                   FileUpload1.PostedFile.ContentType == "image/gif" ||
                   FileUpload1.PostedFile.ContentType == "image/jpeg"))
        {
            ut.showErrorMessage("Não é imagem", "Esse arquivo que você jogou ai não é uma imagem, por favor insira um arquivo que seja uma imagem", titleErro, msgErro, modal, modalback, overflow);
        }
        else if (FileUpload1.PostedFile.ContentLength > 8388608)
        {
            ut.showErrorMessage("Imagem muito grande", "Essa imagem que você colocou aí tem um tamanho muito grande. Por favor insira uma imagem menor que 8MB", titleErro, msgErro, modal, modalback, overflow);
        }
        else
        {
            try
            {
                HttpFileCollection   hfc   = HttpContext.Current.Request.Files;
                System.Drawing.Image image = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream);
                HttpPostedFile       hpf   = hfc[0];
                if (hpf.ContentLength > 0)
                {
                    byte[] imgBytes = null;
                    string ext      = Path.GetExtension(hpf.FileName).ToLower();
                    if (ext == ".jpeg" || ext == ".jpg")
                    {
                        imgBytes = ut.ConvertImageToByteArray(image, System.Drawing.Imaging.ImageFormat.Jpeg);
                    }
                    else if (ext == ".png")
                    {
                        imgBytes = ut.ConvertImageToByteArray(image, System.Drawing.Imaging.ImageFormat.Png);
                    }
                    else if (ext == ".bmp")
                    {
                        imgBytes = ut.ConvertImageToByteArray(image, System.Drawing.Imaging.ImageFormat.Bmp);
                    }
                    else if (ext == ".tiff")
                    {
                        imgBytes = ut.ConvertImageToByteArray(image, System.Drawing.Imaging.ImageFormat.Tiff);
                    }
                    else if (ext == ".gif")
                    {
                        imgBytes = ut.ConvertImageToByteArray(image, System.Drawing.Imaging.ImageFormat.Gif);
                    }


                    sql.updateImagem(imgBytes, HttpContext.Current.Session["usuario"].ToString());
                    IsImageUpload = true;
                }
            }
            catch (Exception e) { }
        }



        if (!string.IsNullOrEmpty(Nome.Text))
        {
            string nomeSemEspacos = ut.retirarEspacos(Nome.Text);
            if (!nomeSemEspacos.Contains(' '))
            {
                ut.showErrorMessageByLbl("Nome Completo - Inválido, deve estar completo", Nome, lblNome);
                return;
            }
            else if (v.validarNome(nomeSemEspacos))
            {
                first = true;
                HttpContext.Current.Session["novosValores"] += "nome = ''" + Nome.Text + "''";
            }
            else
            {
                ut.showErrorMessageByLbl("Nome Completo - Inválido, deve estar completo", Nome, lblNome);
                return;
            }
        }

        if (!string.IsNullOrEmpty(CPF.Text))
        {
            if (v.validarCPF(CPF.Text))
            {
                if (!sql.selectHasRows("*", "tblCliente", "cpf = ''" + CPF.Text + "''"))
                {
                    if (first)
                    {
                        HttpContext.Current.Session["novosValores"] += ",cpf = ''" + CPF.Text + "''";
                    }
                    else
                    {
                        HttpContext.Current.Session["novosValores"] += "cpf = ''" + CPF.Text + "''";
                        first = true;
                    }
                }
                else
                {
                    ut.showErrorMessageByLbl("CPF - Em uso, já tem uma conta com esse CPF", CPF, lblCPF);
                    return;
                }
            }
            else
            {
                ut.showErrorMessageByLbl("CPF - Inválido, este cpf não é válido", CPF, lblCPF);
                return;
            }
        }

        if (!string.IsNullOrEmpty(CEP.Text))
        {
            if (v.validarCep(CEP.Text))
            {
                if (first)
                {
                    HttpContext.Current.Session["novosValores"] += ",cep = ''" + CEP.Text + "''";
                }
                else
                {
                    HttpContext.Current.Session["novosValores"] += "cep = ''" + CEP.Text + "''";
                    first = true;
                }
            }
            else
            {
                ut.showErrorMessageByLbl("CEP - Inválido, Relaxa, não vamos invadir sua casa.", CEP, lblCEP);
                return;
            }
        }

        string emailSemEspacos = "";

        if (!string.IsNullOrEmpty(Email.Text))
        {
            emailSemEspacos = ut.retirarEspacos(Email.Text);
            if (v.validarEmail(emailSemEspacos))
            {
                if (!sql.selectHasRows("*", "tblCliente", "email = ''" + emailSemEspacos + "''"))
                {
                    if (first)
                    {
                        HttpContext.Current.Session["novosValores"] += ",email = ''" + emailSemEspacos + "''";
                    }
                    else
                    {
                        HttpContext.Current.Session["novosValores"] += "email = ''" + emailSemEspacos + "''";
                        first = true;
                    }
                }
                else
                {
                    ut.showErrorMessageByLbl("E-mail - Em uso, já tem uma conta com esse e-mail", Email, lblEmail);
                    return;
                }
            }
            else
            {
                ut.showErrorMessageByLbl("E-mail - Invalido, esse e-mail não é valido", Email, lblEmail);
                return;
            }
        }

        if (!string.IsNullOrEmpty(Usuario.Text))
        {
            string usuSemEspacos = ut.retirarEspacos(Usuario.Text);
            if (v.validarUsu(usuSemEspacos))
            {
                if (!sql.selectHasRows("*", "tblCliente", "usuario = ''" + usuSemEspacos + "''"))
                {
                    if (first)
                    {
                        HttpContext.Current.Session["novosValores"] += ",usuario = ''" + usuSemEspacos + "''";
                    }
                    else
                    {
                        HttpContext.Current.Session["novosValores"] += "usuario = ''" + usuSemEspacos + "''";
                        first = true;
                    }
                    if (!HttpContext.Current.Session["novosValores"].ToString().Contains("email"))
                    {
                        HttpContext.Current.Session["usuarioNovo"] = usuSemEspacos;
                    }
                    userChanged = true;
                }
                else
                {
                    ut.showErrorMessageByLbl("Usuário - Em uso, já existe uma conta com esse usuário :/", Usuario, lblUsuario);
                    return;
                }
            }
            else
            {
                ut.showErrorMessageByLbl("Usuário - Deve ter apenas letras,numeros, _ e -", Usuario, lblUsuario);
                return;
            }
        }

        if (!string.IsNullOrEmpty(Senha.Text))
        {
            if (first)
            {
                HttpContext.Current.Session["novosValores"] += ",senha = ''" + Senha.Text + "''";
            }
            else
            {
                HttpContext.Current.Session["novosValores"] += "senha = ''" + Senha.Text + "''";
                first = true;
            }
            passChanged = true;
        }

        if (HttpContext.Current.Request.Cookies["credenciais"] != null)
        {
            if (userChanged && passChanged)
            {
                HttpCookie cookie = new HttpCookie("credenciais");
                cookie.Values["usuario"] = HttpContext.Current.Session["usuarioNovo"].ToString();
                cookie.Values["senha"]   = Senha.Text;
                cookie.Expires           = DateTime.Now.AddDays(365);
                HttpContext.Current.Response.Cookies.Add(cookie);
                userChanged = true;
            }
            else if (userChanged == true && passChanged == false)
            {
                string     senha  = HttpContext.Current.Request.Cookies["credenciais"]["senha"];
                HttpCookie cookie = new HttpCookie("credenciais");
                cookie.Values["usuario"] = HttpContext.Current.Session["usuarioNovo"].ToString();
                cookie.Values["senha"]   = senha;
                cookie.Expires           = DateTime.Now.AddDays(365);
                HttpContext.Current.Response.Cookies.Add(cookie);
                userChanged = true;
            }
            else if (userChanged == false && passChanged == true)
            {
                string     usuario = HttpContext.Current.Request.Cookies["credenciais"]["usuario"];
                HttpCookie cookie  = new HttpCookie("credenciais");
                cookie.Values["usuario"] = usuario;
                cookie.Values["senha"]   = Senha.Text;
                cookie.Expires           = DateTime.Now.AddDays(365);
                HttpContext.Current.Response.Cookies.Add(cookie);
                userChanged = true;
            }
        }

        if (first)
        {
            if (HttpContext.Current.Session["novosValores"].ToString().Contains("email"))
            {
                ut.showErrorMessage("Estamos quase lá.", "Um código foi enviado pro seu email. Agora é só colocar ele aqui.", titleErro, msgErro, modal, modalback, overflow);
                HttpContext.Current.Session["codigo-mudanca"] = ut.gerarStringConfirmacao();
                ut.enviarEmailConfirmacao(HttpContext.Current.Session["codigo-mudanca"].ToString(), emailSemEspacos, "Alterar email", "Seu email pode ser redefinido utilizando o código abaixo. Se você não pediu uma troca, finja que nunca nem viu esse email.");
                modal.Attributes["class"]           = "modal-wrap minha-conta is-showing codigo";
                HttpContext.Current.Session["temp"] = ut.retirarEspacos(Usuario.Text);
                return;
            }
            else
            {
                string usuSemEspacos = ut.retirarEspacos(Usuario.Text);
                sql.update("tblCliente", "'usuario = ''" + HttpContext.Current.Session["usuario"].ToString() + "'''", "'" + HttpContext.Current.Session["novosValores"].ToString() + "'");
            }
        }
        else if (IsImageUpload)
        {
            HttpContext.Current.Response.Redirect("minha-conta.aspx");
        }
        HttpContext.Current.Response.Redirect("minha-conta.aspx");
    }
Exemple #2
0
    public void btnValida(TextBox txtNome, HtmlGenericControl border, TextBox txtUsu, HtmlGenericControl step, Label lblH1Dica, Label lblDica, TextBox txtEmail, TextBox txtCodigo, Button ReenviarEmail, TextBox txtCpf, TextBox txtSenha, TextBox txtCSenha, Label lblErro)
    {
        bool existe = true;

        //Switch case para cada caso do AUX
        //Se a validacão der erro, o AUX será o mesmo e assim caindo no mesmo caso até o usuário acertar
        switch (Convert.ToInt32(HttpContext.Current.Session["aux"]))
        {
        case 0:
            if (string.IsNullOrEmpty(txtNome.Text) || string.IsNullOrWhiteSpace(txtNome.Text))
            {
                IsNotValid(txtNome, "Nome completo inválido", 0, txtNome, lblErro, border);
                break;
            }

            string nome = ut.retirarEspacos(txtNome.Text);

            if (!v.validarNome(nome) || !nome.Contains(" "))
            {
                IsNotValid(txtNome, "Nome completo inválido", 0, txtNome, lblErro, border);
                border.Attributes["class"] = "textbox-type2-overflow overflow-cad not-valid";
                break;
            }
            else
            {
                IsValid("nome", txtNome, txtUsu, 1, nome, lblErro, border);
                step.Attributes["class"] = "step step1";
                lblH1Dica.Text           = "Hey, " + HttpContext.Current.Session["nome"] + "!";
                lblDica.Text             = "Defina um apelido pra você. <br/> Ele deve ter no mínimo 4 letras e caracteres especiais, exceto _ e - não são permitidos.";
                break;
            }

        case 1:
            txtNome.Attributes["class"] = "textbox textbox-type2 textbox-cad";

            if (string.IsNullOrEmpty(txtUsu.Text) || string.IsNullOrWhiteSpace(txtUsu.Text))
            {
                IsNotValid(txtNome, "Usuário deve ser preenchido.", 1, txtUsu, lblErro, border);
                break;
            }

            string usuario = ut.retirarEspacos(txtUsu.Text);
            existe = ut.verificarCampoExistenteBanco("usuario", usuario);

            if (!v.validarUsu(usuario))
            {
                IsNotValid(txtNome, "Esse apelido é inválido.", 1, txtUsu, lblErro, border);
                break;
            }
            else if (existe)
            {
                IsNotValid(txtNome, "Usuário já em uso.", 1, txtUsu, lblErro, border);
                break;
            }
            else if (usuario.Contains(" "))
            {
                IsNotValid(txtNome, "O usuário não pode conter espaços.", 1, txtUsu, lblErro, border);
                break;
            }
            else
            {
                IsValid("usu", txtUsu, txtEmail, 2, usuario, lblErro, border);
                step.Attributes["class"] = "step step2";
                lblH1Dica.Text           = "Agora vamos te chamar de " + HttpContext.Current.Session["usu"] + ".";
                lblDica.Text             = "Agora insira seu melhor e-mail.";
                break;
            }

        case 2:
            txtUsu.Attributes["class"] = "textbox textbox-type2 textbox-cad";

            if (string.IsNullOrEmpty(txtEmail.Text) || string.IsNullOrWhiteSpace(txtEmail.Text))
            {
                IsNotValid(txtUsu, "Email inválido.", 2, txtEmail, lblErro, border);
                break;
            }

            string email = ut.retirarEspacos(txtEmail.Text);
            existe = ut.verificarCampoExistenteBanco("email", email);

            if (!v.validarEmail(email))
            {
                IsNotValid(txtUsu, "Email inválido.", 2, txtEmail, lblErro, border);
                break;
            }
            else if (existe)
            {
                IsNotValid(txtUsu, "Email já em uso.", 2, txtEmail, lblErro, border);
                break;
            }
            else
            {
                IsValid("email", txtEmail, txtCodigo, 3, email, lblErro, border);
                step.Attributes["class"]              = "step step3";
                HttpContext.Current.Session["email"]  = email;
                HttpContext.Current.Session["codigo"] = ut.gerarStringConfirmacao();
                ut.enviarEmailConfirmacao(HttpContext.Current.Session["codigo"].ToString(), HttpContext.Current.Session["email"].ToString(), "Confirmar E-mail", "Utilize o código abaixo para corfimar seu email. Se você não está criando uma conta na Acroni, finja que nunca nem viu esse email.");
                ReenviarEmail.Attributes.Add("style", "display: block");
                lblH1Dica.Text = "Legal! Agora você só precisa confirmar que é você.";
                lblDica.Text   = "Confira o código no seu e-mail.";
                break;
            }

        case 3:
            txtEmail.Attributes["class"] = "textbox textbox-type2 textbox-cad";
            ReenviarEmail.Attributes.Add("style", "display: block");

            if (!txtCodigo.Text.ToLower().Equals(HttpContext.Current.Session["codigo"].ToString().ToLower()))
            {
                IsNotValid(txtEmail, "Os códigos não coincidem", 3, txtCodigo, lblErro, border);

                break;
            }
            else if (!(txtCodigo.Text.ToLower().Equals(HttpContext.Current.Session["codigo"].ToString().ToLower())))
            {
                IsNotValid(txtEmail, "Os códigos não coincidem", 3, txtCodigo, lblErro, border);
                break;
            }
            else
            {
                IsValid("codigo", txtCodigo, txtCpf, 4, lblErro, border);
                step.Attributes["class"] = "step step4";
                ReenviarEmail.Attributes.Add("style", "display: none");
                lblH1Dica.Text = "Uma pessoa sempre tem um CPF.";
                lblDica.Text   = "Digita ele aí pra nós.";
                break;
            }

        case 4:
            txtUsu.Attributes["class"]    = "textbox textbox-type2 textbox-cad";
            txtCodigo.Attributes["class"] = "textbox textbox-type2 textbox-cad";
            ReenviarEmail.Attributes.Add("style", "display: none");

            if (!v.validarCPF(txtCpf.Text))
            {
                IsNotValid(txtEmail, "CPF inválido", 4, txtCpf, lblErro, border);
                break;
            }
            else if (ut.verificarCampoExistenteBanco("cpf", txtCpf.Text))
            {
                IsNotValid(txtEmail, "CPF já cadastrado", 4, txtCpf, lblErro, border);
                break;
            }
            else
            {
                IsValid("cpf", txtCpf, txtSenha, 5, lblErro, border);
                step.Attributes["class"] = "step step5";
                lblH1Dica.Text           = "E por fim, sua senha.";
                lblDica.Text             = "As senhas dos melhores tem mais de 8 dígitos, com letras maiúsculas e minúsculas, números e símbolos.";
                break;
            }

        case 5:
            txtCpf.Attributes["class"] = "textbox textbox-type2 textbox-cad";

            if (txtSenha.Text == "" || string.IsNullOrWhiteSpace(txtSenha.Text))
            {
                IsNotValid(txtEmail, "Campo de senha vazio :/", 5, txtSenha, lblErro, border);
                break;
            }
            else
            {
                IsValid("senha", txtSenha, txtCSenha, 6, lblErro, border);
                lblH1Dica.Text = "Confirme sua senha.";
                lblDica.Text   = "Nunca se sabe as loucuras que a gente digita lá atrás.";
                break;
            }

        case 6:
            txtSenha.Attributes["class"] = "textbox textbox-type2 textbox-cad";
            if (txtCSenha.Text != HttpContext.Current.Session["senha"].ToString())
            {
                IsNotValid(txtCSenha, "As senhas não coincidem", 6, txtCSenha, lblErro, border);
                break;
            }
            else
            {
                ut.inserirUsuario(HttpContext.Current.Session["nome"].ToString(), HttpContext.Current.Session["usu"].ToString(), HttpContext.Current.Session["email"].ToString(), HttpContext.Current.Session["cpf"].ToString(), HttpContext.Current.Session["senha"].ToString());
                if (HttpContext.Current.Request.QueryString["compra"] != "1")
                {
                    HttpContext.Current.Response.Redirect("~/View/default.aspx");
                }
                else
                {
                    HttpContext.Current.Session["usuario"] = HttpContext.Current.Session["usu"];
                    HttpContext.Current.Session["logado"]  = 1;
                    HttpContext.Current.Response.Redirect("~/View/escolher-pagamento.aspx");
                }

                break;
            }
        }
    }