예제 #1
0
        public Modelos.Response validaAcceso(string usuario, string pass)
        {
            Modelos.Response result = new Modelos.Response();
            result.status = Modelos.Estatus.OK;

            // buscar si el usuario ya existe
            bool us = this._consultasMySQLDatos.buscaUsuario(usuario.Trim().ToLower());

            if (!us)
            {
                result.status = Modelos.Estatus.ERROR;
                result.error  = "El usuario no existe";
                return(result);
            }

            Modelos.Usuarios resultado = this._consultasMySQLDatos.validaAcceso(usuario, pass);

            if (resultado == null)
            {
                result.status = Modelos.Estatus.ERROR;
                result.error  = "Contraseña incorrecta";
                return(result);
            }

            result.usuario = resultado;

            return(result);
        }
예제 #2
0
        public Modelos.Response creaUsuario(string nombreCompleto, string correo, string usuario, string clave, string fecha)
        {
            Modelos.Response result = new Modelos.Response();

            // buscar si el usuario ya existe
            bool us = this._consultasMySQLDatos.buscaUsuario(usuario.Trim().ToLower());

            if (us)
            {
                result.status = Modelos.Estatus.ERROR;
                result.error  = "El usuario ya existe";
                return(result);
            }

            // buscar si el correo existe
            bool corr = this._consultasMySQLDatos.buscaCorreo(correo.Trim().ToLower());

            if (corr)
            {
                result.status = Modelos.Estatus.ERROR;
                result.error  = "El correo ya se registro para otro usuario";
                return(result);
            }

            // inserta el usuario
            bool inserta = this._consultasMySQLDatos.insertaUsuario(nombreCompleto, correo, usuario, clave, fecha);

            result.status = Modelos.Estatus.OK;

            return(result);
        }
        private void btnAcceder_Click(object sender, EventArgs e)
        {
            try
            {
                this._consultasMySQLNegocio = new ConsultasMySQLNegocio();
                this._consultasFBNegocio    = new ConsultasFBNegocio();

                // validaciones
                if (string.IsNullOrEmpty(this.tbUsuario.Text))
                {
                    throw new Exception("Llene el campo Usuario");
                }

                if (string.IsNullOrEmpty(this.tbPass.Text))
                {
                    throw new Exception("Llene el campo Clave");
                }

                Modelos.Response resp = this._consultasMySQLNegocio.validaAcceso(this.tbUsuario.Text, this.tbPass.Text);

                if (resp.status == Modelos.Estatus.OK)
                {
                    // almacenar credeniales
                    Modelos.Login.idUsuario = resp.usuario.idUsuario;
                    Modelos.Login.nombre    = resp.usuario.nombreCompleto;
                    Modelos.Login.usuario   = resp.usuario.usuario;

                    string fecha = getFechaFireBird();

                    // bitacora
                    this._consultasMySQLNegocio.generaBitacora(
                        "Nuevo Acceso a usuario '" + Modelos.Login.nombre + "'", fecha);

                    this.Hide();
                    new FormPrincipal().ShowDialog();
                    this.Close();
                }
                else
                {
                    throw new Exception(resp.error);
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message, "Login", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
        private void btnCrear_Click(object sender, EventArgs e)
        {
            try
            {
                // validaciones
                if (string.IsNullOrEmpty(this.tbNombre.Text))
                {
                    throw new Exception("Defina un nombre");
                }

                if (string.IsNullOrEmpty(this.tbUsuario.Text))
                {
                    throw new Exception("Defina un Usuario");
                }

                if (string.IsNullOrEmpty(this.tbClave.Text))
                {
                    throw new Exception("Defina una clave para la cuenta");
                }

                if (string.IsNullOrEmpty(this.tbCorreo.Text))
                {
                    throw new Exception("Defina un Correo para el usuario");
                }

                if (!this.tbConfirmClave.Text.Equals(this.tbClave.Text))
                {
                    throw new Exception("La claves no coinciden");
                }

                string nombreCompleto = this.tbNombre.Text;
                string correo         = this.tbCorreo.Text;
                string usuario        = this.tbUsuario.Text;
                string clave          = this.tbClave.Text;

                string fecha = getFechaFireBird();

                // guarda el usuario
                Modelos.Response resp = this._consultasMySQLNegocio.creaUsuario(nombreCompleto, correo, usuario, clave, fecha);

                if (resp.status == Modelos.Estatus.OK)
                {
                    // bitacora
                    this._consultasMySQLNegocio.generaBitacora(
                        "Usuario creado '" + usuario + "'", fecha);

                    MessageBox.Show("El usuario ha sido creado correctamente", "Usuarios", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.tbNombre.Text = string.Empty;

                    this.tbCorreo.Text       = string.Empty;
                    this.tbUsuario.Text      = string.Empty;
                    this.tbClave.Text        = string.Empty;
                    this.tbConfirmClave.Text = string.Empty;
                }
                else
                {
                    throw new Exception(resp.error);
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message, "Usuarios", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }