From 7921d128e4bd42d49a43fa45dee834b96c8cac58 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 18 Dec 2015 07:31:36 +0100 Subject: [PATCH] Cleanup routine that checks for blocked domains. --- app/Http/Controllers/Auth/AuthController.php | 40 ++++++++++++++++---- config/mail.php | 2 +- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/Auth/AuthController.php b/app/Http/Controllers/Auth/AuthController.php index a41465ac24..d7620f07b0 100644 --- a/app/Http/Controllers/Auth/AuthController.php +++ b/app/Http/Controllers/Auth/AuthController.php @@ -1,6 +1,7 @@ isBlockedDomain($data['email'])) { $validator->getMessageBag()->add('email', trans('validation.invalid_domain')); $this->throwValidationException( $request, $validator @@ -178,8 +176,8 @@ class AuthController extends Controller // get the email address if (Auth::user() instanceof User) { - $email = Auth::user()->email; - $address = route('index'); + $email = Auth::user()->email; + $address = route('index'); $ipAddress = $request->ip(); // send email. try { @@ -188,7 +186,7 @@ class AuthController extends Controller $message->to($email, $email)->subject('Welcome to Firefly III! '); } ); - } catch(\Swift_TransportException $e) { + } catch (\Swift_TransportException $e) { Log::error($e->getMessage()); } @@ -213,6 +211,32 @@ class AuthController extends Controller // @codeCoverageIgnoreEnd } + /** + * @return array + */ + protected function getBlockedDomains() { + $set = Config::get('mail.blocked_domains'); + $domains = []; + foreach($set as $entry) { + $domain = trim($entry); + if(strlen($domain) > 0) { + $domains[] = $domain; + } + } + return $domains; + } + + protected function isBlockedDomain($email) + { + $parts = explode('@', $email); + $blocked = $this->getBlockedDomains(); + + if (isset($parts[1]) && in_array($parts[1], $blocked)) { + return true; + } + return false; + } + /** * Get a validator for an incoming registration request. * diff --git a/config/mail.php b/config/mail.php index 6a63081d1a..a89c2eaad6 100644 --- a/config/mail.php +++ b/config/mail.php @@ -15,7 +15,7 @@ return [ | */ - 'blocked_domains' => ['trbvm.com', 'example.com','mailinator.com'], + 'blocked_domains' => explode(',', env('BLOCKED_DOMAINS')), 'driver' => env('EMAIL_DRIVER', 'smtp'), /*