Cleanup routine that checks for blocked domains.

This commit is contained in:
James Cole 2015-12-18 07:31:36 +01:00
parent d7e838701a
commit 7921d128e4
2 changed files with 33 additions and 9 deletions

View File

@ -1,6 +1,7 @@
<?php namespace FireflyIII\Http\Controllers\Auth;
use Auth;
use Config;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Role;
use FireflyIII\User;
@ -8,13 +9,12 @@ use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Http\Request;
use Illuminate\Mail\Message;
use Log;
use Mail;
use Request as Rq;
use Session;
use Twig;
use Validator;
use Log;
use Config;
/**
* Class AuthController
@ -165,9 +165,7 @@ class AuthController extends Controller
$data['password'] = bcrypt($data['password']);
// is user email domain blocked?
$parts = explode('@', $data['email']);
if (isset($parts[1]) && in_array($parts[1], Config::get('mail.blocked_domains'))) {
if ($this->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.
*

View File

@ -15,7 +15,7 @@ return [
|
*/
'blocked_domains' => ['trbvm.com', 'example.com','mailinator.com'],
'blocked_domains' => explode(',', env('BLOCKED_DOMAINS')),
'driver' => env('EMAIL_DRIVER', 'smtp'),
/*