Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //1- Check if user already authenticated

            //2- IF user auth. then show all contents
            //else look for query string user/passhash params
            // if they exist - attempt to auth.
            //  if auth. success show all contents
            //else show error message and quit
            // else show error message and quit

            int exceptionErrorCode = 0;
            int autotrigger        = 0;

            try
            {
                truckReservationEmail = ConfigurationManager.AppSettings["SmtpUser"];

                ZXPUserData zxpUD       = ZXPUserData.GetZXPUserDataFromCookie();
                string      sql_connStr = new TruckScheduleConfigurationKeysHelper().sql_connStr;
                if (zxpUD._uid != new ZXPUserData()._uid)
                {
                    sql_connStr = new TruckScheduleConfigurationKeysHelper().sql_connStr;
                    if (sql_connStr == String.Empty)
                    {
                        throw new Exception("Missing SQLConnectionString in web.config");
                    }
                    if (truckReservationEmail == String.Empty)
                    {
                        throw new Exception("Missing SmtpUser in web.config");
                    }
                }
                else
                {
                    Response.BufferOutput = true;
                    bool   isValidLoginURL = false;
                    string userName        = Request.QueryString["UN"];
                    string password        = Request.QueryString["PS"];
                    string strAuto         = Request.QueryString["AUTOTRIGGER"]; //check if this should trigger all
                    autotrigger = Convert.ToInt32(strAuto);
                    if ((userName == null || userName == String.Empty) || (password == null || password == String.Empty))
                    {
                        exceptionErrorCode = 6;//error code for unable to validate login
                        throw new Exception("Unable to validate user: no login provided.");
                    }
                    else
                    {
                        isValidLoginURL = loginForAlertProcessing(userName, password);
                    }

                    if (isValidLoginURL == true)
                    {
                        string strUserData = zxpUD.SerializeZXPUserData(zxpUD);
                        System.Web.Security.FormsAuthenticationTicket ticket = new System.Web.Security.FormsAuthenticationTicket(1, userName, DateTime.Now, DateTime.Now.AddDays(5), true, strUserData);
                        string enticket = System.Web.Security.FormsAuthentication.Encrypt(ticket);
                        System.Web.HttpCookie authcookie = new System.Web.HttpCookie(System.Web.Security.FormsAuthentication.FormsCookieName, enticket);
                        if (ticket.IsPersistent)
                        {
                            authcookie.Expires = ticket.Expiration;
                        }
                        Response.Cookies.Add(authcookie);
                    }
                    else
                    {
                        exceptionErrorCode = 6;//error code for unable to validate login
                        throw new Exception("Unable to validate user.");
                    }
                }
                if (1 == autotrigger)
                {
                    sendAllAlertsAutomatically();
                }

                showContents();
            }
            catch (SqlException excep)
            {
                string strErr = " SQLException Error in alertsProcessing Page_Load(). Details: " + excep.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
                System.Web.HttpContext.Current.Session["ErrorNum"] = 2;
                ErrorLogging.sendtoErrorPage(2);
            }
            catch (Exception ex)
            {
                string strErr = " Exception Error in alertsProcessing Page_Load(). Details: " + ex.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);

                if (exceptionErrorCode > 0)
                {
                    System.Web.HttpContext.Current.Session["ErrorNum"] = exceptionErrorCode;
                    ErrorLogging.sendtoErrorPage(exceptionErrorCode);
                }
                else
                {
                    System.Web.HttpContext.Current.Session["ErrorNum"] = 1;
                    ErrorLogging.sendtoErrorPage(1);
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //1- Check if user already authenticated

            //2- IF user auth. then show all contents
            //else look for query string user/passhash params
            // if they exist - attempt to auth.
            //  if auth. success show all contents
            //else show error message and quit
            // else show error message and quit

            int exceptionErrorCode = 0;

            try
            {
                string sql_connStr = new TruckScheduleConfigurationKeysHelper().sql_connStr;
                sql_connStr = new TruckScheduleConfigurationKeysHelper().sql_connStr;
                if (sql_connStr == String.Empty)
                {
                    throw new Exception("Missing SQLConnectionString in web.config");
                }
                as400_connStr = ConfigurationManager.ConnectionStrings["AS400ConnectionString"].ConnectionString;
                //as400_connStr = ConfigurationManager.AppSettings["AS400ConnectionString"];

                if (string.IsNullOrEmpty(as400_connStr))
                {
                    throw new Exception("Missing AS400ConnectionString in web.config");
                }

                HttpCookie cookie = Request.Cookies[System.Web.Security.FormsAuthentication.FormsCookieName];
                if (null != cookie && !string.IsNullOrEmpty(cookie.Value))
                {
                    System.Web.Security.FormsAuthenticationTicket ticket = System.Web.Security.FormsAuthentication.Decrypt(cookie.Value);
                    zxpUD = ZXPUserData.DeserializeZXPUserData(ticket.UserData);
                }
                else
                {
                    Response.BufferOutput = true;
                    bool   isValidUser = false;
                    string userName    = Request.QueryString["UN"];
                    string password    = Request.QueryString["PS"];

                    if ((userName == null || userName == String.Empty) || (password == null || password == String.Empty))
                    {
                        exceptionErrorCode = 6;//error code for unable to validate login
                        throw new Exception("Unable to validate user: no login provided.");
                    }
                    else
                    {
                        isValidUser = isUserCredentialsValid(userName, password);
                    }

                    if (isValidUser == true)
                    {
                        string strUserData = zxpUD.SerializeZXPUserData(zxpUD);
                        System.Web.Security.FormsAuthenticationTicket ticket = new System.Web.Security.FormsAuthenticationTicket(1, userName, DateTime.Now, DateTime.Now.AddDays(5), true, strUserData);
                        string enticket = System.Web.Security.FormsAuthentication.Encrypt(ticket);
                        System.Web.HttpCookie authcookie = new System.Web.HttpCookie(System.Web.Security.FormsAuthentication.FormsCookieName, enticket);
                        if (ticket.IsPersistent)
                        {
                            authcookie.Expires = ticket.Expiration;
                        }
                        Response.Cookies.Add(authcookie);

                        callAllCleanUpFunctions();
                        callAllUpdateFunctions();
                    }
                    else
                    {
                        exceptionErrorCode = 6;//error code for unable to validate login
                        throw new Exception("User is not valid or does not have permission.");
                    }
                }
            }
            catch (SqlException excep)
            {
                string strErr = " SQLException Error in dataProcessingAndCleanup Page_Load(). Details: " + excep.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
                System.Web.HttpContext.Current.Session["ErrorNum"] = 2;
                ErrorLogging.sendtoErrorPage(2);
            }
            catch (Exception ex)
            {
                string strErr = " Exception Error in dataProcessingAndCleanup Page_Load(). Details: " + ex.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
                if (exceptionErrorCode > 0)
                {
                    System.Web.HttpContext.Current.Session["ErrorNum"] = exceptionErrorCode;
                    ErrorLogging.sendtoErrorPage(exceptionErrorCode);
                }
                else
                {
                    System.Web.HttpContext.Current.Session["ErrorNum"] = 1;
                    ErrorLogging.sendtoErrorPage(1);
                }
            }
        }