Esempio n. 1
0
        public async Task <ISpamCheckerResult> CheckAsync(IUser user)
        {
            // Get StopForumSpam settings
            var settings = await _spamSettingsStore.GetAsync();

            // Identify which flags to check
            var level = settings != null
                ? SpamLevelDefaults.SpamLevels.FirstOrDefault(l => l.Id == settings.SpamLevelId)
                : SpamLevelDefaults.SpamLevels.FirstOrDefault(l => l.Id == SpamLevelDefaults.SpamLevelId);

            if (level == null)
            {
                throw new ArgumentNullException(nameof(level));
            }

            // Return result
            return(await CheckInternalAsync(user, settings?.ApiKey ?? string.Empty, level.Flags));
        }
Esempio n. 2
0
        async Task <ISpamOperation> GetPersistedOperation(ISpamOperation operation)
        {
            // If the spam operation has been persisted within the database ensure we use
            // the persisted version from the database as opposed to the default operation
            var settings = await _spamSettingsStore.GetAsync();

            var existingOperation = settings?.SpamOperations?.FirstOrDefault(o => o.Name.Equals(operation.Name));

            if (existingOperation != null)
            {
                return(existingOperation);
            }

            return(operation);
        }
Esempio n. 3
0
        async Task <string> GetStopForumSpamApiKeyAsync()
        {
            // Get spam settings
            var settings = await _spamSettingsStore.GetAsync();

            // Ensure we have settings
            if (settings == null)
            {
                throw new Exception("No spam settings have been configured!");
            }

            // Ensure we have an api key
            if (String.IsNullOrEmpty(settings.ApiKey))
            {
                throw new Exception("A StopForumSpam API key is required!");
            }

            return(settings.ApiKey);
        }
Esempio n. 4
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));
        }