Beispiel #1
0
        public override async Task <IViewProviderResult> BuildDisplayAsync(Article entity, IViewProviderContext updater)
        {
            // Override breadcrumb configuration within base controller
            IEnumerable <Category> parents = null;

            if (entity.CategoryId > 0)
            {
                parents = await _categoryStore.GetParentsByIdAsync(entity.CategoryId);
            }

            _breadCrumbManager.Configure(builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Home", "Plato.Core")
                            .LocalNav()
                            ).Add(S["Articles"], home => home
                                  .Action("Index", "Home", "Plato.Articles")
                                  .LocalNav()
                                  );

                if (parents != null)
                {
                    builder.Add(S["Categories"], channels => channels
                                .Action("Index", "Home", "Plato.Articles.Categories", new RouteValueDictionary()
                    {
                        ["opts.categoryId"] = null,
                        ["opts.alias"]      = null
                    })
                                .LocalNav()
                                );
                    foreach (var parent in parents)
                    {
                        builder.Add(S[parent.Name], channel => channel
                                    .Action("Index", "Home", "Plato.Articles.Categories", new RouteValueDictionary
                        {
                            ["opts.categoryId"] = parent.Id,
                            ["opts.alias"]      = parent.Alias,
                        })
                                    .LocalNav()
                                    );
                    }
                }

                builder.Add(S[entity.Title]);
            });

            // Get current feature
            var feature = await GetFeatureAsync();

            if (feature == null)
            {
                return(default(IViewProviderResult));
            }

            return(default(IViewProviderResult));
        }
Beispiel #2
0
        public override async Task <IViewProviderResult> BuildDisplayAsync(Issue issue, IViewProviderContext updater)
        {
            // Override breadcrumb configuration within controller
            IEnumerable <CategoryAdmin> parents = null;

            if (issue.CategoryId > 0)
            {
                parents = await _categoryStore.GetParentsByIdAsync(issue.CategoryId);
            }

            _breadCrumbManager.Configure(builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Home", "Plato.Core")
                            .LocalNav()
                            ).Add(S["Issues"], home => home
                                  .Action("Index", "Home", "Plato.Issues")
                                  .LocalNav()
                                  );

                if (parents != null)
                {
                    builder.Add(S["Categories"], c => c
                                .Action("Index", "Home", "Plato.Issues.Categories", new RouteValueDictionary()
                    {
                        ["opts.categoryId"] = null,
                        ["opts.alias"]      = null
                    })
                                .LocalNav()
                                );
                    foreach (var parent in parents)
                    {
                        builder.Add(S[parent.Name], c => c
                                    .Action("Index", "Home", "Plato.Issues.Categories", new RouteValueDictionary
                        {
                            ["opts.categoryId"] = parent.Id,
                            ["opts.alias"]      = parent.Alias,
                        })
                                    .LocalNav()
                                    );
                    }
                }

                builder.Add(S[issue.Title]);
            });


            return(default(IViewProviderResult));
        }
Beispiel #3
0
        public async Task <IActionResult> Index()
        {
            _breadCrumbManager.Configure(builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Admin", "Plato.Admin")
                            .LocalNav()
                            ).Add(S["Settings"], channels => channels
                                  .Action("Index", "Admin", "Plato.Settings")
                                  .LocalNav()
                                  ).Add(S["reCAPTCHA2"]);
            });

            // Get reCAPTCHA settings
            var settings = await _recaptchaSettingsStore.GetAsync();

            // Build view
            var result = await _viewProvider.ProvideEditAsync(new ReCaptchaSettings()
            {
                SiteKey = settings?.SiteKey ?? "",
                Secret  = settings?.Secret ?? ""
            }, this);

            //Return view
            return(View(result));
        }
Beispiel #4
0
        public async Task <IActionResult> Index(FeatureUpdateOptions opts)
        {
            // Ensure we have permission
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageFeatureUpdates))
            {
                return(Unauthorized());
            }

            if (opts == null)
            {
                opts = new FeatureUpdateOptions();
            }

            // Build breadcrumb
            _breadCrumbManager.Configure(builder =>
            {
                builder
                .Add(S["Home"], home => home
                     .Action("Index", "Admin", "Plato.Admin")
                     .LocalNav())
                .Add(S["Features"], features => features
                     .Action("Index", "Admin", "Plato.Features")
                     .LocalNav())
                .Add(S["Updates"]);
            });

            var model = new FeatureUpdatesViewModel()
            {
                Options = opts
            };

            return(View((LayoutViewModel)await _viewProvider.ProvideIndexAsync(model, this)));
        }
Beispiel #5
0
        // ------------
        // Index
        // ------------

        public async Task <IActionResult> Index()
        {
            // Ensure we have permission
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageThemes))
            {
                return(Unauthorized());
            }

            _breadCrumbManager.Configure(builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Admin", "Plato.Admin")
                            .LocalNav()
                            ).Add(S["Themes"]);
            });

            return(View((LayoutViewModel)await _viewProvider.ProvideIndexAsync(new ThemeAdmin(), this)));
        }
Beispiel #6
0
        public async Task <IActionResult> Index(DisplayUserOptions opts)
        {
            if (opts == null)
            {
                opts = new DisplayUserOptions();
            }

            var user = opts.Id > 0
                ? await _platoUserStore.GetByIdAsync(opts.Id)
                : await _contextFacade.GetAuthenticatedUserAsync();

            if (user == null)
            {
                return(NotFound());
            }

            // Build page title
            _pageTitleBuilder.AddSegment(S[user.DisplayName], int.MaxValue);

            // Breadcrumb
            _breadCrumbManager.Configure(builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Home", "Plato.Core")
                            .LocalNav()
                            ).Add(S["Users"], discuss => discuss
                                  .Action("Index", "Home", "Plato.Users")
                                  .LocalNav()
                                  ).Add(S[user.DisplayName], discuss => discuss
                                        .Action("Display", "Home", "Plato.Users", new RouteValueDictionary()
                {
                    ["opts.id"]    = user.Id,
                    ["opts.alias"] = user.Alias
                })
                                        .LocalNav()
                                        ).Add(S["Badges"]);
            });

            // Return view
            return(View((LayoutViewModel)await _userBadgeViewProvider.ProvideIndexAsync(new UserBadge()
            {
                UserId = user.Id
            }, this)));
        }
Beispiel #7
0
        public Task <IActionResult> Denied(string returnUrl = null)
        {
            // Persist returnUrl
            ViewData["ReturnUrl"] = returnUrl;

            Response.StatusCode = 401;

            // Build breadcrumb
            _breadCrumbManager.Configure(builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Home", "Plato.Core")
                            .LocalNav()
                            ).Add(S["Access Denied"]);
            });

            // Return view
            return(Task.FromResult((IActionResult)View()));
        }
Beispiel #8
0
        // --------------
        // Index
        // --------------

        public async Task <IActionResult> Index(TenantIndexOptions opts)
        {
            // Ensure we have permission
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageTenants))
            {
                return(Unauthorized());
            }

            // Ensure host
            if (!_shellSettings.IsDefaultShell())
            {
                return(Unauthorized());
            }

            if (opts == null)
            {
                opts = new TenantIndexOptions();
            }

            // Configure breadcrumb
            _breadCrumbManager.Configure(builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Admin", "Plato.Admin")
                            .LocalNav()
                            ).Add(S["Tenants"]);
            });

            // Build view model
            var viewModel = new TenantIndexViewModel()
            {
                Options = opts
            };

            // Add view model to context
            this.HttpContext.Items[typeof(TenantIndexViewModel)] = viewModel;

            // Return view
            return(View((LayoutViewModel)await _viewProvider.ProvideIndexAsync(new ShellSettings(), this)));
        }
Beispiel #9
0
        public async Task <IActionResult> Index()
        {
            // Ensure we have permission
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageEmailSettings))
            {
                return(Unauthorized());
            }

            _breadCrumbManager.Configure(builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Admin", "Plato.Admin")
                            .LocalNav()
                            ).Add(S["Settings"], channels => channels
                                  .Action("Index", "Admin", "Plato.Settings")
                                  .LocalNav()
                                  ).Add(S["Email"]);
            });

            // Return view
            return(View((LayoutViewModel)await _viewProvider.ProvideEditAsync(new EmailSettings(), this)));
        }
Beispiel #10
0
        public async Task <IActionResult> Index()
        {
            //var moderators = await _moderatorStore.GetCategorizedModeratorsAsync();

            //var claims = "";
            //if (moderators != null)
            //{
            //    foreach (var moderator in moderators)
            //    {
            //        claims += moderator.Key.DisplayName + "<br>";
            //        foreach (var channel in moderator.Value)
            //        {
            //            claims += channel.CategoryId + "<br>";
            //            foreach (var claim in channel.Claims)
            //            {
            //                claims += "- " + claim.ClaimType + " - " + claim.ClaimValue + "<br>";
            //            }
            //        }
            //    }

            //}

            //ViewData["claims"] = claims;

            _breadCrumbManager.Configure(builder =>
            {
                builder
                .Add(S["Home"], home => home
                     .Action("Index", "Admin", "Plato.Admin")
                     .LocalNav())
                .Add(S["Discuss"], discuss => discuss
                     .Action("Index", "Admin", "Plato.Discuss")
                     .LocalNav())
                .Add(S["Moderators"]);
            });

            return(View((LayoutViewModel)await _viewProvider.ProvideIndexAsync(new Moderator(), this)));
        }
Beispiel #11
0
        public async Task <IActionResult> Index()
        {
            // Breadcrumb
            _breadCrumbManager.Configure(builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Home", "Plato.Core")
                            .LocalNav()
                            ).Add(S["Badges"]);
            });

            // Return view
            return(View((LayoutViewModel)await _badgeViewProvider.ProvideIndexAsync(new Badge(), this)));
        }
Beispiel #12
0
        public async Task <IActionResult> Index()
        {
            _breadCrumbManager.Configure(builder =>
            {
                builder
                .Add(S["Home"], home => home
                     .Action("Index", "Admin", "Plato.Admin")
                     .LocalNav())
                .Add(S["Ideas"], articles => articles
                     .LocalNav());
            });

            // Return view
            return(View((LayoutViewModel)await _viewProvider.ProvideIndexAsync(new AdminIndex(), this)));
        }
Beispiel #13
0
        public async Task <IActionResult> Index()
        {
            _breadCrumbManager.Configure(builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Admin", "Plato.Admin")
                            .LocalNav()
                            ).Add(S["Settings"], channels => channels
                                  .Action("Index", "Admin", "Plato.Settings")
                                  .LocalNav()
                                  ).Add(S["Demo"]);
            });

            // Return view
            return(View((LayoutViewModel)await _viewProvider.ProvideEditAsync(new DemoSettings(), this)));
        }
Beispiel #14
0
        public async Task <IActionResult> Index()
        {
            // Build breadcrumb
            _breadCrumbManager.Configure(builder =>
            {
                builder
                .Add(S["Home"], home => home
                     .Action("Index", "Admin", "Plato.Admin")
                     .LocalNav())
                .Add(S["Reports"], home => home
                     .Action("Index", "Admin", "Plato.Reports")
                     .LocalNav())
                .Add(S["Top Pages"], reports => reports
                     .LocalNav());
            });

            // Return view
            return(View((LayoutViewModel)await _pageViewsViewProvider.ProvideIndexAsync(new FeatureViewIndex(), this)));
        }
Beispiel #15
0
        public async Task <IActionResult> Index()
        {
            //if (!await _authorizationService.AuthorizeAsync(User, PermissionsProvider.ManageRoles))
            //{
            //    return Unauthorized();
            //}

            _breadCrumbManager.Configure(builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Admin", "Plato.Admin")
                            .LocalNav()
                            ).Add(S["Settings"], channels => channels
                                  .Action("Index", "Admin", "Plato.Settings")
                                  .LocalNav()
                                  ).Add(S["SSL Settings"]);
            });


            return(View(await GetModel()));
        }
Beispiel #16
0
        public async Task <IActionResult> Index()
        {
            // Return Url for authentication purposes
            ViewData["ReturnUrl"] = _contextFacade.GetRouteUrl(new RouteValueDictionary()
            {
                ["area"]       = "Plato.Users.Badges",
                ["controller"] = "Home",
                ["action"]     = "Index"
            });

            // Breadcrumb
            _breadCrumbManager.Configure(builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Home", "Plato.Core")
                            .LocalNav()
                            ).Add(S["Badges"]);
            });

            // Return view
            return(View((LayoutViewModel)await _badgeViewProvider.ProvideIndexAsync(new Badge(), this)));
        }
Beispiel #17
0
        public async Task <IActionResult> Index(EntityIndexOptions opts, PagerOptions pager)
        {
            // Default options
            if (opts == null)
            {
                opts = new EntityIndexOptions();
            }

            // Default pager
            if (pager == null)
            {
                pager = new PagerOptions();
            }

            // Get user
            var user = await _platoUserStore.GetByIdAsync(opts.CreatedByUserId);

            // Ensure user exists
            if (user == null)
            {
                return(NotFound());
            }

            // Get default options
            var defaultViewOptions  = new EntityIndexOptions();
            var defaultPagerOptions = new PagerOptions();

            // Add non default route data for pagination purposes
            if (opts.Search != defaultViewOptions.Search)
            {
                this.RouteData.Values.Add("opts.search", opts.Search);
            }
            if (opts.Sort != defaultViewOptions.Sort)
            {
                this.RouteData.Values.Add("opts.sort", opts.Sort);
            }
            if (opts.Order != defaultViewOptions.Order)
            {
                this.RouteData.Values.Add("opts.order", opts.Order);
            }
            if (opts.Filter != defaultViewOptions.Filter)
            {
                this.RouteData.Values.Add("opts.filter", opts.Filter);
            }
            if (pager.Page != defaultPagerOptions.Page)
            {
                this.RouteData.Values.Add("pager.page", pager.Page);
            }
            if (pager.Size != defaultPagerOptions.Size)
            {
                this.RouteData.Values.Add("pager.size", pager.Size);
            }

            // Build view model
            var viewModel = await GetIndexViewModelAsync(opts, pager);

            // Add view model to context
            HttpContext.Items[typeof(EntityIndexViewModel <Article>)] = viewModel;

            // If we have a pager.page querystring value return paged results
            if (int.TryParse(HttpContext.Request.Query["pager.page"], out var page))
            {
                if (page > 0)
                {
                    return(View("GetArticles", viewModel));
                }
            }

            // Build page title
            _pageTitleBuilder
            .AddSegment(S["Users"])
            .AddSegment(S[user.DisplayName])
            .AddSegment(S["Articles"]);

            // Build breadcrumb
            _breadCrumbManager.Configure(builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Home", "Plato.Core")
                            .LocalNav()
                            ).Add(S["Users"], users => users
                                  .Action("Index", "Home", "Plato.Users")
                                  .LocalNav()
                                  ).Add(S[user.DisplayName], name => name
                                        .Action("Display", "Home", "Plato.Users", new RouteValueDictionary()
                {
                    ["opts.id"]    = user.Id,
                    ["opts.alias"] = user.Alias
                })
                                        .LocalNav()
                                        ).Add(S["Articles"]);
            });

            //// Return view
            return(View((LayoutViewModel)await _userViewProvider.ProvideDisplayAsync(new UserIndex()
            {
                Id = user.Id
            }, this)));
        }
Beispiel #18
0
        public async Task <IActionResult> Login(string returnUrl = null)
        {
            // Clear the existing external cookie to ensure a clean login process
            await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);

            // Build breadcrumb
            _breadCrumbManager.Configure(builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Home", "Plato.Core")
                            .LocalNav()
                            ).Add(S["Login"]);
            });

            // Persist returnUrl
            ViewData["ReturnUrl"] = returnUrl;

            // Return view
            return(View((LayoutViewModel)await _loginViewProvider.ProvideIndexAsync(new LoginPage(), this)));
        }
Beispiel #19
0
        // ---------------
        // Index
        // ---------------

        public async Task <IActionResult> Index(AttachmentIndexOptions opts, PagerOptions pager)
        {
            // Ensure we have permission
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageAttachmentSettings))
            {
                return(Unauthorized());
            }

            // Default options
            if (opts == null)
            {
                opts = new AttachmentIndexOptions();
            }

            // Default pager
            if (pager == null)
            {
                pager = new PagerOptions();
            }

            // Get default options
            var defaultViewOptions  = new AttachmentIndexOptions();
            var defaultPagerOptions = new PagerOptions();

            // Add non default route data for pagination purposes
            if (opts.Start != defaultViewOptions.Start)
            {
                this.RouteData.Values.Add("opts.start", opts.Start);
            }
            if (opts.End != defaultViewOptions.End)
            {
                this.RouteData.Values.Add("opts.end", opts.End);
            }
            if (opts.Search != defaultViewOptions.Search)
            {
                this.RouteData.Values.Add("opts.search", opts.Search);
            }
            if (opts.Sort != defaultViewOptions.Sort)
            {
                this.RouteData.Values.Add("opts.sort", opts.Sort);
            }
            if (opts.Order != defaultViewOptions.Order)
            {
                this.RouteData.Values.Add("opts.order", opts.Order);
            }
            if (pager.Page != defaultPagerOptions.Page)
            {
                this.RouteData.Values.Add("pager.page", pager.Page);
            }
            if (pager.Size != defaultPagerOptions.Size)
            {
                this.RouteData.Values.Add("pager.size", pager.Size);
            }

            // Build view model
            var viewModel = await GetIndexViewModelAsync(opts, pager);

            // Add view model to context
            HttpContext.Items[typeof(AttachmentIndexViewModel)] = viewModel;

            // If we have a pager.page querystring value return paged view
            if (int.TryParse(HttpContext.Request.Query["pager.page"], out var page))
            {
                if (page > 0)
                {
                    return(View("GetAttachments", viewModel));
                }
            }

            _breadCrumbManager.Configure(builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Admin", "Plato.Admin")
                            .LocalNav()
                            ).Add(S["Attachments"]);
            });

            // Return view
            return(View((LayoutViewModel)await _indexViewProvider.ProvideIndexAsync(new AttachmentIndex(), this)));
        }
Beispiel #20
0
        public async Task <IActionResult> Index(LabelIndexOptions opts, PagerOptions pager)
        {
            if (opts == null)
            {
                opts = new LabelIndexOptions();
            }

            if (pager == null)
            {
                pager = new PagerOptions();
            }

            // Get default options
            var defaultViewOptions  = new LabelIndexOptions();
            var defaultPagerOptions = new PagerOptions();

            // Add non default route data for pagination purposes
            if (opts.Search != defaultViewOptions.Search && !this.RouteData.Values.ContainsKey("opts.search"))
            {
                this.RouteData.Values.Add("opts.search", opts.Search);
            }
            if (opts.Sort != defaultViewOptions.Sort && !this.RouteData.Values.ContainsKey("opts.sort"))
            {
                this.RouteData.Values.Add("opts.sort", opts.Sort);
            }
            if (opts.Order != defaultViewOptions.Order && !this.RouteData.Values.ContainsKey("opts.order"))
            {
                this.RouteData.Values.Add("opts.order", opts.Order);
            }
            if (pager.Page != defaultPagerOptions.Page && !this.RouteData.Values.ContainsKey("pager.page"))
            {
                this.RouteData.Values.Add("pager.page", pager.Page);
            }
            if (pager.Size != defaultPagerOptions.Size && !this.RouteData.Values.ContainsKey("pager.size"))
            {
                this.RouteData.Values.Add("pager.size", pager.Size);
            }

            // Build view model
            var viewModel = await GetIndexViewModelAsync(opts, pager);

            // Add view options to context
            HttpContext.Items[typeof(LabelIndexViewModel <Label>)] = viewModel;

            // If we have a pager.page querystring value return paged results
            if (int.TryParse(HttpContext.Request.Query["pager.page"], out var page))
            {
                if (page > 0)
                {
                    return(View("GetLabels", viewModel));
                }
            }

            // Return Url for authentication purposes
            ViewData["ReturnUrl"] = _contextFacade.GetRouteUrl(new RouteValueDictionary()
            {
                ["area"]       = "Plato.Issues.Labels",
                ["controller"] = "Home",
                ["action"]     = "Index"
            });

            // Breadcrumb
            _breadCrumbManager.Configure(builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Home", "Plato.Core")
                            .LocalNav()
                            ).Add(S["Issues"], discuss => discuss
                                  .Action("Index", "Home", "Plato.Issues")
                                  .LocalNav()
                                  ).Add(S["Labels"]);
            });

            // Return view
            return(View((LayoutViewModel)await _labelViewProvider.ProvideIndexAsync(new Label(), this)));
        }
Beispiel #21
0
        public async Task <IActionResult> Index(ReportOptions opts, PagerOptions pager)
        {
            // Default options
            if (opts == null)
            {
                opts = new ReportOptions();
            }

            // Default pager
            if (pager == null)
            {
                pager = new PagerOptions();
            }


            // Get default options
            var defaultViewOptions  = new ReportOptions();
            var defaultPagerOptions = new PagerOptions();

            // Add non default route data for pagination purposes
            if (opts.Search != defaultViewOptions.Search)
            {
                this.RouteData.Values.Add("opts.search", opts.Search);
            }
            if (opts.Sort != defaultViewOptions.Sort)
            {
                this.RouteData.Values.Add("opts.sort", opts.Sort);
            }
            if (opts.Order != defaultViewOptions.Order)
            {
                this.RouteData.Values.Add("opts.order", opts.Order);
            }
            if (pager.Page != defaultPagerOptions.Page)
            {
                this.RouteData.Values.Add("pager.page", pager.Page);
            }
            if (pager.Size != defaultPagerOptions.Size)
            {
                this.RouteData.Values.Add("pager.size", pager.Size);
            }

            // Build view model
            var viewModel = await GetIndexViewModelAsync(opts, pager);

            // Add view model to context
            HttpContext.Items[typeof(ReportIndexViewModel <Metric>)] = viewModel;

            // Build breadcrumb
            _breadCrumbManager.Configure(builder =>
            {
                builder
                .Add(S["Home"], home => home
                     .Action("Index", "Admin", "Plato.Admin")
                     .LocalNav())
                .Add(S["Reports"], reports => reports
                     .LocalNav());
            });

            // Return view
            return(View((LayoutViewModel)await _reportViewProvider.ProvideIndexAsync(new ReportIndex(), this)));
        }
Beispiel #22
0
        public async Task <IActionResult> Index()
        {
            // Register bootstrap slider client script
            //var baseUri = await _contextFacade.GetBaseUrlAsync();
            //_scriptManager.RegisterScriptBlock(new ScriptBlock(new Dictionary<string, object>()
            //{
            //    ["src"] = "/plato.users.stopforumspam/content/js/bootstrap-slider.js"
            //}), ScriptSection.Footer);


            _breadCrumbManager.Configure(builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Admin", "Plato.Admin")
                            .LocalNav()
                            ).Add(S["Settings"], channels => channels
                                  .Action("Index", "Admin", "Plato.Settings")
                                  .LocalNav()
                                  ).Add(S["StopForumSpam"]);
            });

            // Get StopForumSpam settings
            var settings = await _spamSettingsStore.GetAsync();

            // Build view
            var result = await _viewProvider.ProvideEditAsync(new SpamSettings()
            {
                ApiKey         = settings?.ApiKey ?? "",
                SpamLevelId    = settings?.SpamLevelId ?? SpamLevelDefaults.SpamLevelId,
                SpamOperations = settings?.SpamOperations ?? null
            }, this);

            //var user = new User()
            //{
            //    UserName = "******",
            //    Email = "*****@*****.**",
            //    IpV4Address = "3.16.155.194"
            //};

            //// Configure checker
            //_spamProxy.Configure(o =>
            //{
            //    o.ApiKey = settings?.ApiKey ?? "";
            //});

            //// Get frequencies
            //var frequencies = await _spamProxy.GetAsync(user);

            //var sb = new StringBuilder();

            //sb
            //    .Append("Username: "******", ")
            //    .Append("Email: ")
            //    .Append(frequencies.Email.Count)
            //    .Append(", ")
            //    .Append("Ip: ")
            //    .Append(frequencies.IpAddress.Count)
            //    .Append(", ")
            //    .Append("success: ")
            //    .Append(frequencies.Success)
            //    .Append(", ");

            //ViewData["Test"] = sb.ToString();



            //Return view
            return(View(result));
        }
Beispiel #23
0
        // -----------------
        // Index
        // -----------------

        public async Task <IActionResult> Index(EntityIndexOptions opts, PagerOptions pager)
        {
            // Build options
            if (opts == null)
            {
                opts = new EntityIndexOptions();
            }

            // Build pager
            if (pager == null)
            {
                pager = new PagerOptions();
            }

            // Get default options
            var defaultViewOptions  = new EntityIndexOptions();
            var defaultPagerOptions = new PagerOptions();

            // Add non default route data for pagination purposes
            if (opts.Search != defaultViewOptions.Search)
            {
                this.RouteData.Values.Add("opts.search", opts.Search);
            }
            if (opts.Sort != defaultViewOptions.Sort)
            {
                this.RouteData.Values.Add("opts.sort", opts.Sort);
            }
            if (opts.Order != defaultViewOptions.Order)
            {
                this.RouteData.Values.Add("opts.order", opts.Order);
            }
            if (opts.Filter != defaultViewOptions.Filter)
            {
                this.RouteData.Values.Add("opts.filter", opts.Filter);
            }
            if (pager.Page != defaultPagerOptions.Page)
            {
                this.RouteData.Values.Add("pager.page", pager.Page);
            }
            if (pager.Size != defaultPagerOptions.Size)
            {
                this.RouteData.Values.Add("pager.size", pager.Size);
            }

            // Build view model
            var viewModel = await GetIndexViewModelAsync(null, opts, pager);

            // Add view model to context
            HttpContext.Items[typeof(EntityIndexViewModel <Doc>)] = viewModel;

            // If we have a pager.page query string value return paged results
            if (int.TryParse(HttpContext.Request.Query["pager.page"], out var page))
            {
                if (page > 0 && !pager.Enabled)
                {
                    return(View("GetDocs", viewModel));
                }
            }

            // Return Url for authentication purposes
            ViewData["ReturnUrl"] = _contextFacade.GetRouteUrl(new RouteValueDictionary()
            {
                ["area"]       = "Plato.Docs.Categories",
                ["controller"] = "Home",
                ["action"]     = "Index"
                                 //["opts.categoryId"] = category != null ? category.Id.ToString() : string.Empty,
                                 //["opts.alias"] = category != null ? category.Alias.ToString() : string.Empty
            });

            //// Build page title
            //if (category != null)
            //{
            //    _pageTitleBuilder.AddSegment(S[category.Name], int.MaxValue);
            //}

            // Build breadcrumb
            _breadCrumbManager.Configure(async builder =>
            {
                builder
                .Add(S["Home"], home => home
                     .Action("Index", "Home", "Plato.Core")
                     .LocalNav()
                     ).Add(S["Docs"], docs => docs
                           .Action("Index", "Home", "Plato.Docs")
                           .LocalNav()
                           ).Add(S["Categories"]);
            });

            // Return view
            return(View((LayoutViewModel)await _categoryViewProvider.ProvideIndexAsync(new Category(), this)));
        }
Beispiel #24
0
        public override async Task <IViewProviderResult> BuildDisplayAsync(Doc doc, IViewProviderContext updater)
        {
            // Ensure we explicitly set the featureId
            var feature = await _featureFacade.GetFeatureByIdAsync("Plato.Docs.Categories");

            if (feature == null)
            {
                return(default(IViewProviderResult));
            }

            // Override breadcrumb configuration within base controller
            IEnumerable <CategoryAdmin> parentCategories = null;

            if (doc.CategoryId > 0)
            {
                parentCategories = await _categoryStore.GetParentsByIdAsync(doc.CategoryId);
            }

            // Get parent entities
            var parentEntities = await _entityStore.GetParentsByIdAsync(doc.Id);

            // Build breadcrumb
            _breadCrumbManager.Configure(builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Home", "Plato.Core")
                            .LocalNav()
                            ).Add(S["Docs"], home => home
                                  .Action("Index", "Home", "Plato.Docs")
                                  .LocalNav()
                                  );

                // Parent categories
                if (parentCategories != null)
                {
                    builder.Add(S["Categories"], c => c
                                .Action("Index", "Home", "Plato.Docs.Categories", new RouteValueDictionary()
                    {
                        ["opts.categoryId"] = null,
                        ["opts.alias"]      = null
                    })
                                .LocalNav()
                                );
                    foreach (var parent in parentCategories)
                    {
                        builder.Add(S[parent.Name], channel => channel
                                    .Action("Index", "Home", "Plato.Docs.Categories", new RouteValueDictionary
                        {
                            ["opts.categoryId"] = parent.Id,
                            ["opts.alias"]      = parent.Alias,
                        })
                                    .LocalNav()
                                    );
                    }
                }

                // Parent entities
                if (parentEntities != null)
                {
                    foreach (var parent in parentEntities)
                    {
                        if (parent.Id != doc.Id)
                        {
                            builder.Add(S[parent.Title], channel => channel
                                        .Action("Display", "Home", "Plato.Docs", new RouteValueDictionary
                            {
                                ["opts.id"]    = parent.Id,
                                ["opts.alias"] = parent.Alias,
                            })
                                        .LocalNav()
                                        );
                        }
                    }
                }

                builder.Add(S[doc.Title]);
            });

            // Build view
            var categoryIndexViewModel = new CategoryIndexViewModel()
            {
                Options = new CategoryIndexOptions()
                {
                    FeatureId  = feature.Id,
                    CategoryId = doc.CategoryId
                }
            };

            return(Views(
                       View <CategoryIndexViewModel>("Doc.Categories.Index.Sidebar", model => categoryIndexViewModel).Zone("sidebar").Order(int.MinValue + 10)
                       ));
        }
Beispiel #25
0
        public async Task <IActionResult> Index(EntityIndexOptions opts, PagerOptions pager)
        {
            // Build options
            if (opts == null)
            {
                opts = new EntityIndexOptions();
            }

            // Build pager
            if (pager == null)
            {
                pager = new PagerOptions();
            }

            // Get category
            var category = await _categoryStore.GetByIdAsync(opts.CategoryId);

            // If supplied ensure category exists
            if (category == null && opts.CategoryId > 0)
            {
                return(NotFound());
            }

            // Get default options
            var defaultViewOptions  = new EntityIndexOptions();
            var defaultPagerOptions = new PagerOptions();

            // Add non default route data for pagination purposes
            if (opts.Search != defaultViewOptions.Search)
            {
                this.RouteData.Values.Add("opts.search", opts.Search);
            }
            if (opts.Sort != defaultViewOptions.Sort)
            {
                this.RouteData.Values.Add("opts.sort", opts.Sort);
            }
            if (opts.Order != defaultViewOptions.Order)
            {
                this.RouteData.Values.Add("opts.order", opts.Order);
            }
            if (opts.Filter != defaultViewOptions.Filter)
            {
                this.RouteData.Values.Add("opts.filter", opts.Filter);
            }
            if (pager.Page != defaultPagerOptions.Page)
            {
                this.RouteData.Values.Add("pager.page", pager.Page);
            }
            if (pager.Size != defaultPagerOptions.Size)
            {
                this.RouteData.Values.Add("pager.size", pager.Size);
            }

            // Build view model
            var viewModel = await GetIndexViewModelAsync(category, opts, pager);

            // Add view model to context
            HttpContext.Items[typeof(EntityIndexViewModel <Topic>)] = viewModel;

            // If we have a pager.page querystring value return paged results
            if (int.TryParse(HttpContext.Request.Query["pager.page"], out var page))
            {
                if (page > 0 && !pager.Enabled)
                {
                    return(View("GetTopics", viewModel));
                }
            }

            // Return Url for authentication purposes
            ViewData["ReturnUrl"] = _contextFacade.GetRouteUrl(new RouteValueDictionary()
            {
                ["area"]            = "Plato.Discuss.Categories",
                ["controller"]      = "Home",
                ["action"]          = "Index",
                ["opts.categoryId"] = category != null ? category.Id.ToString() : "",
                ["opts.alias"]      = category != null ? category.Alias.ToString() : ""
            });

            // Build page title
            if (category != null)
            {
                _pageTitleBuilder.AddSegment(S[category.Name], int.MaxValue);
            }

            // Build breadcrumb
            _breadCrumbManager.Configure(async builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Home", "Plato.Core")
                            .LocalNav()
                            ).Add(S["Discuss"], home => home
                                  .Action("Index", "Home", "Plato.Discuss")
                                  .LocalNav()
                                  );

                // Build breadcrumb
                var parents = category != null
                    ? await _categoryStore.GetParentsByIdAsync(category.Id)
                    : null;
                if (parents == null)
                {
                    builder.Add(S["Categories"]);
                }
                else
                {
                    builder.Add(S["Categories"], c => c
                                .Action("Index", "Home", "Plato.Discuss.Categories", new RouteValueDictionary()
                    {
                        ["opts.categoryId"] = null,
                        ["opts.alias"]      = null
                    })
                                .LocalNav()
                                );

                    foreach (var parent in parents)
                    {
                        if (parent.Id != category.Id)
                        {
                            builder.Add(S[parent.Name], channel => channel
                                        .Action("Index", "Home", "Plato.Discuss.Categories", new RouteValueDictionary
                            {
                                ["opts.categoryId"] = parent.Id,
                                ["opts.alias"]      = parent.Alias,
                            })
                                        .LocalNav()
                                        );
                        }
                        else
                        {
                            builder.Add(S[parent.Name]);
                        }
                    }
                }
            });

            // Return view
            return(View((LayoutViewModel)await _categoryViewProvider.ProvideIndexAsync(category, this)));
        }
Beispiel #26
0
        public override async Task <IViewProviderResult> BuildEditAsync(Answer viewModel, IViewProviderContext context)
        {
            var topic = await _entityStore.GetByIdAsync(viewModel.EntityId);

            if (topic == null)
            {
                return(default(IViewProviderResult));
            }

            // Override breadcrumb configuration within base controller
            IEnumerable <CategoryAdmin> parents = null;

            if (topic.CategoryId > 0)
            {
                parents = await _channelStore.GetParentsByIdAsync(topic.CategoryId);
            }

            _breadCrumbManager.Configure(builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Home", "Plato.Core")
                            .LocalNav()
                            ).Add(S["Questions"], home => home
                                  .Action("Index", "Home", "Plato.Questions")
                                  .LocalNav()
                                  );

                if (parents != null)
                {
                    builder.Add(S["Categories"], categories => categories
                                .Action("Index", "Home", "Plato.Questions.Categories", new RouteValueDictionary()
                    {
                        ["opts.id"]    = "",
                        ["opts.alias"] = ""
                    })
                                .LocalNav()
                                );
                    foreach (var parent in parents)
                    {
                        builder.Add(S[parent.Name], channel => channel
                                    .Action("Index", "Home", "Plato.Questions.Categories", new RouteValueDictionary
                        {
                            ["opts.id"]    = parent.Id,
                            ["opts.alias"] = parent.Alias,
                        })
                                    .LocalNav()
                                    );
                    }
                }

                builder.Add(S[topic.Title], t => t
                            .Action("Display", "Home", "Plato.Questions", new RouteValueDictionary
                {
                    ["opts.id"]    = topic.Id,
                    ["opts.alias"] = topic.Alias,
                })
                            .LocalNav()
                            );

                builder.Add(S["Edit Answer"]);
            });

            return(default(IViewProviderResult));
        }
Beispiel #27
0
        // --------------
        // Index
        // --------------

        public async Task <IActionResult> Index(int id)
        {
            //if (!await _authorizationService.AuthorizeAsync(User, PermissionsProvider.ManageRoles))
            //{
            //    return Unauthorized();
            //}

            IEnumerable <CategoryAdmin> parents = null;

            if (id > 0)
            {
                parents = await _categoryStore.GetParentsByIdAsync(id);
            }

            _breadCrumbManager.Configure(builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Admin", "Plato.Admin")
                            .LocalNav())
                .Add(S["Docs"], docs => docs
                     .Action("Index", "Admin", "Plato.Docs")
                     .LocalNav());

                if (parents == null)
                {
                    builder.Add(S["Categories"]);
                }
                else
                {
                    builder.Add(S["Categories"], c => c
                                .Action("Index", "Admin", "Plato.Docs.Categories", new RouteValueDictionary {
                        ["Id"] = 0
                    })
                                .LocalNav()
                                );
                    foreach (var parent in parents)
                    {
                        if (parent.Id != id)
                        {
                            builder.Add(S[parent.Name], channel => channel
                                        .Action("Index", "Admin", "Plato.Docs.Categories", new RouteValueDictionary {
                                ["Id"] = parent.Id
                            })
                                        .LocalNav()
                                        );
                        }
                        else
                        {
                            builder.Add(S[parent.Name]);
                        }
                    }
                }
            });

            // Get optional current category
            CategoryAdmin currentCategory = null;

            if (id > 0)
            {
                currentCategory = await _categoryStore.GetByIdAsync(id);
            }

            // Return view
            return(View((LayoutViewModel)await _viewProvider.ProvideIndexAsync(currentCategory ?? new CategoryAdmin(), this)));
        }
Beispiel #28
0
        // --------------
        // Manage Users
        // --------------

        public async Task <IActionResult> Index(int offset, UserIndexOptions opts, PagerOptions pager)
        {
            // Ensure we have permission
            if (!await _authorizationService.AuthorizeAsync(HttpContext.User,
                                                            Permissions.ManageUsers))
            {
                return(Unauthorized());
            }

            // default options
            if (opts == null)
            {
                opts = new UserIndexOptions();
            }

            // default pager
            if (pager == null)
            {
                pager = new PagerOptions();
            }

            // Set pager call back Url
            pager.Url = _contextFacade.GetRouteUrl(pager.Route(RouteData));

            // Get default options
            var defaultViewOptions  = new UserIndexOptions();
            var defaultPagerOptions = new PagerOptions();

            // Add non default route data for pagination purposes
            if (opts.Search != defaultViewOptions.Search)
            {
                RouteData.Values.Add("opts.search", opts.Search);
            }
            if (opts.Sort != defaultViewOptions.Sort)
            {
                RouteData.Values.Add("opts.sort", opts.Sort);
            }
            if (opts.Order != defaultViewOptions.Order)
            {
                RouteData.Values.Add("opts.order", opts.Order);
            }
            if (pager.Page != defaultPagerOptions.Page)
            {
                RouteData.Values.Add("pager.page", pager.Page);
            }
            if (pager.Size != defaultPagerOptions.Size)
            {
                RouteData.Values.Add("pager.size", pager.Size);
            }

            // Enable edit options for admin view
            opts.EnableEdit = true;

            var viewModel = new UserIndexViewModel()
            {
                Options = opts,
                Pager   = pager
            };

            // Add view options to context for use within view adapters
            HttpContext.Items[typeof(UserIndexViewModel)] = viewModel;

            // If we have a pager.page querystring value return paged results
            if (int.TryParse(HttpContext.Request.Query["pager.page"], out var page))
            {
                if (page > 0)
                {
                    return(View("GetUsers", viewModel));
                }
            }

            // Build breadcrumb
            _breadCrumbManager.Configure(builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Admin", "Plato.Admin")
                            .LocalNav()
                            ).Add(S["Users"]);
            });

            // Return view
            return(View((LayoutViewModel)await _viewProvider.ProvideIndexAsync(new User(), this)));
        }
Beispiel #29
0
        // ------------
        // Index
        // ------------

        public async Task <IActionResult> Index(TagIndexOptions opts, PagerOptions pager)
        {
            //if (!await _authorizationService.AuthorizeAsync(User, PermissionsProvider.ManageRoles))
            //{
            //    return Unauthorized();
            //}

            if (opts == null)
            {
                opts = new TagIndexOptions();
            }

            if (pager == null)
            {
                pager = new PagerOptions();
            }

            // Get default options
            var defaultViewOptions  = new TagIndexOptions();
            var defaultPagerOptions = new PagerOptions();

            // Add non default route data for pagination purposes
            if (opts.Search != defaultViewOptions.Search)
            {
                this.RouteData.Values.Add("opts.search", opts.Search);
            }
            if (opts.Sort != defaultViewOptions.Sort)
            {
                this.RouteData.Values.Add("opts.sort", opts.Sort);
            }
            if (opts.Order != defaultViewOptions.Order)
            {
                this.RouteData.Values.Add("opts.order", opts.Order);
            }
            if (pager.Page != defaultPagerOptions.Page)
            {
                this.RouteData.Values.Add("pager.page", pager.Page);
            }
            if (pager.Size != defaultPagerOptions.Size)
            {
                this.RouteData.Values.Add("pager.size", pager.Size);
            }

            // Build view model
            var viewModel = await GetIndexViewModelAsync(opts, pager);

            // Add view model to context
            HttpContext.Items[typeof(TagIndexViewModel <Tag>)] = viewModel;

            // If we have a pager.page querystring value return paged results
            if (int.TryParse(HttpContext.Request.Query["pager.page"], out var page))
            {
                if (page > 0)
                {
                    return(View("GetTags", viewModel));
                }
            }

            // Breadcrumb
            _breadCrumbManager.Configure(builder =>
            {
                builder
                .Add(S["Home"], home => home
                     .Action("Index", "Admin", "Plato.Admin")
                     .LocalNav())
                .Add(S["Articles"], discuss => discuss
                     .Action("Index", "Admin", "Plato.Articles")
                     .LocalNav())
                .Add(S["Tags"]);
            });

            // Return view
            return(View((LayoutViewModel)await _viewProvider.ProvideIndexAsync(new Tag(), this)));
        }
Beispiel #30
0
        public async Task <IActionResult> Index()
        {
            // We need to be authenticated to access notification settings
            var user = await _contextFacade.GetAuthenticatedUserAsync();

            if (user == null)
            {
                return(NotFound());
            }

            // Breadcrumb
            _breadCrumbManager.Configure(builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Home", "Plato.Core")
                            .LocalNav()
                            ).Add(S["Your Account"]);
            });

            // Get saved notification types
            var userNotificationSettings = user.GetOrCreate <UserNotificationTypes>();

            // Get all notification types to enable by default
            var defaultNotificationTypes     = _notificationTypeManager.GetDefaultNotificationTypes(user.RoleNames);
            var defaultUserNotificationTypes = new List <UserNotificationType>();

            foreach (var notificationType in defaultNotificationTypes)
            {
                defaultUserNotificationTypes.Add(new UserNotificationType(notificationType.Name));
            }

            // Holds our list of enabled notification types
            var enabledNotificationTypes = new List <UserNotificationType>();

            // We have previously saved settings
            if (userNotificationSettings.NotificationTypes != null)
            {
                // Add all user specified notification types
                enabledNotificationTypes.AddRange(userNotificationSettings.NotificationTypes);

                // Loop through all default notification types to see if the user has saved
                // a value (on or off) for that notification type, if no value have been previously saved
                // ensure the default notification type is added to our list of enabled notification types
                foreach (var userNotification in defaultUserNotificationTypes)
                {
                    var foundNotification = enabledNotificationTypes.FirstOrDefault(n =>
                                                                                    n.Name.Equals(userNotification.Name, StringComparison.OrdinalIgnoreCase));
                    if (foundNotification == null)
                    {
                        enabledNotificationTypes.Add(userNotification);
                    }
                }
            }
            else
            {
                // If we don't have any notification types ensure we enable all by default
                enabledNotificationTypes.AddRange(defaultUserNotificationTypes);
            }

            var editProfileViewModel = new EditNotificationsViewModel()
            {
                Id = user.Id
            };

            // Return view
            return(View((LayoutViewModel)await _editProfileViewProvider.ProvideEditAsync(editProfileViewModel, this)));
        }