Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: option to report blocked registrations to sfs #5

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
)
);
}
}
}