Exemplo n.º 1
0
        public HttpResponseMessage Grabar(clsModelDGuardados pdatos)
        {
            HttpResponseMessage respuesta = new HttpResponseMessage();

            // ===============================================================================
            //                      Para leer el TokenKey
            // ===============================================================================
            // https://www.guidgenerator.com/online-guid-generator.aspx

            clsTokenKey TokenKeyUtil = new clsTokenKey();
            var         headers      = Request.Headers;

            string TokenKey = "";

            if (headers.Contains("TokenKey"))
            {
                TokenKey = headers.GetValues("TokenKey").First();
            }
            if (TokenKey.Length == 0)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Token Key Missing"));
            }

            if (!TokenKeyUtil.fnGetTokenKeyValido(TokenKey))
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Token Key Invalid or Inactive"));
            }
            // ===============================================================================
            try
            {
                clsModelEstatus msg = new clsModelEstatus();

                Boolean lResult = fnSet(pdatos);
                if (lResult)
                {
                    msg.Id      = 0;
                    msg.Mensaje = "Datos Actualizados";
                    respuesta   = Request.CreateResponse(HttpStatusCode.OK, msg);
                }
                else
                {
                    msg.Id      = -1;
                    msg.Mensaje = "No fue posible actualizar los datos ingresados favor reintentar";
                    respuesta   = Request.CreateResponse(HttpStatusCode.Conflict, msg);
                }

                //clsModelEstatus Estado = new clsModelEstatus();

                //Estado.Id = 0;
                //Estado.Mensaje = "Datos Actualizados";

                //respuesta = Request.CreateResponse(HttpStatusCode.OK,Estado);
            }
            catch (Exception ex)
            {
                respuesta = Request.CreateErrorResponse(HttpStatusCode.Conflict, ex.Message.ToString() + ' ' + ex.InnerException.Message.ToString());
            }

            return(respuesta);
        }
Exemplo n.º 2
0
        public HttpResponseMessage GetAll(List <clsModelInventarioDsbCns> param)
        {
            HttpResponseMessage respuesta = new HttpResponseMessage();

            // ===============================================================================
            //                      Para leer el TokenKey
            // ===============================================================================
            // https://www.guidgenerator.com/online-guid-generator.aspx

            clsTokenKey TokenKeyUtil = new clsTokenKey();
            var         headers      = Request.Headers;

            string TokenKey = "";

            if (headers.Contains("TokenKey"))
            {
                TokenKey = headers.GetValues("TokenKey").First();
            }
            if (TokenKey.Length == 0)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Token Key Missing"));
            }

            if (!TokenKeyUtil.fnGetTokenKeyValido(TokenKey))
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Token Key Invalid or Inactive"));
            }
            // ===============================================================================

            try
            {
                switch (param[0].Opccion)
                {
                case 0:
                    List <clsModelInventarioDsb> lnivel0 = fnGetAllNivel0(param[0].IdPadre);
                    respuesta = Request.CreateResponse(HttpStatusCode.OK, lnivel0);
                    break;

                default:

                    string[] valores = param[0].StrPadre.Split('_');

                    List <clsModelInventarioDsbDetalle> lnivel1 = fnGetAllNivel1(param[0].Opccion, Convert.ToInt64(valores[0]), Convert.ToInt64(valores[1]), Convert.ToInt64(valores[2]));
                    respuesta = Request.CreateResponse(HttpStatusCode.OK, lnivel1);
                    break;
                }
            }
            catch (Exception ex)
            {
                respuesta = Request.CreateErrorResponse(HttpStatusCode.Conflict, ex.Message.ToString() + ' ' + ex.InnerException.Message.ToString());
            }

            return(respuesta);
        }
Exemplo n.º 3
0
        public HttpResponseMessage Actualizar(List <clsModelInventarioSemillas> pdatos)
        {
            HttpResponseMessage respuesta = new HttpResponseMessage();

            // ===============================================================================
            //                      Para leer el TokenKey
            // ===============================================================================
            // https://www.guidgenerator.com/online-guid-generator.aspx

            clsTokenKey TokenKeyUtil = new clsTokenKey();
            var         headers      = Request.Headers;

            string TokenKey = "";

            if (headers.Contains("TokenKey"))
            {
                TokenKey = headers.GetValues("TokenKey").First();
            }
            if (TokenKey.Length == 0)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Token Key Missing"));
            }

            if (!TokenKeyUtil.fnGetTokenKeyValido(TokenKey))
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Token Key Invalid or Inactive"));
            }
            // ===============================================================================


            try
            {
                Boolean lResult = fnUpdInventario(pdatos);
                if (lResult)
                {
                    respuesta = Request.CreateResponse(HttpStatusCode.OK, lResult);
                }
                else
                {
                    respuesta = Request.CreateResponse(HttpStatusCode.Conflict, "No fue posible grabar los datos ingresados favor reintentar");
                }
            }
            catch (Exception ex)
            {
                respuesta = Request.CreateErrorResponse(HttpStatusCode.Conflict, ex.Message.ToString() + ' ' + ex.InnerException.Message.ToString());
            }

            return(respuesta);
        }
Exemplo n.º 4
0
        public HttpResponseMessage GetAll(List <clsModelDGuardadosOpc> param)
        {
            HttpResponseMessage respuesta = new HttpResponseMessage();

            // ===============================================================================
            //                      Para leer el TokenKey
            // ===============================================================================
            // https://www.guidgenerator.com/online-guid-generator.aspx

            clsTokenKey TokenKeyUtil = new clsTokenKey();
            var         headers      = Request.Headers;

            string TokenKey = "";

            if (headers.Contains("TokenKey"))
            {
                TokenKey = headers.GetValues("TokenKey").First();
            }
            if (TokenKey.Length == 0)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Token Key Missing"));
            }

            if (!TokenKeyUtil.fnGetTokenKeyValido(TokenKey))
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Token Key Invalid or Inactive"));
            }
            // ===============================================================================

            try
            {
                clsModelEstatus           msg     = new clsModelEstatus();
                List <clsModelDGuardados> lResult = fnGetAll(param[0]);

                respuesta = Request.CreateResponse(HttpStatusCode.OK, lResult);
            }
            catch (Exception ex)
            {
                clsModelEstatus msg = new clsModelEstatus();
                msg.Id      = -1;
                msg.Mensaje = ex.Message.ToString() + ' ' + ex.InnerException.Message.ToString();

                respuesta = Request.CreateResponse(HttpStatusCode.Conflict, msg);
            }

            return(respuesta);
        }
Exemplo n.º 5
0
        public HttpResponseMessage SetAutorizar(List <clsModelAutorizaciones> pdatos)
        {
            HttpResponseMessage respuesta = new HttpResponseMessage();

            // ===============================================================================
            //                      Para leer el TokenKey
            // ===============================================================================
            // https://www.guidgenerator.com/online-guid-generator.aspx

            clsTokenKey TokenKeyUtil = new clsTokenKey();
            var         headers      = Request.Headers;

            string TokenKey = "";

            if (headers.Contains("TokenKey"))
            {
                TokenKey = headers.GetValues("TokenKey").First();
            }
            if (TokenKey.Length == 0)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Token Key Missing"));
            }

            if (!TokenKeyUtil.fnGetTokenKeyValido(TokenKey))
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Token Key Invalid or Inactive"));
            }
            // ===============================================================================


            try
            {
                Int64  Id     = pdatos[0].Id;
                Int16  Estado = pdatos[0].Estado;
                string Notas  = pdatos[0].Notas;

                Boolean lResult = fnSetAutorizacion(Id, Estado, Notas);
                respuesta = Request.CreateResponse(HttpStatusCode.OK, lResult);
            }
            catch (Exception ex)
            {
                respuesta = Request.CreateErrorResponse(HttpStatusCode.Conflict, ex.Message.ToString() + ' ' + ex.InnerException.Message.ToString());
            }

            return(respuesta);
        }
Exemplo n.º 6
0
        public HttpResponseMessage GetPorAutorizar(string Usuario)
        {
            HttpResponseMessage respuesta = new HttpResponseMessage();

            // ===============================================================================
            //                      Para leer el TokenKey
            // ===============================================================================
            // https://www.guidgenerator.com/online-guid-generator.aspx

            clsTokenKey TokenKeyUtil = new clsTokenKey();
            var         headers      = Request.Headers;

            string TokenKey = "";

            if (headers.Contains("TokenKey"))
            {
                TokenKey = headers.GetValues("TokenKey").First();
            }
            if (TokenKey.Length == 0)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Token Key Missing"));
            }

            if (!TokenKeyUtil.fnGetTokenKeyValido(TokenKey))
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Token Key Invalid or Inactive"));
            }
            // ===============================================================================



            try
            {
                List <clsModelAutorizaciones> lResult = fnGetDatosAutorizaciones(1, Usuario);
                respuesta = Request.CreateResponse(HttpStatusCode.OK, lResult);
            }
            catch (Exception ex)
            {
                respuesta = Request.CreateErrorResponse(HttpStatusCode.Conflict, ex.Message.ToString() + ' ' + ex.InnerException.Message.ToString());
            }

            return(respuesta);
        }
Exemplo n.º 7
0
        public HttpResponseMessage Ingreso(List <clsModelLogin> pdatos)
        {
            HttpResponseMessage respuesta = new HttpResponseMessage();

            try
            {
                // ===============================================================================
                //                      Para leer el TokenKey
                // ===============================================================================
                // https://www.guidgenerator.com/online-guid-generator.aspx

                clsTokenKey TokenKeyUtil = new clsTokenKey();
                var         headers      = Request.Headers;

                string TokenKey = "";
                if (headers.Contains("TokenKey"))
                {
                    TokenKey = headers.GetValues("TokenKey").First();
                }
                if (TokenKey.Length == 0)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Token Key Missing"));
                }

                if (!TokenKeyUtil.fnGetTokenKeyValido(TokenKey))
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Token Key Invalid or Inactive"));
                }
                // ===============================================================================

                string Usuario  = pdatos[0].Usuario;
                string ClaveEnc = pdatos[0].EncPass;
                string Clave    = "";

                List <clsModelLogin> lResult = fnGetUsuarioParaValidar(Usuario);

                //Con los datos de usuario se valida clave
                //using System.Configuration;
                string EncKeyBase = "";
                EncKeyBase = ConfigurationManager.AppSettings["enc_key_base"].ToString();
                clsEncryption enc = new clsEncryption(EncKeyBase);
                Clave = enc.fnGetDecrypt(ClaveEnc);

                if (ClaveEnc == "")
                {
                    respuesta = Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Clave en blanco no ingresada");
                }
                else
                {
                    if (Clave == "")
                    {
                        respuesta = Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Clave con encripcion incorrecta");
                    }
                    else
                    {
                        if (lResult.Count == 0)
                        {
                            //usuario no existe
                            respuesta = Request.CreateResponse(HttpStatusCode.Unauthorized, "Usuario No Existe");
                        }
                        else
                        {
                            // Se valida que la clave sea la correcta
                            if (Clave == lResult[0].EncPass)
                            {
                                if (lResult[0].Estado == "AC")
                                {
                                    //en esta variabe se recibe el password desde la base de datos sin encripcion
                                    //se devuelve al cliente encriptada
                                    lResult[0].EncPass = enc.fnGetEncrypt(lResult[0].EncPass);
                                    //calcula token por usuario
                                    lResult[0].Token = enc.fnGetTokenByUser(lResult[0].Usuario);
                                    respuesta        = Request.CreateResponse(HttpStatusCode.OK, lResult);
                                }
                                else
                                {
                                    respuesta = Request.CreateResponse(HttpStatusCode.Unauthorized, "Usuario Bloqueado");
                                }
                            }
                            else
                            {
                                respuesta = Request.CreateResponse(HttpStatusCode.Unauthorized, "Clave incorrecta");
                            }
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                respuesta = Request.CreateErrorResponse(HttpStatusCode.Conflict, ex.Message.ToString() + ' ' + ex.InnerException.Message.ToString());
            }

            return(respuesta);
        }
Exemplo n.º 8
0
        public HttpResponseMessage ValidaAccesoWeb(List <clsModelLoginValidaWeb> pdatos)
        {
            HttpResponseMessage respuesta = new HttpResponseMessage();

            // ===============================================================================
            //                      Para leer el TokenKey
            // ===============================================================================
            // https://www.guidgenerator.com/online-guid-generator.aspx

            clsTokenKey TokenKeyUtil = new clsTokenKey();
            var         headers      = Request.Headers;

            string TokenKey = "";

            if (headers.Contains("TokenKey"))
            {
                TokenKey = headers.GetValues("TokenKey").First();
            }
            if (TokenKey.Length == 0)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Token Key Missing"));
            }

            if (!TokenKeyUtil.fnGetTokenKeyValido(TokenKey))
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Token Key Invalid or Inactive"));
            }
            // ===============================================================================



            List <clsModelLoginMensaje> lResult = new List <clsModelLoginMensaje>();

            try
            {
                string Usuario = pdatos[0].Usuario;
                string Token   = pdatos[0].Token;
                string Opcion  = pdatos[0].Opcion;

                string[] arrOpc = Opcion.Split('|');

                // Desencripta el token y valida que la primera parte
                // sea el usuario, la segunda la llave que esta en
                // el web config del api
                // con el usuario lo compara con el usuario que se recibe
                // opcion trae en un split el nombre del controlador y la accion para
                // buscarlo en la tabla de seguridad

                string EncKeyBase   = "";
                string CodigoModulo = "";
                EncKeyBase   = ConfigurationManager.AppSettings["enc_key_base"].ToString();
                CodigoModulo = ConfigurationManager.AppSettings["Codigo_Modulo"].ToString();
                clsEncryption enc = new clsEncryption(EncKeyBase);

                Token = enc.fnGetDecrypt(Token);
                string[] arr = Token.Split('|');

                if (arr.Length != 3)
                {
                    // longitud de token inválida
                    respuesta = Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Token Inválido L!=3");
                }
                else
                {
                    if (Usuario != arr[0])
                    {
                        // la primera parte del token no es igual al usuario
                        respuesta = Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Token Inválido L0!=USR");
                    }
                    else
                    {
                        if (EncKeyBase != arr[1])
                        {
                            // la segunda parte del token no es la llave
                            respuesta = Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Token Inválido L1!=KEY");
                        }
                        else
                        {
                            // valida acceso a la opcion
                            if (fnGetUsuarioConAcceso(Usuario, CodigoModulo, arrOpc[0], arrOpc[1]))
                            {
                                clsModelLoginMensaje Mensaje = new clsModelLoginMensaje();
                                Mensaje.Mensaje = "Token Válido";
                                lResult.Add(Mensaje);
                                respuesta = Request.CreateResponse(HttpStatusCode.OK, lResult);
                            }
                            else
                            {
                                respuesta = Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Token Inválido L3!=OPC");
                            }
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                respuesta = Request.CreateErrorResponse(HttpStatusCode.Conflict, ex.Message.ToString() + ' ' + ex.InnerException.Message.ToString());
            }

            return(respuesta);
        }