Skip to content

Commit

Permalink
feat: option to report blocked registrations to sfs (#5)
Browse files Browse the repository at this point in the history
* feat: option to report blocked registrations to sfs

* Apply fixes from StyleCI

---------

Co-authored-by: StyleCI Bot <bot@styleci.io>
  • Loading branch information
imorland and StyleCIBot committed Dec 8, 2023
1 parent a5a6c54 commit 933f279
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
3 changes: 2 additions & 1 deletion extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
->default('fof-anti-spam.actions.deleteUser', false)
->default('fof-anti-spam.actions.deletePosts', false)
->default('fof-anti-spam.actions.deleteDiscussions', false)
->default('fof-anti-spam.reportToStopForumSpam', true),
->default('fof-anti-spam.reportToStopForumSpam', true)
->default('fof-anti-spam.report_blocked_registrations', true),

(new Extend\ServiceProvider())
->register(Providers\SfsProvider::class),
Expand Down
6 changes: 6 additions & 0 deletions js/src/admin/components/AntiSpamSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ export default class AntiSpamSettingsPage extends ExtensionPage {
label: app.translator.trans('fof-anti-spam.admin.settings.stopforumspam.sfs_lookup_label'),
help: app.translator.trans('fof-anti-spam.admin.settings.stopforumspam.sfs_lookup_help'),
})}
{this.buildSettingComponent({
type: 'boolean',
setting: 'fof-anti-spam.report_blocked_registrations',
label: app.translator.trans('fof-anti-spam.admin.settings.stopforumspam.report_blocked_registrations_label'),
help: app.translator.trans('fof-anti-spam.admin.settings.stopforumspam.report_blocked_registrations_help'),
})}
{this.buildSettingComponent({
type: 'boolean',
setting: 'fof-anti-spam.username',
Expand Down
3 changes: 3 additions & 0 deletions locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ fof-anti-spam:

sfs_lookup_label: Lookup registrations
sfs_lookup_help: If enabled, we will check the StopForumSpam database when a new user registers on your forum. If the user is found (username, IP address, email) and that data point is enabled along with the SFS confidence level reaching your defined level, they will be prevented from completing their registration.

report_blocked_registrations_label: Report blocked registrations
report_blocked_registrations_help: When a registration is blocked by the Lookup Registrations feature, we will report the attempt back to StopForumSpam, so that the spammers activity can be better confirmed. Requires a StopForumSpam API key to be set (see below).
blocked_registrations:
button: Blocked Registrations
title: Blocked Registrations
Expand Down
46 changes: 46 additions & 0 deletions src/Listener/ReportBlockedRegistration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/*
* This file is part of fof/anti-spam.
*
* Copyright (c) FriendsOfFlarum.
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

namespace FoF\AntiSpam\Listener;

use Flarum\Settings\SettingsRepositoryInterface;
use FoF\AntiSpam\Event\RegistrationWasBlocked;
use FoF\AntiSpam\Job\ReportSpammerJob;
use FoF\AntiSpam\StopForumSpam;
use Illuminate\Contracts\Queue\Queue;

class ReportBlockedRegistration
{
protected $settings;
protected $sfs;
protected $queue;

public function __construct(SettingsRepositoryInterface $settings, StopForumSpam $sfs, Queue $queue)
{
$this->settings = $settings;
$this->sfs = $sfs;
$this->queue = $queue;
}

public function handle(RegistrationWasBlocked $event): void
{
if ($this->settings->get('fof-anti-spam.report_blocked_registrations') && $this->sfs->isEnabled()) {
$blocked = $event->blocked;
$this->queue->push(
new ReportSpammerJob(
$blocked->username,
$blocked->email,
$blocked->ip
)
);
}
}
}

0 comments on commit 933f279

Please sign in to comment.