Esempio n. 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Usuario            u          = new Usuario();
            UsuarioRepositorio uRecuperar = new UsuarioRepositorio();

            HashConfirmacao hc = new HashConfirmacao();

            string hash = hc.GerarHash(30).ToString();

            if (uRecuperar.RecuperarSenha(Request.QueryString["email"].ToString(), hash))
            {
                MailMessage message    = null;
                IsEmail     enviarConf = new IsEmail();

                string urlConf = null;
                if (HttpContext.Current.Request.IsLocal)
                {
                    urlConf = "http://*****:*****@gmail.com", Request.QueryString["email"].ToString())
                {
                    Subject = "Recuperar / Alterar senha",
                    Body = strBody.ToString()
                })

                    enviarConf.Enviar(message);

                Response.Write("E-mail enviado com sucesso");
            }
            else
            {
                Response.Write("E-mail não localizado...");
            }
        }
Esempio n. 2
0
        //AO CLICAR NO BOTÃO CADASTRAR
        protected void btCadastrar_Click(object sender, EventArgs e)
        {
            Usuario u = new Usuario();

            //VARIFICAR QUAL O TIPO DE PESSOA (FÍSICA OU JURÍDICA)
            if (dpTipoPessoa.SelectedValue == "2")//PESSOA JURÍDICA
            {
                IsCpfCnpj cnpj = new IsCpfCnpj();
                txtCnpj.Text = txtCnpj.Text.Replace(">", "").Replace(",", "").Replace(".", "").Replace("-", "").Replace("/", "");
                if (cnpj.validarCpfCnpj(txtCnpj.Text))
                {
                    u.CpfCnpj = txtCnpj.Text;
                }
                else
                {
                    //txtCnpj.Text = null;
                    txtCnpj.BorderColor = System.Drawing.Color.Red;
                    return;
                }
                u.Nome = txtRazaoSocial.Text;
            }
            else if (dpTipoPessoa.SelectedValue == "1")//PESSOA FÍSICA
            {
                IsCpfCnpj cpf = new IsCpfCnpj();
                txtCpf.Text = txtCpf.Text.Replace(">", "").Replace(",", "").Replace(".", "").Replace("-", "").Replace("/", "");
                if (cpf.validarCpfCnpj(txtCpf.Text))
                {
                    u.CpfCnpj = txtCpf.Text;
                }
                else
                {
                    //txtCpf.Text = "";
                    txtCpf.BorderColor = System.Drawing.Color.Red;
                    return;
                }
                u.Nome      = txtNome.Text;
                u.Sobrenome = txtSobrenome.Text;
                u.Genero    = int.Parse(dpGenero.SelectedValue);
            }

            //VERIFICAR SE O E-MAIL É VÁLIDO
            IsEmail mail = new IsEmail();

            if (mail.ValidarEmail(txtEmailEtapa2.Text))
            {
                u.Email = txtEmailEtapa2.Text;
            }
            else
            {
                txtEmailEtapa2.BorderColor = System.Drawing.Color.Red;
                dvMsg.Visible             = true;
                dvMsg.Attributes["class"] = "alert alert-info alert-dismissible";
                lbMsg.Text = "Por favor, digite um email válido.<a class='glyphicon glyphicon-question-sign' href='/Views/SistemaAjuda.aspx?help=5' target='_blank'></a>";
                return;
            }
            u.Telefone = txtTel.Text;

            //CRIPTOGRAFA A SENHA
            Criptografia criptografia = new Criptografia();

            u.Senha = criptografia.CriptografarSenha(txtSenha.Text);

            //VERIFICAR QUAL O TIPO DE USUÁRIO
            if (rdComprar.Checked == true)
            {
                u.Tipousuario = new TipoUsuario(int.Parse(rdComprar.Value));
                u.AreaAtuacao = 5;
            }
            else if (rdVender.Checked == true)
            {
                u.Tipousuario = new TipoUsuario(int.Parse(rdVender.Value));
                u.AreaAtuacao = Convert.ToDouble(dpArea.SelectedValue);
            }

            //RECEEBR COORDENADAS DO ENDEREÇO DO USUÁRIO
            Usuario uEndereco = (Usuario)Session["latlog"];

            u.Latitude       = uEndereco.Latitude;
            u.Longitude      = uEndereco.Longitude;
            txtEndereco.Text = txtEndereco.Text.Replace("-", "");
            u.CEP            = txtEndereco.Text;
            u.Complemento    = txtComplemento.Text;
            u.Numero         = int.Parse(txtNumero.Text);

            //CRIAR UM HASH PARA CONFIRMAÇÃO DE CADASTRO POR E-MAIL
            HashConfirmacao hc = new HashConfirmacao();

            u.HashConfirmacao = hc.GerarHash(30);

            UsuarioRepositorio cadastrar = new UsuarioRepositorio();

            //VERIFICAR SE E-MAIL JÁ POSSUI CADASTRO
            string existe = cadastrar.ValidarEmailCpfCnpj(u);

            //SE NÃO POSSUI CADASTRO, CADASTRAR
            if (existe == null)
            {
                if (cadastrar.CadastrarUsuario(u))
                {
                    //GERAR LINK DE CONFIRMAÇÃO
                    MailMessage   message    = null;
                    IsEmail       enviarConf = new IsEmail();
                    string        urlConf    = null;
                    StringBuilder strBody;

                    if (HttpContext.Current.Request.IsLocal)
                    {
                        urlConf = "http://*****:*****@gmail.com", u.Email.ToString())
                    {
                        Subject = "Confirmação de Cadastro",
                        Body = strBody.ToString()
                    })

                        enviarConf.Enviar(message);
                    //ENVIAR E-MAIL PARA: [email protected], INFORMANDO NOVO CADASTRO DE USUÁRIO
                    strBody = new StringBuilder();
                    strBody.AppendLine("NOVO USUÁRIO");
                    strBody.AppendLine("Id: " + u.Id);
                    strBody.AppendLine("Nome: " + u.Nome + " " + u.Sobrenome);
                    strBody.AppendLine("E-mail: " + u.Email);
                    strBody.AppendLine("Dt. Cadastro: " + DateTime.Now);
                    strBody.AppendLine("Telefone: " + u.Telefone);
                    strBody.AppendLine("");
                    strBody.AppendLine("Unimarket Brasil");

                    using (message = new MailMessage("*****@*****.**", "*****@*****.**")
                    {
                        Subject = "NOVO USUÁRIO",
                        Body = strBody.ToString()
                    })

                        enviarConf.Enviar(message);

                    //CADASTRAR IMAGEM PADRÃO
                    var caminho = Server.MapPath(string.Format(@"~/Imagens/{0}/Perfil/", u.Id));

                    Directory.CreateDirectory(caminho);

                    File.Copy(Server.MapPath(string.Format(@"~/Imagens/Sistema/ImagemPadrao.jpg")), caminho + "ImagemPadrao.jpg", true);

                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "$(function () { cadastroConcluido(); });", true);
                    return;
                }
                else
                {
                    dvMsg.Visible             = true;
                    dvMsg.Attributes["class"] = "alert alert-warning alert-dismissible";
                    lbMsg.Text = "Não foi possível atender sua solicitação, tente novamente mais tarde.";
                }
            }
            //SE POSSUI CADASTRO, TRATAR E INFORMAR PARA O USUÁRIO QUE JÁ ESTÁ CADASTRADO
            else if (existe != null)
            {
                if (existe.Equals("Email_CpfCnpj"))
                {
                    dvMsg.Visible             = true;
                    dvMsg.Attributes["class"] = "alert alert-info alert-dismissible";
                    lbMsg.Text = "E-mail e CNPJ/CPJ já estão cadastrados no sistema.<a class='glyphicon glyphicon-question-sign' href='/Views/SistemaAjuda.aspx?help=6' target='_blank'></a>";
                }
                else if (existe.Equals("Email"))
                {
                    dvMsg.Visible             = true;
                    dvMsg.Attributes["class"] = "alert alert-info alert-dismissible";
                    lbMsg.Text = "E-mail já está cadastrado no sistema.<a class='glyphicon glyphicon-question-sign' href='/Views/SistemaAjuda.aspx?help=7' target='_blank'></a>";
                }
                else if (existe.Equals("CpfCnpj"))
                {
                    if (u.CpfCnpj.Length == 11)
                    {
                        dvMsg.Visible             = true;
                        dvMsg.Attributes["class"] = "alert alert-info alert-dismissible";
                        lbMsg.Text = "CPF já cadastrado. <a class='glyphicon glyphicon-question-sign' href='/Views/SistemaAjuda.aspx?help=8' target='_blank'></a>";
                    }
                    else if (u.CpfCnpj.Length == 14)
                    {
                        dvMsg.Visible             = true;
                        dvMsg.Attributes["class"] = "alert alert-info alert-dismissible";
                        lbMsg.Text = "CNPJ já cadastrado. <a class='glyphicon glyphicon-question-sign' href='/Views/SistemaAjuda.aspx?help=9' target='_blank'></a>";
                    }
                }
            }
        }