Example #1
0
        /// <summary>
        /// Compare object with another
        /// </summary>
        /// <param name="other">Object to compare</param>
        /// <returns>Indicates if objects are equals</returns>
        public bool Equals(LogOnObject other)
        {
            if (other == null)
            {
                return(false);
            }

            if (this.Result != other.Result)
            {
                return(false);
            }

            return(this.Result == other.Result);
        }
        private static void TraceLogin(LogOnObject result, string email, string clientAddress)
        {
            /* CREATE PROCEDURE AspadLand_Trace_Insert
             *   @CentroId uniqueidentifier,
             *   @Type int,
             *   @Busqueda nvarchar(50),
             *   @ColectivoId uniqueidentifier,
             *   @PresupuestoId uniqueidentifier */
            using (var cmdT = new SqlCommand("AspadLand_Trace_Insert"))
            {
                using (var cnnT = new SqlConnection(ConfigurationManager.ConnectionStrings["cns"].ConnectionString))
                {
                    cmdT.Connection  = cnnT;
                    cmdT.CommandType = CommandType.StoredProcedure;
                    cmdT.Parameters.Add(DataParameter.Input("@CentroId", result.Id));
                    cmdT.Parameters.Add(DataParameter.Input("@Type", result.Id == string.Empty ? 8 : 7));
                    cmdT.Parameters.Add(DataParameter.Input("@Busqueda", email));
                    cmdT.Parameters.Add(DataParameter.InputNull("@ColectivoId"));
                    cmdT.Parameters.Add(DataParameter.InputNull("@PresupuestoId"));
                    try
                    {
                        cmdT.Connection.Open();
                        cmdT.ExecuteNonQuery();
                    }
                    finally
                    {
                        if (cmdT.Connection.State != ConnectionState.Closed)
                        {
                            cmdT.Connection.Close();
                        }
                    }
                }
            }

            if (string.IsNullOrEmpty(clientAddress))
            {
                clientAddress = "no-ip";
            }
        }
        /// <summary>Log on application</summary>
        /// <param name="email">User email</param>
        /// <param name="password">User password</param>
        /// <param name="clientAddress">IP address from log on action</param>
        /// <returns>Result of action</returns>
        public static ActionResult ApplicationAccess(string email, string password, string clientAddress)
        {
            if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
            {
                return(ActionResult.NoAction);
            }

            var res    = ActionResult.NoAction;
            var result = new LogOnObject
            {
                Id                = string.Empty,
                UserName          = string.Empty,
                Result            = LogOnResult.NoUser,
                MustResetPassword = false
            };

            var binding = HttpContext.Current.Session["SForceConnection"] as SforceService;
            var query   = string.Format(
                CultureInfo.InvariantCulture,
                @"SELECT Id, name,nIF__c,usuario_ASPADLand__c,Password_ASPADLand__c FROM Account WHERE usuario_ASPADLand__c = '{0}'",
                email);

            var bindingResult = binding.query(query);
            var login         = false;

            if (bindingResult != null)
            {
                foreach (var r in bindingResult.records)
                {
                    Account ac = r as Account;
                    if (ac.Password_ASPADLand__c.Equals(password))
                    {
                        var actosCentro = Acto.ByCentro(ac.Usuario_ASPADLand__c);
                        var actos       = Acto.All;

                        foreach (var acto in actos)
                        {
                            foreach (var actoCentro in actosCentro)
                            {
                                if (actosCentro.Any(a => a.Id.Equals(acto.Id, StringComparison.OrdinalIgnoreCase)))
                                {
                                    acto.Ofertado = true;
                                    break;
                                }
                            }
                        }

                        login           = true;
                        result.Result   = LogOnResult.Ok;
                        result.Id       = ac.Id;
                        result.UserName = ac.Name;
                        HttpContext.Current.Session["User"]            = ApplicationUser.GetById(ac.Id);
                        HttpContext.Current.Session["Actos"]           = actosCentro;
                        HttpContext.Current.Session["Colectivos"]      = Colectivo.All;
                        HttpContext.Current.Session["ColectivosASPAD"] = Colectivo.AllASPAD;
                        break;
                    }
                }
            }

            if (!login)
            {
                result.Result = LogOnResult.Fail;
                // weke: LogOnFailed(result.Id);
            }

            // weke: TraceLogin(result, email, clientAddress);
            res.SetSuccess(result);
            return(res);
        }