Exemplo n.º 1
0
        public async Task <IActionResult> Login(LoginViewModel model, string returnUrl = null)
        {
            clsQuery consul = new clsQuery();

            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                if (consul._loginSession(model.Email, model.Password))
                {
                    List <Claim> claims = new List <Claim>();
                    claims.Add(new Claim(ClaimTypes.Email, model.Email));
                    claims.Add(new Claim(ClaimTypes.Name, model.Email));
                    claims.Add(new Claim(ClaimTypes.Role, "Admin"));
                    claims.Add(new Claim(ClaimsIdentity.DefaultRoleClaimType, "Admin"));
                    ClaimsPrincipal principal = new ClaimsPrincipal();
                    ClaimsIdentity  iden      = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
                    principal.AddIdentity(iden);
                    //await HttpContext.Authentication.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, new Microsoft.AspNetCore.Http.Authentication.AuthenticationProperties
                    //{
                    //    IsPersistent = true,
                    //    AllowRefresh=true
                    //});
                    byte[] SessionUSer = System.Text.Encoding.UTF8.GetBytes(model.Email);

                    ViewBag.IsAuth = true;
                    ViewBag.Role   = "Admin";
                    Sec.secjwt JWT = new Sec.secjwt();
                    string     jwt = JWT.GetToken(model);
                    Response.Cookies.Append("Bearer", jwt, new Microsoft.AspNetCore.Http.CookieOptions {
                        Path = "/", HttpOnly = true
                    });
                    Response.Cookies.Append("pandoraRules", Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(model.Email)), new Microsoft.AspNetCore.Http.CookieOptions {
                        Path = "/", HttpOnly = true
                    });
                    Response.Cookies.Append("IsAuth", Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(model.Email)), new Microsoft.AspNetCore.Http.CookieOptions {
                        Path = "/", HttpOnly = true
                    });
                    return(RedirectToAction("Index", "PSAV"));
                }
                else
                {
                    ViewBag.result = "Credenciales inválidas";
                }
            }
            else
            {
                ViewBag.result = "Error al llenar el formulario";
            }
            return(View());
        }
Exemplo n.º 2
0
        public DataSet getPrueba()
        {
            DataSet ods = null;

            try
            {
                clsQuery oquery = new clsQuery(clsConfig.getConection());
                ods = oquery.exec(String.Format(cVaciado.query_getPrueba()));
            }
            catch (Exception ex)
            {
                throw new Exception("clsVaciado" + ", getPrueba: " + ex.Message);
            }
            return(ods);
        }
Exemplo n.º 3
0
        public DataSet getVaciado()
        {
            DataSet ods = null;

            try
            {
                clsQuery oquery = new clsQuery(clsConfig.getConection());
                ods = oquery.exec(String.Format(cVaciado.query_getVaciado(), this.Operador, this.Supervisor, this.Banco));
            }
            catch (Exception ex)
            {
                throw new Exception("clsVaciado" + ", getVaciado: " + ex.Message);
            }
            return(ods);
        }
Exemplo n.º 4
0
        public DataSet getPlantaLoad(int iCodRol)
        {
            DataSet ods;

            try
            {
                clsQuery oquery = new clsQuery(clsConfig.getConection());
                ods = oquery.exec(String.Format(clsSelPlanta.query_cod_planta(), iCodRol.ToString()));
            }
            catch (Exception ex)
            {
                throw new Exception("clsSelPlanta" + ", ObtenerPlantasRol: " + ex.Message);
            }
            return(ods);
        }
Exemplo n.º 5
0
        public DataSet getBanco(String id_planta, String id_centro_trabajo)
        {
            DataSet ods;

            try
            {
                clsQuery oquery = new clsQuery(clsConfig.getConection());
                ods = oquery.exec(String.Format(clsVaciado.query_getBanco(), id_planta, id_centro_trabajo));
            }
            catch (Exception ex)
            {
                throw new Exception("clsVaciado" + ", getBanco: " + ex.Message);
            }
            return(ods);
        }
Exemplo n.º 6
0
        public DataSet getNumSupervisor(String id_operador, String id_supervisor)
        {
            DataSet ods;

            try
            {
                clsQuery oquery = new clsQuery(clsConfig.getConection());
                ods = oquery.exec(String.Format(clsVaciado.query_getNumSupervisor(), id_operador, id_supervisor));
            }
            catch (Exception ex)
            {
                throw new Exception("clsVaciado" + ", getNumSupervisor: " + ex.Message);
            }
            return(ods);
        }
Exemplo n.º 7
0
        public LoginUsuario Login(string sLogin, string sPassword)
        {
            LoginUsuario lu = new LoginUsuario();

            //
            try
            {
                clsQuery            oquery = new clsQuery(clsConfig.getConection());
                System.Data.DataSet ods    = new System.Data.DataSet();

                ods.Tables.Add(oquery.exec(String.Format(clsLogin.query_login_s(), sLogin, sPassword)).Tables[0].Copy());
                ods.Tables[0].TableName = "Tabla1";
                ods.Tables.Add(oquery.exec(String.Format(clsLogin.query_config1_s(), sLogin, sPassword)).Tables[0].Copy());
                ods.Tables[1].TableName = "Tabla2";
                ods.Tables.Add(oquery.exec(String.Format(clsLogin.query_config2_s(), sLogin, sPassword)).Tables[0].Copy());
                ods.Tables[2].TableName = "Tabla3";
                ods.Tables.Add(oquery.exec(String.Format(clsLogin.query_num_intentos_s(), sLogin, sPassword)).Tables[0].Copy());
                ods.Tables[3].TableName = "Tabla4";
                oquery.exec(String.Format(clsLogin.query_num_intentos1_upd(), sLogin, sPassword));
                oquery.exec(String.Format(clsLogin.query_num_intentos2_upd(), sLogin, sPassword));


                if (ods.Tables.Count == 0 || ods.Tables[0].Rows.Count == 0)
                {
                    lu.CodUsuario = -1;
                    lu.IsLogin    = false;
                    lu.Mensaje    = "El usuario no existe. Favor de verificar.";
                    return(lu);
                }


                lu.CodUsuario       = Convert.ToInt32(ods.Tables[0].Rows[0]["CodUsuario"]);
                lu.Login            = Convert.ToString(ods.Tables[0].Rows[0]["Login"]);
                lu.Password         = Convert.ToString(ods.Tables[0].Rows[0]["Password"]);
                lu.CodEmpleado      = Convert.ToInt32(ods.Tables[0].Rows[0]["CodEmpleado"]);
                lu.NomEmpleado      = Convert.ToString(ods.Tables[0].Rows[0]["NomEmpleado"]);
                lu.CodRol           = Convert.ToInt32(ods.Tables[0].Rows[0]["CodRol"]);
                lu.DesRol           = Convert.ToString(ods.Tables[0].Rows[0]["DesRol"]);
                lu.CodPuesto        = Convert.ToInt32(ods.Tables[0].Rows[0]["CodPuesto"]);
                lu.DesPuesto        = Convert.ToString(ods.Tables[0].Rows[0]["DesPuesto"]);
                lu.Bloqueado        = Convert.ToBoolean(ods.Tables[0].Rows[0]["Bloqueado"]);
                lu.FechaVigPassword = Convert.ToDateTime(ods.Tables[0].Rows[0]["FechaVigPassword"]);
                lu.CodSupervisor    = Convert.ToInt32(ods.Tables[0].Rows[0]["cod_supervisor"]);

                // Verificar que el usuario existe.
                if (lu.CodUsuario == -1)
                {
                    lu.IsLogin = false;
                    lu.Mensaje = "El usuario no existe. Favor de verificar.";
                    return(lu);
                }

                // Verificar si el usuario está bloqueado.
                if (lu.Bloqueado)
                {
                    lu.IsLogin = false;
                    lu.Mensaje = "Usuario bloqueado. Favor de comunicarse con el administrador del sistema.";
                    return(lu);
                }

                // Obtener los dias para expirar password.
                TimeSpan ts = lu.FechaVigPassword - DateTime.Today;
                int      iDiasVencimiento = ts.Days;

                // Verificar si la contraseña ya expiro.
                if (iDiasVencimiento <= 0)
                {
                    lu.IsLogin = false;
                    lu.Mensaje = "La contraseña ya expiró. Favor de cambiar contraseña.";
                    return(lu);
                }

                // Verificar password.
                if (lu.Password == sPassword)
                {
                    // Obtener dias aviso de vigencia de password.
                    int iDiasAvisoVigPass = Convert.ToInt32(ods.Tables[1].Rows[0]["DiasAvisoVigPass"]);

                    // Informar los días que faltan para el vencimiento del password.
                    if (iDiasVencimiento <= iDiasAvisoVigPass)
                    {
                        lu.Mensaje = "Faltan " + iDiasVencimiento.ToString() + " día(s) para vencimiento de contraseña. Favor de cambiarla.";
                    }

                    lu.IsLogin = true;
                    return(lu);
                }
                else
                {
                    // Obtener intentos configurados.
                    int iNumIntentosConfigurados = Convert.ToInt32(ods.Tables[2].Rows[0]["NumIntentosConfig"]);

                    // Obtener número de intentos que tiene el usuario.
                    int iNumIntentosUsuario = Convert.ToInt32(ods.Tables[3].Rows[0]["NumIntentosUsuario"]);

                    // Bloquear usuario y restablecer el contador de intentos.
                    if (iNumIntentosUsuario == iNumIntentosConfigurados)
                    {
                        oquery.exec(String.Format(clsLogin.query_bloquearUsuario(), sLogin));
                        lu.IsLogin = false;
                        lu.Mensaje = "Usuario bloqueado. Favor de comunicarse con el administrador del sistema.";
                        return(lu);
                    }
                    else
                    {
                        lu.IsLogin = false;
                        lu.Mensaje = "El password es incorrecto. Favor de verificar.";
                        return(lu);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("clsLogin" + ", Login: " + ex.Message);
            }
        }