Skip to content

Commit

Permalink
Add composer meta, use events extender (#3)
Browse files Browse the repository at this point in the history
* Update composer meta, use Event extender

* Reduce core constraint back to 14 as we don't need to require 15 here
  • Loading branch information
imorland authored Dec 14, 2020
1 parent c5efece commit 048d8ac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
13 changes: 13 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@
],
"type": "flarum-extension",
"license": "MIT",
"support": {
"issues": "https://github.com/FriendsOfFlarum/disposabile-emails/issues",
"source": "https://github.com/FriendsOfFlarum/disposable-emails",
"forum": "https://discuss.flarum.org/d/21894"
},
"homepage": "https://friendsofflarum.org",
"funding": [
{
"type": "website",
"url": "https://opencollective.com/fof/donate"
}
],
"require": {
"flarum/core": "^0.1.0-beta.14",
"fgribreau/mailchecker": "^3.3.17"
Expand All @@ -25,6 +37,7 @@
"extra": {
"flarum-extension": {
"title": "FoF Disposable Emails",
"category": "moderation",
"icon": {
"name": "fas fa-user-times",
"backgroundColor": "#e74c3c",
Expand Down
9 changes: 4 additions & 5 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,20 @@
use Flarum\Extend;
use Flarum\Foundation\ValidationException;
use Flarum\User\Event\Saving;
use Illuminate\Events\Dispatcher;
use Illuminate\Support\Arr;
use MailChecker;

return [
new Extend\Locales(__DIR__.'/locale'),
function (Dispatcher $events) {
$events->listen(Saving::class, function (Saving $event) {

(new Extend\Event())
->listen(Saving::class, function (Saving $event) {
$email = Arr::get($event->data, 'attributes.email');

if ($email !== null && !MailChecker::isValid($email)) {
throw new ValidationException([
app('translator')->trans('fof-email-checker.error.disposable_email_message'),
]);
}
});
},
}),
];

0 comments on commit 048d8ac

Please sign in to comment.