예제 #1
0
        private bool SignIn(string userName, string password, bool persistCookie = false)
        {
            FormsAuthentication.SignOut();
            bool success = false;
            Logear acceso = new Logear();

            var userNameOld = (userName.ToLower() == "test" ? "0" : userName);
            var passwordOld = (password == "Test2015k" ? "0" : password);

            var user = acceso.LoginAgenteWeb(int.Parse(userNameOld), passwordOld);

            if (user != null)
            {
                string rol = "";
                string name = user.Tables["catAgentes"].Rows[0]["cNombre"].ToString();
                if (user.Tables["catAgentes"].Rows[0]["nAgenteID"].ToString() == "0")
                {
                    rol = "A";
                    name = (userName.ToLower() == "test" ? "Usuario Test" : "Nancy Martinez");
                }

                VarProcAMC ProcAMC = new VarProcAMC();
                if (!ProcAMC.IniciarCarga())
                {
                    Session["UserObj"] = null;
                    ModelState.AddModelError("", "Error en inicio de la carga de variables");
                }
                else
                {
                    VarProcCentral proCentral = new VarProcCentral();
                    proCentral.IniciaDatos(VarProcAMC.strPeriodo);
                    AccesoSistema accesos = new AccesoSistema();
                    accesos.P_AccesosSistema("03", "E");

                    Session["UserObj"] = user;
                    Session["Periodo"] = "Periodo: " + VarProcAMC.strPeriodo;
                    Session["UserRol"] = rol;
                    if (password.Equals("agente" + userName))
                    {
                        Session["ChangePassword"] = 1;
                    }
                    else {
                        Session["ChangePassword"] = 0;
                    }

                    FormsAuthentication.SetAuthCookie(name, false);
                    success = true;
                }
            }

            return success;
        }