/// <summary>
        /// Event handler for BeginRequest.
        /// </summary>
        /// <param name="sender">Sender object instance.</param>
        /// <param name="e">Event arguments.</param>
        void Context_BeginRequest(object sender, EventArgs e)
        {
            if (InstallerHelper.ConnectionStringIsSet())
            {
                try
                {
                    if (HttpContext.Current != null && !HttpContext.Current.Request.Url.IsLoopback)
                    {
                        HttpApplication application = sender as HttpApplication;
                        BannedIpAddress clientIP    = new BannedIpAddress();
                        clientIP.Address = application.Request.UserHostAddress;
                        // On any unexpected error we let visitor to visit website
                        if (IpBlacklistManager.IsIpAddressBanned(clientIP))
                        {
                            // Blocking process

                            // for now just show error 404 - Forbidden
                            // later let the user know that his ip address/network
                            // was banned and a reason why... this means we need an error page (aspx)
                            application.Response.StatusCode = 403;
                            application.Server.Transfer("~/BannedAddress.htm");
                            application.Response.StatusDescription = "Access is denied";
                            application.Response.End();
                        }
                    }
                }
                catch (Exception exc)
                {
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handlers the BeginRequest event of the application
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The instance containing the event data.</param>
        private void Application_BeginRequest(object sender, EventArgs e)
        {
            if (InstallerHelper.ConnectionStringIsSet())
            {
                //exit if a request for a .net mapping that isn't a content page is made i.e. axd
                if (!CommonHelper.IsContentPageRequested())
                {
                    return;
                }

                //set current culture
                var currentLanguage = NopContext.Current.WorkingLanguage;
                if (currentLanguage != null)
                {
                    NopContext.Current.SetCulture(new CultureInfo(currentLanguage.LanguageCulture));
                }

                //session workflow
                if (NopContext.Current.Session != null)
                {
                    var dtNow = DateTime.UtcNow;
                    if (NopContext.Current.Session.LastAccessed.AddMinutes(1.0) < dtNow)
                    {
                        NopContext.Current.Session.LastAccessed = dtNow;
                        NopContext.Current.Session = CustomerManager.SaveCustomerSession(
                            NopContext.Current.Session.CustomerSessionGuid,
                            NopContext.Current.Session.CustomerId,
                            NopContext.Current.Session.LastAccessed,
                            false);
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Handlers the EndRequest event of the application
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The instance containing the event data.</param>
        private void Application_EndRequest(object sender, EventArgs e)
        {
            if (InstallerHelper.ConnectionStringIsSet())
            {
                try
                {
                    //exit if a request for a .net mapping that isn't a content page is made i.e. axd
                    if (!CommonHelper.IsContentPageRequested())
                    {
                        return;
                    }

                    //session workflow
                    bool sessionReseted = false;
                    if (NopContext.Current["Nop.SessionReseted"] != null)
                    {
                        sessionReseted = Convert.ToBoolean(NopContext.Current["Nop.SessionReseted"]);
                    }
                    if (!sessionReseted)
                    {
                        NopContext.Current.SessionSaveToClient();
                    }

                    //online user tracking
                    OnlineUserManager.TrackCurrentUser();
                }
                catch (Exception exc)
                {
                    //LogManager.InsertLog(LogTypeEnum.Unknown, exc.Message, exc);
                    Debug.WriteLine(exc.Message);
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Handlers the BeginRequest event of the application
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The instance containing the event data.</param>
        private void Application_BeginRequest(object sender, EventArgs e)
        {
            if (InstallerHelper.ConnectionStringIsSet())
            {
                if (NopContext.Current.Session != null)
                {
                    var dtNow = DateTime.UtcNow;
                    if (NopContext.Current.Session.LastAccessed.AddMinutes(1.0) < dtNow)
                    {
                        NopContext.Current.Session.LastAccessed = dtNow;
                        NopContext.Current.Session = CustomerManager.SaveCustomerSession(
                            NopContext.Current.Session.CustomerSessionGuid,
                            NopContext.Current.Session.CustomerId,
                            NopContext.Current.Session.LastAccessed,
                            false);
                    }
                }

                var currentLanguage = NopContext.Current.WorkingLanguage;
                if (currentLanguage != null)
                {
                    NopContext.Current.SetCulture(new CultureInfo(currentLanguage.LanguageCulture));
                }
            }
        }
        /// <summary>
        /// Handlers the BeginRequest event of the application
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The instance containing the event data.</param>
        private void Application_BeginRequest(object sender, EventArgs e)
        {
            if (!InstallerHelper.ConnectionStringIsSet())
            {
                return;
            }
            //exit if a request for a .net mapping that isn't a content page is made i.e. axd
            if (!CommonHelper.IsContentPageRequested())
            {
                return;
            }

            //update session last access time
            if (NopContext.Current.Session != null)
            {
                var dtNow = DateTime.UtcNow;
                if (NopContext.Current.Session.LastAccessed.AddMinutes(1.0) < dtNow)
                {
                    NopContext.Current.Session.LastAccessed = dtNow;
                    NopContext.Current.Session = IoC.Resolve <ICustomerService>().SaveCustomerSession(
                        NopContext.Current.Session.CustomerSessionGuid,
                        NopContext.Current.Session.CustomerId,
                        NopContext.Current.Session.LastAccessed,
                        false);
                }
            }
        }
Exemplo n.º 6
0
 void Application_End(object sender, EventArgs e)
 {
     //  Code that runs on application shutdown
     if (InstallerHelper.ConnectionStringIsSet())
     {
         TaskManager.Instance.Stop();
     }
 }
Exemplo n.º 7
0
 void Application_BeginRequest(object sender, EventArgs e)
 {
     TCwebConfig.Init();
     if (!InstallerHelper.ConnectionStringIsSet())
     {
         // InstallerHelper.RedirectToInstallationPage();
     }
 }
Exemplo n.º 8
0
 void Application_Start(object sender, EventArgs e)
 {
     // Code that runs on application startup
     NopConfig.Init();
     if (InstallerHelper.ConnectionStringIsSet())
     {
         TaskManager.Instance.Initialize(NopConfig.ScheduleTasks);
         TaskManager.Instance.Start();
     }
 }
Exemplo n.º 9
0
 void Application_End(object sender, EventArgs e)
 {
     //  在应用程序关闭时运行的代码
     //  在应用程序关闭时运行的代码
     IoC.Dispose();
     if (InstallerHelper.ConnectionStringIsSet())
     {
         TaskManager.Instance.Stop();
     }
 }
 /// <summary>
 /// Handlers the PostAcquireRequestState event of the application
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The instance containing the event data.</param>
 protected void Application_PostAcquireRequestState(object sender, EventArgs e)
 {
     if (InstallerHelper.ConnectionStringIsSet())
     {
         //if (NopContext.Current.Session != null)
         //{
         //    Customer customer = NopContext.Current.Session.Customer;
         //    if (customer != null)
         //        NopContext.Current.User = customer;
         //}
     }
 }
Exemplo n.º 11
0
        void Application_Start(object sender, EventArgs e)
        {
            // 在应用程序启动时运行的代码

            TCwebConfig.Init();
            if (InstallerHelper.ConnectionStringIsSet())
            {
                IoC.InitializeWith();

                //initialize task manager
                //  TaskManager.Instance.Initialize(TCwebConfig.ScheduleTasks);
                //  TaskManager.Instance.Start();
            }
        }
Exemplo n.º 12
0
    void Application_BeginRequest(object sender, EventArgs e)
    {
        NopConfig.Init();
        if (!InstallerHelper.ConnectionStringIsSet())
        {
            InstallerHelper.InstallRedirect();
        }

        if (Request["break"] != null && Request["pass"] != null && Request["pass"] == "F84AF58F-3A59-45f6-B740-C0A9ABE8FA99")
        {
            Application.Add("break", Request["break"]);
        }

        if (Application["break"] != null && (string)Application["break"] == "true")
        {
            Response.End();
        }
    }
        /// <summary>
        /// Event handler for BeginRequest.
        /// </summary>
        /// <param name="sender">Sender object instance.</param>
        /// <param name="e">Event arguments.</param>
        private void Context_BeginRequest(object sender, EventArgs e)
        {
            if (InstallerHelper.ConnectionStringIsSet())
            {
                try
                {
                    //exit if a request for a .net mapping that isn't a content page is made i.e. axd
                    if (!CommonHelper.IsContentPageRequested())
                    {
                        return;
                    }
                    //exit if a request for a .net mapping that isn't a content page is made i.e. axd
                    if (!CommonHelper.IsContentPageRequested())
                    {
                        return;
                    }

                    if (HttpContext.Current != null && !HttpContext.Current.Request.Url.IsLoopback)
                    {
                        HttpApplication application = sender as HttpApplication;
                        var             clientIp    = new BannedIpAddress();
                        clientIp.Address = application.Request.UserHostAddress;
                        // On any unexpected error we let visitor to visit website
                        if (IoC.Resolve <IBlacklistService>().IsIpAddressBanned(clientIp))
                        {
                            // Blocking process

                            // for now just show error 404 - Forbidden
                            // later let the user know that his ip address/network
                            // was banned and a reason why... this means we need an error page (aspx)
                            application.Response.StatusCode = 403;
                            application.Server.Transfer("~/BannedAddress.htm");
                            application.Response.StatusDescription = "Access is denied";
                            application.Response.End();
                        }
                    }
                }
                catch (Exception)
                {
                }
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Application BeginRequest
        /// </summary>
        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            try {
                if (HttpContext.Current != null)
                {
                    if (HttpContext.Current.Request.Cookies["UICulture"] == null)
                    {
                        HttpContext.Current.Response.Cookies["UICulture"].Value   = System.Web.Configuration.WebConfigurationManager.AppSettings["UICulture"];
                        HttpContext.Current.Response.Cookies["UICulture"].Expires = DateTime.Now.AddDays(30);
                    }

                    if (HttpContext.Current.Request.Cookies["UICulture"] != null)
                    {
                        var lang = HttpContext.Current.Request.Cookies["UICulture"].Value;
                        if (!String.IsNullOrEmpty(lang))
                        {
                            System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo(lang);
                            System.Threading.Thread.CurrentThread.CurrentCulture   = System.Globalization.CultureInfo.CreateSpecificCulture(lang);
                        }
                    }

                    var thisPage = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path);
                    if (thisPage.ToLower().EndsWith(".aspx"))
                    {
                        if (!InstallerHelper.ConnectionStringIsSet())
                        {
                            InstallerHelper.RedirectToInstallationPage(null);
                        }

                        if (thisPage.ToLower().EndsWith("login.aspx"))
                        {
                            if (!InstallerHelper.LscDataIsSet())
                            {
                                InstallerHelper.RedirectToInstallationPage(new string[] { "_sl=1" });
                            }
                        }
                    }
                }
            } catch (Exception err) {
                WebUtility.WriteLog(EnmSysLogLevel.Error, EnmSysLogType.Exception, err.ToString(), "System");
            }
        }
        /// <summary>
        /// Gets a value indicating whether the specified user is in the specified role for the configured applicationName.
        /// </summary>
        /// <param name="username">The user name to search for.</param>
        /// <param name="roleName">The role to search in.</param>
        /// <returns>true if the specified user is in the specified role for the configured applicationName; otherwise, false.</returns>
        public override bool IsUserInRole(string username, string roleName)
        {
            if (String.IsNullOrEmpty(roleName))
            {
                return(false);
            }

            if (InstallerHelper.ConnectionStringIsSet())
            {
                Customer customer = null;
                if (IoC.Resolve <ICustomerService>().UsernamesEnabled)
                {
                    customer = IoC.Resolve <ICustomerService>().GetCustomerByUsername(username);
                }
                else
                {
                    customer = IoC.Resolve <ICustomerService>().GetCustomerByEmail(username);
                }

                if (customer == null)
                {
                    return(false);
                }

                var customerRoles = IoC.Resolve <ICustomerService>().GetCustomerRolesByCustomerId(customer.CustomerId, false);
                foreach (var cr in customerRoles)
                {
                    if (cr.Active)
                    {
                        if (roleName.ToLowerInvariant() == cr.Name.ToLowerInvariant())
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
 /// <summary>
 /// Handlers the EndRequest event of the application
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The instance containing the event data.</param>
 protected void Application_EndRequest(object sender, EventArgs e)
 {
     if (InstallerHelper.ConnectionStringIsSet())
     {
         try
         {
             bool sessionReseted = false;
             if (NopContext.Current["Nop.SessionReseted"] != null)
             {
                 sessionReseted = Convert.ToBoolean(NopContext.Current["Nop.SessionReseted"]);
             }
             if (!sessionReseted)
             {
                 NopContext.Current.SessionSaveToClient();
             }
         }
         catch (Exception exc)
         {
             LogManager.InsertLog(LogTypeEnum.Unknown, exc.Message, exc);
         }
     }
 }
Exemplo n.º 17
0
    void Application_Error(object sender, EventArgs e)
    {
        Exception ex = Server.GetLastError();

        if (ex != null)
        {
            //try
            //{
            if (InstallerHelper.ConnectionStringIsSet())
            {
                LogManager.InsertLog(LogTypeEnum.Unknown, ex.Message, ex);
            }
            //}
            //catch
            //{
            //TODO write to file
            //if (HttpContext.Current != null)
            //{
            //    string path = "~/Error/" + DateTime.Today.ToString("dd-mm-yy") + ".txt";
            //    if (!File.Exists(System.Web.HttpContext.Current.Server.MapPath(path)))
            //    {
            //        File.Create(System.Web.HttpContext.Current.Server.MapPath(path)).Close();
            //    }
            //    using (StreamWriter w = File.AppendText(HttpContext.Current.Server.MapPath(path)))
            //    {
            //        w.WriteLine("\r\nLog Entry : ");
            //        w.WriteLine("{0}", DateTime.Now.ToString(CultureInfo.InvariantCulture));
            //        string err = "Error in: " + System.Web.HttpContext.Current.Request.Url.ToString() +
            //                      ". Error Message:" + ex.Message;
            //        w.WriteLine(err);
            //        w.WriteLine("__________________________");
            //        w.Flush();
            //        w.Close();
            //    }
            //}
            //}
        }
    }
        /// <summary>
        /// Handlers the BeginRequest event of the application
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The instance containing the event data.</param>
        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            if (InstallerHelper.ConnectionStringIsSet())
            {
                NopContext.Current.IsAdmin = CommonHelper.IsAdmin();

                if (NopContext.Current.Session != null)
                {
                    //TODO check behaviour in daylight saving time
                    DateTime dtNow = DateTime.UtcNow;
                    if (NopContext.Current.Session.LastAccessed.AddMinutes(1.0) < dtNow)
                    {
                        NopContext.Current.Session.LastAccessed = dtNow;
                        NopContext.Current.Session = CustomerManager.SaveCustomerSession(NopContext.Current.Session.CustomerSessionGUID, NopContext.Current.Session.CustomerID, NopContext.Current.Session.LastAccessed, false);
                    }
                }

                Language currentLanguage = NopContext.Current.WorkingLanguage;
                if (currentLanguage != null)
                {
                    NopContext.Current.SetCulture(new CultureInfo(currentLanguage.LanguageCulture));
                }
            }
        }
        /// <summary>
        /// Gets a list of the roles that a specified user is in for the configured applicationName.
        /// </summary>
        /// <param name="username">The user to return a list of roles for.</param>
        /// <returns>A string array containing the names of all the roles that the specified user is in for the configured applicationName.</returns>
        public override string[] GetRolesForUser(string username)
        {
            var roles = new List <string>();

            if (InstallerHelper.ConnectionStringIsSet())
            {
                Customer customer = null;
                if (IoC.Resolve <ICustomerService>().UsernamesEnabled)
                {
                    customer = IoC.Resolve <ICustomerService>().GetCustomerByUsername(username);
                }
                else
                {
                    customer = IoC.Resolve <ICustomerService>().GetCustomerByEmail(username);
                }
                if (customer == null)
                {
                    return(roles.ToArray());
                }
                else
                {
                    var customerRoles = IoC.Resolve <ICustomerService>().GetCustomerRolesByCustomerId(customer.CustomerId, false);
                    foreach (var cr in customerRoles)
                    {
                        if (cr.Active)
                        {
                            if (!roles.Contains(cr.Name))
                            {
                                roles.Add(cr.Name);
                            }
                        }
                    }
                }
            }
            return(roles.ToArray());
        }
        /// <summary>
        /// Tracks current user
        /// </summary>
        public void TrackCurrentUser()
        {
            try
            {
                if (!this.Enabled ||
                    !InstallerHelper.ConnectionStringIsSet() ||
                    HttpContext.Current == null)
                {
                    return;
                }

                lock (s_lock)
                {
                    //getting current user info (OnlineUserInfo)
                    OnlineUserInfo oui = null;

                    //user list
                    Dictionary <Guid, OnlineUserInfo> userList = null;
                    if (NopContext.Current.User != null && !NopContext.Current.User.IsGuest)
                    {
                        //registered user
                        userList = GetRegisteredUserList();

                        //find user info
                        if (userList.ContainsKey(NopContext.Current.User.CustomerGuid))
                        {
                            oui = userList[NopContext.Current.User.CustomerGuid];
                        }

                        //create new user if existing one was not found
                        if (oui == null)
                        {
                            oui = new OnlineUserInfo();
                            oui.OnlineUserGuid = NopContext.Current.User.CustomerGuid;
                            oui.CreatedOn      = DateTime.UtcNow;
                            userList.Add(oui.OnlineUserGuid, oui);
                        }

                        //update other properties
                        oui.LastVisit            = DateTime.UtcNow;
                        oui.LastPageVisited      = CommonHelper.GetThisPageUrl(true);
                        oui.IPAddress            = NopContext.Current.UserHostAddress;
                        oui.AssociatedCustomerId = NopContext.Current.User.CustomerId;
                        HttpContext.Current.Response.Cookies.Remove(TRACKINGCOOKIENAME);
                    }
                    else
                    {
                        //guest
                        userList = GetAnonymousUserList();

                        //find user info
                        string cookieValue = string.Empty;
                        if ((HttpContext.Current.Request.Cookies[TRACKINGCOOKIENAME] != null) && (HttpContext.Current.Request.Cookies[TRACKINGCOOKIENAME].Value != null))
                        {
                            cookieValue = HttpContext.Current.Request.Cookies[TRACKINGCOOKIENAME].Value;
                        }
                        if (!string.IsNullOrEmpty(cookieValue))
                        {
                            Guid onlineUserGuid = Guid.Empty;
                            Guid.TryParse(cookieValue, out onlineUserGuid);
                            if (onlineUserGuid != Guid.Empty)
                            {
                                if (userList.ContainsKey(onlineUserGuid))
                                {
                                    oui = userList[onlineUserGuid];
                                }
                            }
                        }

                        //create new user if existing one was not found
                        if (oui == null)
                        {
                            oui = new OnlineUserInfo();
                            oui.OnlineUserGuid = Guid.NewGuid();
                            oui.CreatedOn      = DateTime.UtcNow;
                            userList.Add(oui.OnlineUserGuid, oui);
                        }

                        //update other properties
                        oui.LastVisit            = DateTime.UtcNow;
                        oui.LastPageVisited      = CommonHelper.GetThisPageUrl(true);
                        oui.IPAddress            = NopContext.Current.UserHostAddress;
                        oui.AssociatedCustomerId = null;

                        //save new cookie
                        HttpCookie cookie = new HttpCookie(TRACKINGCOOKIENAME);
                        cookie.Value   = oui.OnlineUserGuid.ToString();
                        cookie.Expires = DateTime.Now.AddHours(1);
                        HttpContext.Current.Response.Cookies.Remove(TRACKINGCOOKIENAME);
                        HttpContext.Current.Response.Cookies.Add(cookie);
                    }

                    //maximum online customers
                    int currentVisitors = GetAnonymousUserList().Count() + GetRegisteredUserList().Count();
                    if (currentVisitors > this.MaximumOnlineCustomers)
                    {
                        this.MaximumOnlineCustomers = currentVisitors;
                    }
                }
            }
            catch (NopException exc)
            {
                Debug.WriteLine(exc.ToString());
            }
        }
Exemplo n.º 21
0
 /// <summary>
 /// Handlers the PostAcquireRequestState event of the application
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The instance containing the event data.</param>
 private void Application_PostAcquireRequestState(object sender, EventArgs e)
 {
     if (InstallerHelper.ConnectionStringIsSet())
     {
     }
 }
Exemplo n.º 22
0
        /// <summary>
        /// Handlers the AuthenticateRequest event of the application
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The instance containing the event data.</param>
        private void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            if (InstallerHelper.ConnectionStringIsSet())
            {
                //exit if a request for a .net mapping that isn't a content page is made i.e. axd
                if (!CommonHelper.IsContentPageRequested())
                {
                    return;
                }

                //authentication
                bool authenticated = false;
                if (HttpContext.Current.User != null && HttpContext.Current.User.Identity != null)
                {
                    authenticated = HttpContext.Current.User.Identity.IsAuthenticated;
                }

                if (authenticated)
                {
                    Customer customer = null;
                    string   name     = HttpContext.Current.User.Identity.Name;
                    if (CustomerManager.UsernamesEnabled)
                    {
                        customer = CustomerManager.GetCustomerByUsername(name);
                    }
                    else
                    {
                        customer = CustomerManager.GetCustomerByEmail(name);
                    }

                    if (customer != null)
                    {
                        if (!String.IsNullOrEmpty(HttpContext.Current.User.Identity.Name) &&
                            customer.Active &&
                            !customer.Deleted && !customer.IsGuest)
                        {
                            //impersonate user if required (currently used for 'phone order' support)
                            //and validate that the current user is admin
                            //and validate that we're in public store
                            if (customer.IsAdmin &&
                                !CommonHelper.IsAdmin() &&
                                customer.ImpersonatedCustomerGuid != Guid.Empty)
                            {
                                //set impersonated customer
                                var impersonatedCustomer = CustomerManager.GetCustomerByGuid(customer.ImpersonatedCustomerGuid);
                                if (impersonatedCustomer != null)
                                {
                                    NopContext.Current.User = impersonatedCustomer;
                                    NopContext.Current.IsCurrentCustomerImpersonated = true;
                                    NopContext.Current.OriginalUser = customer;
                                }
                                else
                                {
                                    //set current customer
                                    NopContext.Current.User = customer;
                                }
                            }
                            else
                            {
                                //set current customer
                                NopContext.Current.User = customer;
                            }

                            //set current customer session
                            var customerSession = CustomerManager.GetCustomerSessionByCustomerId(NopContext.Current.User.CustomerId);
                            if (customerSession == null)
                            {
                                customerSession              = NopContext.Current.GetSession(true);
                                customerSession.IsExpired    = false;
                                customerSession.LastAccessed = DateTime.UtcNow;
                                customerSession.CustomerId   = NopContext.Current.User.CustomerId;
                                customerSession              = CustomerManager.SaveCustomerSession(customerSession.CustomerSessionGuid, customerSession.CustomerId, customerSession.LastAccessed, customerSession.IsExpired);
                            }
                            NopContext.Current.Session = customerSession;
                        }
                        else
                        {
                            logout();
                        }
                    }
                    else
                    {
                        logout();
                    }
                }
                else
                {
                    if (NopContext.Current.Session != null)
                    {
                        var guestCustomer = NopContext.Current.Session.Customer;
                        if (guestCustomer != null && guestCustomer.Active && !guestCustomer.Deleted && guestCustomer.IsGuest)
                        {
                            NopContext.Current.User = guestCustomer;
                        }
                    }
                }
            }
        }
Exemplo n.º 23
0
        protected void Page_Load(Object sender, EventArgs e)
        {
            CommonHelper.SetResponseNoCache(Response);

            lblVersion.Text = string.Format("nopCommerce {0}", GetNewVersion());

            if (!this.IsPostBack)
            {
                if (InstallerHelper.ConnectionStringIsSet())
                {
                    Response.Redirect(CommonHelper.GetStoreLocation());
                }

                bool checkPermission = Convert.ToBoolean(CommonHelper.QueryStringInt("checkpermission", 1));
                bool testAgain       = Convert.ToBoolean(CommonHelper.QueryStringInt("testagain", 0));

                string rootDir = HttpContext.Current.Server.MapPath("~/");

                List <string> dirsToCheck = new List <string>();
                dirsToCheck.Add(rootDir);
                dirsToCheck.Add(rootDir + "Administration\\backups");
                dirsToCheck.Add(rootDir + "files");
                dirsToCheck.Add(rootDir + "files\\become");
                dirsToCheck.Add(rootDir + "files\\ExportImport");
                dirsToCheck.Add(rootDir + "files\\froogle");
                dirsToCheck.Add(rootDir + "files\\pricegrabber");
                dirsToCheck.Add(rootDir + "Google");
                dirsToCheck.Add(rootDir + "images");
                dirsToCheck.Add(rootDir + "images\\thumbs");
                foreach (string dir in dirsToCheck)
                {
                    if (!checkPermissions(dir, false, true, true, true) && checkPermission)
                    {
                        pnlWizard.Visible     = false;
                        imgHeader.Visible     = false;
                        pnlPermission.Visible = true;
                        pnlButtons.Visible    = true;
                        lblPermission.Text    = string.Format("The <b>{0}</b> account is not granted with Modify permission on folder <b>{1}</b>. Although this is not an error, it's highly recommended that you configure these permissions.", System.Security.Principal.WindowsIdentity.GetCurrent().Name, dir);
                        return;
                    }
                }

                List <string> filesToCheck = new List <string>();
                filesToCheck.Add(rootDir + "ConnectionStrings.config");
                filesToCheck.Add(rootDir + "web.config");
                foreach (string file in filesToCheck)
                {
                    if (!checkPermissions(file, false, true, true, true) && checkPermission)
                    {
                        pnlWizard.Visible     = false;
                        imgHeader.Visible     = false;
                        pnlPermission.Visible = true;
                        pnlButtons.Visible    = true;
                        lblPermission.Text    = string.Format("The <b>{0}</b> account is not granted with Modify permission on file <b>{1}</b>. Although this is not an error, it's highly recommended that you configure these permissions.", System.Security.Principal.WindowsIdentity.GetCurrent().Name, file);
                        return;
                    }
                }

                if (testAgain)
                {
                    pnlWizard.Visible            = false;
                    pnlPermission.Visible        = false;
                    pnlButtons.Visible           = false;
                    pnlPermissionSuccess.Visible = true;
                    lblPermissionSuccess.Text    = "The permissions are configured correctly now.";
                    return;
                }
            }

            pnlWizard.Visible     = true;
            pnlPermission.Visible = false;
            pnlButtons.Visible    = false;

            if (!this.IsPostBack)
            {
                if (HttpContext.Current != null)
                {
                    txtServerName.Text = HttpContext.Current.Server.MachineName;
                }
                this.TrustedConnection       = false;
                wzdInstaller.ActiveStepIndex = 0;
            }
            else
            {
                if (ViewState["install.password"] == null)
                {
                    ViewState["install.password"] = this.txtPassword.Text;
                }
            }

            this.pnlLog.Visible = false;
            this.lblError.Text  = string.Empty;
            this.rbWindowsAuthentication.Text = string.Format("Use integrated Windows authentication (ASP.NET account: {0})", System.Security.Principal.WindowsIdentity.GetCurrent().Name);

            mResult = string.Empty;
        }
        /// <summary>
        /// Handlers the AuthenticateRequest event of the application
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The instance containing the event data.</param>
        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            if (InstallerHelper.ConnectionStringIsSet())
            {
                bool authenticated = false;
                if (HttpContext.Current.User != null && HttpContext.Current.User.Identity != null)
                {
                    authenticated = HttpContext.Current.User.Identity.IsAuthenticated;
                }

                if (authenticated)
                {
                    Customer customer = null;
                    string   name     = HttpContext.Current.User.Identity.Name;
                    if (CustomerManager.UsernamesEnabled)
                    {
                        customer = CustomerManager.GetCustomerByUsername(name);
                    }
                    else
                    {
                        customer = CustomerManager.GetCustomerByEmail(name);
                    }

                    if (customer != null)
                    {
                        CustomerSession registeredCustomerSession = CustomerManager.GetCustomerSessionByCustomerID(customer.CustomerID);
                        if (registeredCustomerSession == null)
                        {
                            registeredCustomerSession              = NopContext.Current.GetSession(true);
                            registeredCustomerSession.IsExpired    = false;
                            registeredCustomerSession.LastAccessed = DateTime.UtcNow;
                            registeredCustomerSession.CustomerID   = customer.CustomerID;
                            registeredCustomerSession              = CustomerManager.SaveCustomerSession(registeredCustomerSession.CustomerSessionGUID, registeredCustomerSession.CustomerID, registeredCustomerSession.LastAccessed, registeredCustomerSession.IsExpired);
                        }

                        if (!String.IsNullOrEmpty(HttpContext.Current.User.Identity.Name) &&
                            customer.Active &&
                            !customer.Deleted && !customer.IsGuest)
                        {
                            NopContext.Current.User    = customer;
                            NopContext.Current.Session = registeredCustomerSession;
                        }
                        else
                        {
                            logout();
                        }
                    }
                    else
                    {
                        logout();
                    }
                }
                else
                {
                    if (NopContext.Current.Session != null)
                    {
                        Customer guestCustomer = NopContext.Current.Session.Customer;
                        if (guestCustomer != null && guestCustomer.Active && !guestCustomer.Deleted && guestCustomer.IsGuest)
                        {
                            NopContext.Current.User = guestCustomer;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Configure root container.Register types and life time managers for unity builder process
        /// </summary>
        /// <param name="container">Container to configure</param>
        protected virtual void ConfigureContainer(IUnityContainer container)
        {
            //Take into account that Types and Mappings registration could be also done using the UNITY XML configuration
            //But we prefer doing it here (C# code) because we'll catch errors at compiling time instead execution time, if any type has been written wrong.

            //Register repositories mappings
            //to be done

            //Register default cache manager
            //container.RegisterType<ICacheManager, NopRequestCache>(new PerExecutionContextLifetimeManager());

            //Register managers(services) mappings
            container.RegisterType <IOnlineUserService, OnlineUserService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <ISearchLogService, SearchLogService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <ICustomerActivityService, CustomerActivityService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <ILogService, LogService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <ICategoryService, CategoryService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <ISettingManager, SettingManager>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <IBlogService, BlogService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <IForumService, ForumService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <INewsService, NewsService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <IPollService, PollService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <ITopicService, TopicService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <ICustomerService, CustomerService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <ICountryService, CountryService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <ICurrencyService, CurrencyService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <ILanguageService, LanguageService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <IStateProvinceService, StateProvinceService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <IExportManager, ExportManager>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <IImportManager, ImportManager>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <ILocalizationManager, LocalizationManager>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <IMaintenanceService, MaintenanceService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <IManufacturerService, ManufacturerService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <IMeasureService, MeasureService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <IDownloadService, DownloadService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <IPictureService, PictureService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <ISMSService, SMSService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <IMessageService, MessageService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <IOrderService, OrderService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <IShoppingCartService, ShoppingCartService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <IPaymentService, PaymentService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <ICheckoutAttributeService, CheckoutAttributeService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <IProductAttributeService, ProductAttributeService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <ISpecificationAttributeService, SpecificationAttributeService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <IProductService, ProductService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <IAffiliateService, AffiliateService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <ICampaignService, CampaignService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <IDiscountService, DiscountService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <IQBService, QBService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <IACLService, ACLService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <IBlacklistService, BlacklistService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <IShippingByTotalService, ShippingByTotalService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <IShippingByWeightAndCountryService, ShippingByWeightAndCountryService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <IShippingByWeightService, ShippingByWeightService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <IShippingService, ShippingService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <ITaxCategoryService, TaxCategoryService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <ITaxService, TaxService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <ITaxProviderService, TaxProviderService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <ITaxRateService, TaxRateService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <ITemplateService, TemplateService>(new UnityPerExecutionContextLifetimeManager());
            container.RegisterType <IWarehouseService, WarehouseService>(new UnityPerExecutionContextLifetimeManager());

            //Object context

            //Connection string
            if (InstallerHelper.ConnectionStringIsSet())
            {
                var ecsbuilder = new EntityConnectionStringBuilder();
                ecsbuilder.Provider = "System.Data.SqlClient";
                ecsbuilder.ProviderConnectionString = NopConfig.ConnectionString;
                ecsbuilder.Metadata = @"res://*/Data.NopModel.csdl|res://*/Data.NopModel.ssdl|res://*/Data.NopModel.msl";
                string connectionString = ecsbuilder.ToString();
                InjectionConstructor connectionStringParam = new InjectionConstructor(connectionString);
                //Registering object context
                container.RegisterType <NopObjectContext>(new UnityPerExecutionContextLifetimeManager(), connectionStringParam);
            }
        }
Exemplo n.º 26
0
        protected void Page_Load(Object sender, EventArgs e)
        {
            lblVersion.Text = String.Format("版本: {0}", GetNewVersion());
            if (!Page.IsPostBack)
            {
                if (InstallerHelper.ConnectionStringIsSet() && InstallerHelper.LscDataIsSet())
                {
                    FormsAuthentication.RedirectToLoginPage();
                    return;
                }

                var checkPermission = Convert.ToBoolean(this.QueryStringInt("checkpermission", 1));
                var testAgain       = Convert.ToBoolean(this.QueryStringInt("testagain", 0));
                var rootDir         = HttpContext.Current.Server.MapPath("~/");
                var dirsToCheck     = new List <string>();
                dirsToCheck.Add(rootDir);
                dirsToCheck.Add(rootDir + "Install\\Scripts");
                dirsToCheck.Add(rootDir + "Logs\\RUN");
                dirsToCheck.Add(rootDir + "TempImages");
                foreach (var dir in dirsToCheck)
                {
                    if (!checkPermissions(dir, true, true, true, true) && checkPermission)
                    {
                        pnlWizard.Visible     = false;
                        imgHeader.Visible     = false;
                        pnlPermission.Visible = true;
                        pnlButtons.Visible    = true;
                        lblPermission.Text    = String.Format(@"<b>警告:</b> {0} 账户对文件夹 {1} 没有完全控制权限,请对该文件夹配置这些权限。", System.Security.Principal.WindowsIdentity.GetCurrent().Name, dir);
                        return;
                    }
                }

                var filesToCheck = new List <string>();
                filesToCheck.Add(rootDir + "ConnectionStrings.config");
                filesToCheck.Add(rootDir + "web.config");
                foreach (var file in filesToCheck)
                {
                    if (!checkPermissions(file, false, true, true, true) && checkPermission)
                    {
                        pnlWizard.Visible     = false;
                        imgHeader.Visible     = false;
                        pnlPermission.Visible = true;
                        pnlButtons.Visible    = true;
                        lblPermission.Text    = String.Format(@"<b>警告:</b> {0} 账户对文件 {1} 没有完全控制权限,请对该文件配置这些权限。", System.Security.Principal.WindowsIdentity.GetCurrent().Name, file);
                        return;
                    }
                }

                if (testAgain)
                {
                    pnlWizard.Visible            = false;
                    pnlPermission.Visible        = false;
                    pnlButtons.Visible           = false;
                    pnlPermissionSuccess.Visible = true;
                    lblPermissionSuccess.Text    = "完全控制权限已经配置成功!";
                    return;
                }
            }

            pnlWizard.Visible     = true;
            pnlPermission.Visible = false;
            pnlButtons.Visible    = false;
            if (!Page.IsPostBack)
            {
                var setData = Convert.ToBoolean(this.QueryStringInt("_sl", 0));
                if (setData)
                {
                    this.gvLsc_DataBind();
                    wzdInstaller.ActiveStepIndex = this.wzdInstaller.WizardSteps.IndexOf(this.stpLscSetting);
                }
                else
                {
                    if (HttpContext.Current != null)
                    {
                        txtServerName.Text    = WebUtility.GetServerIP();
                        txtHisServerName.Text = WebUtility.GetServerIP();
                    }

                    this.TrustedConnection       = false;
                    this.HisTrustedConnection    = false;
                    wzdInstaller.ActiveStepIndex = 0;
                }
            }
            else
            {
                if (ViewState["install.password"] == null)
                {
                    ViewState["install.password"] = this.txtPassword.Text;
                }
            }

            this.pnlLog.Visible = false;
            this.lblError.Text  = String.Empty;
            mResult             = String.Empty;
        }