Exemplo n.º 1
0
        private async void picLogin_Click(object sender, System.EventArgs e)
        {
            // INICIAR SESION

            if (canLogin)
            {
                HideBoxes();
                ShowLoadingIcon();
                await Task.Run(() => WaitLoading());

                if (personaDAO.verificarCorreo(txtEmail.Text) == -1)
                {
                    loginError   = true;
                    currentError = (int)ErrorType.InvalidEmail;
                    ClearPassword();
                    txtPassword_Leave(null, null);
                    txtEmail.Select();
                    RestartTogglePassword();
                    SetErrorBoxes();
                    HideLoadingIcon();
                    ShowBoxes();
                }
                else
                {
                    PersonaWS.persona user = personaDAO.verificarPersona(txtEmail.Text, txtPassword.Text);

                    if (user != null)
                    {
                        loginError = false;

                        if (user.tipo == 'E')
                        {
                            empleadoLogueado = empleadoDAO.buscarEmpleadoPorCodigo(user.codigo);
                            AbrirInicioEmpleado();
                        }
                        else if (user.tipo == 'A')
                        {
                            agenteLogueado = agenteDAO.buscarAgentePorCodigo(user.codigo);
                            if (agenteLogueado.rol.nombre.Contains("AGENTE"))
                            {
                                AbrirInicioAgente();
                            }
                            else if (agenteLogueado.rol.nombre.Contains("SUPERVISOR"))
                            {
                                AbrirInicioSupervisor();
                            }
                            else if (agenteLogueado.rol.nombre.Contains("ADMIN"))
                            {
                                AbrirInicioAdmin();
                            }
                        }

                        Hide();
                        if (boxesDown)
                        {
                            MoveBoxesUp();
                            HideErrorMessage();
                        }
                        ClearEmail();
                        ClearPassword();
                        txtPassword_Leave(null, null);
                        txtEmail.Select();
                        RestartTogglePassword();
                        ShowBoxes();
                    }
                    else
                    {
                        loginError   = true;
                        currentError = (int)ErrorType.InvalidPassword;
                        ClearPassword();
                        txtPassword.Select();
                        SetErrorBoxes();
                        RestartTogglePassword();
                        HideLoadingIcon();
                        ShowBoxes();
                        txtPassword.Select();
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void btnEnviarEmail_Click(object sender, EventArgs e)
        {
            // Validar email no vacio
            if (txtEmail.Text == "")
            {
                lblErrEmail.Text = "Ingresa tu email.";
            }
            else
            {
                if (lblErrEmail.Text != "")
                {
                    lblErrEmail.Text = "";
                }
                if (!Regex.IsMatch(txtEmail.Text, @"^([\w-.]+)@(pucp.(edu.)?pe)$"))
                {
                    MessageBox.Show(
                        "Debe ingresar un correo válido del dominio PUCP.",
                        "Error de email",
                        MessageBoxButtons.OK, MessageBoxIcon.Information
                        );
                    return;
                }

                int rpta = personaDAO.verificarCorreo(txtEmail.Text);

                if (rpta == -1)
                {
                    lblErrEmail.Text = "Has ingresado un email incorrecto.";
                }

                else
                {
                    // Conectar con Gmail API

                    string            codigo = RandomGenerator.GenerateRandomCode();
                    PersonaWS.persona per    = personaDAO.buscarPersonaxEmail(txtEmail.Text);

                    StreamReader streamReader = new StreamReader("../../emails/EmailRecuperarPass.html", System.Text.Encoding.UTF8);
                    string       body         = streamReader.ReadToEnd();
                    body = body.Replace("*NOMBREPH*", per.nombre);
                    body = body.Replace("*APELLIDOPH*", per.apellidoPaterno);
                    body = body.Replace("*CODIGOPH*", codigo);

                    EmailWS.YanapayEmail correo = new EmailWS.YanapayEmail();
                    correo.FromAddress  = "*****@*****.**";
                    correo.ToRecipients = txtEmail.Text;
                    correo.Subject      = "Yanapay - Recuperación de contraseña";
                    correo.Body         = body;
                    correo.IsHtml       = true;

                    if (servicioEmail.EnviarCorreo(correo) == false)
                    {
                        MessageBox.Show(
                            "Ha ocurrido un error al enviar el correo de confirmación",
                            "Correo no enviado",
                            MessageBoxButtons.OK, MessageBoxIcon.Information
                            );
                    }
                    else
                    {
                        frmRecuperarEnvioExitoso frm = new frmRecuperarEnvioExitoso(codigo, txtEmail.Text)
                        {
                            StartPosition = FormStartPosition.Manual,
                            Location      = this.Location
                        };

                        this.Hide();
                        if (frm.ShowDialog() == DialogResult.Retry)
                        {
                            LimpiarCampos();
                            this.Show();
                        }
                        else
                        {
                            LimpiarCampos();
                            this.Close();
                        }
                    }
                }
            }
        }