示例#1
0
        public Task <bool> MatchAsync(CartRuleContext context, RuleExpression expression)
        {
            var country = _countryLookup.LookupCountry(_webHelper.GetClientIpAddress());
            var match   = expression.HasListMatch(country?.IsoCode ?? string.Empty, StringComparer.InvariantCultureIgnoreCase);

            return(Task.FromResult(match));
        }
示例#2
0
 public async Task Invoke(HttpContext context, IWebHelper webHelper, IWorkContext workContext)
 {
     using (LogContext.PushProperty("CustomerId", workContext.CurrentCustomer?.Id))
         using (LogContext.PushProperty("UserName", context.User.Identity.Name))
             using (LogContext.PushProperty("Url", webHelper.GetCurrentPageUrl(true)))
                 using (LogContext.PushProperty("Referrer", webHelper.GetUrlReferrer()))
                     using (LogContext.PushProperty("HttpMethod", context?.Request.Method))
                         using (LogContext.PushProperty("Ip", webHelper.GetClientIpAddress().ToString()))
                         {
                             await _next.Invoke(context);
                         }
 }
示例#3
0
            public void OnAuthorization(AuthorizationFilterContext context)
            {
                if (!_validate)
                {
                    return;
                }

                // Prevent lockout
                if (context.HttpContext.Connection.IsLocal())
                {
                    return;
                }

                var overrideFilter = context.ActionDescriptor.FilterDescriptors
                                     .Where(x => x.Scope == FilterScope.Action)
                                     .Select(x => x.Filter)
                                     .OfType <ValidateAdminIpAddressAttribute>()
                                     .FirstOrDefault();

                if (overrideFilter?.Validate == false)
                {
                    return;
                }

                var  allowedIpAddresses = _securitySettings.AdminAreaAllowedIpAddresses;
                bool allow = allowedIpAddresses == null || allowedIpAddresses.Count == 0;

                if (!allow)
                {
                    var currentIpAddress = _webHelper.GetClientIpAddress().ToString();
                    allow = allowedIpAddresses.Any(ip => ip.EqualsNoCase(currentIpAddress));
                }

                if (!allow)
                {
                    throw new AccessDeniedException();
                }
            }
示例#4
0
        private async Task <bool> DisplayForCountryAsync()
        {
            var ipAddress             = _webHelper.GetClientIpAddress();
            var lookUpCountryResponse = _countryLookup.LookupCountry(ipAddress);

            if (lookUpCountryResponse?.IsoCode == null)
            {
                // No country was found (e.g. localhost), so we better return true.
                return(true);
            }

            var country = await _db.Countries
                          .AsNoTracking()
                          .ApplyIsoCodeFilter(lookUpCountryResponse.IsoCode)
                          .FirstOrDefaultAsync();

            if (country != null && country.DisplayCookieManager)
            {
                // Country was configured to display cookie manager.
                return(true);
            }

            return(false);
        }
示例#5
0
        public async Task <IActionResult> ReviewsAdd(int id, ProductReviewsModel model, string captchaError)
        {
            // INFO: Entitity is being loaded tracked because else navigation properties can't be loaded in PrepareProductReviewsModelAsync.
            var product = await _db.Products
                          .IncludeReviews()
                          .FindByIdAsync(id);

            if (product == null || product.IsSystemProduct || !product.Published || !product.AllowCustomerReviews)
            {
                return(NotFound());
            }

            if (_captchaSettings.ShowOnProductReviewPage && captchaError.HasValue())
            {
                ModelState.AddModelError("", captchaError);
            }

            var customer = Services.WorkContext.CurrentCustomer;

            if (customer.IsGuest() && !_catalogSettings.AllowAnonymousUsersToReviewProduct)
            {
                ModelState.AddModelError("", T("Reviews.OnlyRegisteredUsersCanWriteReviews"));
            }

            if (ModelState.IsValid)
            {
                var rating = model.Rating;
                if (rating < 1 || rating > 5)
                {
                    rating = _catalogSettings.DefaultProductRatingValue;
                }

                var isApproved    = !_catalogSettings.ProductReviewsMustBeApproved;
                var productReview = new ProductReview
                {
                    ProductId       = product.Id,
                    CustomerId      = customer.Id,
                    IpAddress       = _webHelper.GetClientIpAddress().ToString(),
                    Title           = model.Title,
                    ReviewText      = model.ReviewText,
                    Rating          = rating,
                    HelpfulYesTotal = 0,
                    HelpfulNoTotal  = 0,
                    IsApproved      = isApproved,
                };

                product.ProductReviews.Add(productReview);
                _productService.ApplyProductReviewTotals(product);

                if (_catalogSettings.NotifyStoreOwnerAboutNewProductReviews)
                {
                    await _messageFactory.Value.SendProductReviewNotificationMessageAsync(productReview, _localizationSettings.DefaultAdminLanguageId);
                }

                Services.ActivityLogger.LogActivity("PublicStore.AddProductReview", T("ActivityLog.PublicStore.AddProductReview"), product.Name);

                if (isApproved)
                {
                    _customerService.ApplyRewardPointsForProductReview(customer, product, true);
                }

                TempData["SuccessfullyAdded"] = true;

                return(RedirectToAction("Reviews"));
            }

            // If we got this far something failed. Redisplay form.
            await _helper.PrepareProductReviewsModelAsync(model, product);

            return(View(model));
        }
        private void DoTrack(ActionExecutingContext context)
        {
            if (!HttpMethods.IsGet(context.HttpContext.Request.Method))
            {
                return;
            }

            var customer = _workContext.CurrentCustomer;

            if (customer == null || customer.Deleted || customer.IsSystemAccount)
            {
                return;
            }

            bool dirty = false;

            // Last activity date
            if (_attribute.TrackDate && customer.LastActivityDateUtc.AddMinutes(1.0) < DateTime.UtcNow)
            {
                customer.LastActivityDateUtc = DateTime.UtcNow;
                dirty = true;
            }

            // Last IP address
            if (_attribute.TrackIpAddress && _privacySettings.StoreLastIpAddress)
            {
                var currentIpAddress = _webHelper.GetClientIpAddress().ToString();
                if (currentIpAddress.HasValue())
                {
                    customer.LastIpAddress = currentIpAddress;
                    dirty = true;
                }
            }

            // Last visited page
            if (_attribute.TrackPage && _customerSettings.StoreLastVisitedPage)
            {
                var currentUrl = _webHelper.GetCurrentPageUrl(true);
                if (currentUrl.HasValue())
                {
                    customer.GenericAttributes.LastVisitedPage = currentUrl;
                    dirty = true;
                }
            }

            // Last user agent
            if (_attribute.TrackUserAgent && _customerSettings.StoreLastVisitedPage)
            {
                // TODO: (core) Make new setting CustomerSettings.StoreLastUserAgent
                var currentUserAgent = _userAgent.RawValue;
                if (currentUserAgent.HasValue())
                {
                    customer.LastUserAgent = currentUserAgent;
                    dirty = true;
                }
            }

            if (dirty)
            {
                _db.TryUpdate(customer);
            }
        }