Exemple #1
0
        /// <summary>
        /// Invoke middleware actions
        /// </summary>
        /// <param name="context">HTTP context</param>
        /// <returns>Task</returns>
        public async Task InvokeAsync(HttpContext context, IWorkContext workContext)
        {
            //set current customer
            var customer = await workContext.SetCurrentCustomer();

            var vendor = await workContext.SetCurrentVendor(customer);

            var language = await workContext.SetWorkingLanguage(customer);

            var currency = await workContext.SetWorkingCurrency(customer);

            var taxtype = await workContext.SetTaxDisplayType(customer);

            //set culture in admin area
            if (context.Request.Path.Value.StartsWith("/admin", StringComparison.InvariantCultureIgnoreCase))
            {
                var culture = new CultureInfo("en-US");
                CultureInfo.CurrentCulture   = culture;
                CultureInfo.CurrentUICulture = culture;
            }
            else
            {
                //set culture for customer
                if (!string.IsNullOrEmpty(language?.LanguageCulture))
                {
                    var culture = new CultureInfo(language.LanguageCulture);
                    CultureInfo.CurrentCulture   = culture;
                    CultureInfo.CurrentUICulture = culture;
                }
            }

            //call the next middleware in the request pipeline
            await _next(context);
        }
        /// <summary>
        /// Invoke middleware actions
        /// </summary>
        /// <param name="context">HTTP context</param>
        /// <returns>Task</returns>
        public async Task InvokeAsync(HttpContext context, IWorkContext workContext)
        {
            //set current customer
            var customer = await workContext.SetCurrentCustomer();

            var vendor = await workContext.SetCurrentVendor(customer);

            var language = await workContext.SetWorkingLanguage(customer);

            var currency = await workContext.SetWorkingCurrency(customer);

            var taxtype = await workContext.SetTaxDisplayType(customer);

            //call the next middleware in the request pipeline
            await _next(context);
        }
Exemple #3
0
        public virtual async Task <IActionResult> SetLanguage(
            [FromServices] ILanguageService languageService,
            [FromServices] GrandConfig config,
            string langid, string returnUrl = "")
        {
            var language = await languageService.GetLanguageById(langid);

            if (!language?.Published ?? false)
            {
                language = _workContext.WorkingLanguage;
            }

            //home page
            if (string.IsNullOrEmpty(returnUrl))
            {
                returnUrl = Url.RouteUrl("HomePage");
            }

            //prevent open redirection attack
            if (!Url.IsLocalUrl(returnUrl))
            {
                returnUrl = Url.RouteUrl("HomePage");
            }

            //language part in URL
            if (config.SeoFriendlyUrlsForLanguagesEnabled)
            {
                //remove current language code if it's already localized URL
                if (await returnUrl.IsLocalizedUrlAsync(languageService, this.Request.PathBase, true))
                {
                    returnUrl = returnUrl.RemoveLanguageSeoCodeFromUrl(this.Request.PathBase, true);
                }

                //and add code of passed language
                returnUrl = returnUrl.AddLanguageSeoCodeToUrl(this.Request.PathBase, true, language);
            }

            await _workContext.SetWorkingLanguage(language);

            return(Redirect(returnUrl));
        }
Exemple #4
0
        public async Task <IActionResult> SetLanguage(string langid, [FromServices] ILanguageService languageService, string returnUrl = "")
        {
            var language = await languageService.GetLanguageById(langid);

            if (language != null)
            {
                await _workContext.SetWorkingLanguage(language);
            }

            //home page
            if (String.IsNullOrEmpty(returnUrl))
            {
                returnUrl = Url.Action("Index", "Home", new { area = "Admin" });
            }
            //prevent open redirection attack
            if (!Url.IsLocalUrl(returnUrl))
            {
                return(RedirectToAction("Index", "Home", new { area = "Admin" }));
            }
            return(Redirect(returnUrl));
        }
Exemple #5
0
        public virtual async Task <IActionResult> SetLanguage(
            [FromServices] AppConfig config,
            string langid, string returnUrl = "")
        {
            var language = await _languageService.GetLanguageById(langid);

            if (!language?.Published ?? false)
            {
                language = _workContext.WorkingLanguage;
            }

            //home page
            if (string.IsNullOrEmpty(returnUrl))
            {
                returnUrl = Url.RouteUrl("HomePage");
            }

            //prevent open redirection attack
            if (!Url.IsLocalUrl(returnUrl))
            {
                returnUrl = Url.RouteUrl("HomePage");
            }

            //language part in URL
            if (config.SeoFriendlyUrlsForLanguagesEnabled)
            {
                if (await IsLocalized(returnUrl, this.Request.PathBase))
                {
                    returnUrl = RemoveLanguageSeoCode(returnUrl, this.Request.PathBase);
                }

                returnUrl = AddLanguageSeo(returnUrl, this.Request.PathBase, language);
            }

            await _workContext.SetWorkingLanguage(language);

            return(Redirect(returnUrl));
        }