Exemplo n.º 1
0
        private void btEnviar_Click(object sender, EventArgs e)
        {
            #region Validação de dados
            errorProvider.SetError(textPara, string.Empty);
            errorProvider.SetError(textAssunto, string.Empty);
            errorProvider.SetError(textMensagem, string.Empty);

            int verif = 0;

            if (!Variaveis.regexEmail.IsMatch(textPara.Text))
            {
                errorProvider.SetError(textPara, "Informe um e-mail válido");
                verif++;
            }

            if (textAssunto.Text.Trim().Equals(""))
            {
                errorProvider.SetError(textAssunto, "Informe um assunto para a mensagem");
                verif++;
            }

            if (textMensagem.Text.Trim().Equals(""))
            {
                errorProvider.SetError(textMensagem, "Informe a mensagem a ser enviada");
                return;
            }

            if (verif > 0)
            {
                return;
            }
            #endregion

            if (Variaveis.enviarEmail(textPara.Text, textAssunto.Text, textMensagem.Text, listCaminhos))
            {
                textPara.Clear();
                textAssunto.Clear();
                textMensagem.Clear();
                listBoxAnexos.Items.Clear();
                listCaminhos.Clear();

                // Inserção de log de envio de e-mail
                logsDAO.insert(3);
            }
            else
            {
                MessageBox.Show("Não foi possível enviar o e-mail.", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemplo n.º 2
0
        private void btRecuperar_Click(object sender, EventArgs e)
        {
            #region Validação dos campos
            errorProvider.SetError(textEmail, string.Empty);
            errorProvider.SetError(textSenhaAntiga, string.Empty);
            errorProvider.SetError(textBoxFundo, string.Empty);
            errorProvider.SetError(textConfSenha, string.Empty);

            int verif = 0;

            if (!Variaveis.regexEmail.IsMatch(textEmail.Text))
            {
                errorProvider.SetError(textEmail, "Informe um e-mail válido");
                verif++;
            }

            if (textSenhaAntiga.Text.Trim().Equals(""))
            {
                errorProvider.SetError(textSenhaAntiga, "Informe a senha antiga da conta");
                verif++;
            }

            if (textSenhaNova.Text.Length < 5 || textSenhaNova.Text.Length > 25)
            {
                errorProvider.SetError(textBoxFundo, "Informe uma senha entre 5 e 25 caracteres");
                verif++;
            }

            if (textConfSenha.Text.Equals(""))
            {
                errorProvider.SetError(textConfSenha, "Confirme sua nova senha");
                return;
            }
            else if (!textConfSenha.Text.Equals(textSenhaNova.Text))
            {
                errorProvider.SetError(textConfSenha, "Você confirmou uma senha diferente da informada anteriormente");
                return;
            }

            if (verif > 0)
            {
                return;
            }

            Usuarios usuario = usuariosDAO.selectEmail(textEmail.Text, Variaveis.gerarHashMD5(textSenhaAntiga.Text));

            if (usuario == null)
            {
                MessageBox.Show("E-mail ou senha antiga inválido.", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else
            {
                login = usuario.Login;
            }
            #endregion

            // Validação da senha de acordo com as palavras proibidas e sequências (verificação com nome de login do usuário)
            if (validarSenha(textSenhaNova.Text) == false)
            {
                return;
            }

            Variaveis.enviarEmail(textEmail.Text, "Troca de Senha",
                                  "Foi realizada uma troca de senha na sua conta (" + DateTime.Today + ").", null);

            // Alteração da senha do usuário
            usuario.Senha = Variaveis.gerarHashMD5(textSenhaNova.Text);
            usuariosDAO.update(usuario);

            MessageBox.Show("Senha alterada com sucesso.", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }