public IActionResult ChangeTheme([FromQuery] string selection)
        {
            var state = new PEngineStateModel(Settings.Current, HttpContext, false, false);

            if (state.ThemeList.Any(t => t.Equals(selection, StringComparison.OrdinalIgnoreCase)))
            {
                state.ThemeChange(selection);
            }
            var redirectUrl = "/";

            if (!string.IsNullOrWhiteSpace(Request.Headers[HeaderNames.Referer]))
            {
                if (!string.IsNullOrWhiteSpace(Settings.Current.ExternalBaseUrl) &&
                    Request.Headers[HeaderNames.Referer].ToString().StartsWith(Settings.Current.ExternalBaseUrl, StringComparison.OrdinalIgnoreCase) &&
                    Request.Headers[HeaderNames.Referer].ToString().Length > Settings.Current.ExternalBaseUrl.Length)
                {
                    redirectUrl = Request.Headers[HeaderNames.Referer];
                    if (Settings.Current.ExternalBaseUrl.EndsWith("/"))
                    {
                        redirectUrl = redirectUrl.Substring(Settings.Current.ExternalBaseUrl.Length - 1);
                    }
                    else
                    {
                        redirectUrl = redirectUrl.Substring(Settings.Current.ExternalBaseUrl.Length);
                    }
                }
            }
            return(this.Redirect(redirectUrl));
        }
Example #2
0
        public IActionResult ChangeTheme([FromQuery] string selection)
        {
            var state = new PEngineStateModel(_svp, Settings.Current, HttpContext, false, false);

            if (!Settings.Current.DisableThemeSelection)
            {
                if (state.ThemeList.Any(t => t.Equals(selection, StringComparison.OrdinalIgnoreCase)))
                {
                    state.ThemeChange(selection);
                }
                var redirectUrl = PEngine.Core.Shared.Settings.Current.BasePath;
                if (!string.IsNullOrWhiteSpace(Request.Headers[HeaderNames.Referer]))
                {
                    redirectUrl = Request.Headers[HeaderNames.Referer];
                }
                return(this.Redirect(redirectUrl));
            }
            else
            {
                return(this.NotFound());
            }
        }