mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-16 17:33:45 +00:00
Cleanup routine that checks for blocked domains.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
<?php namespace FireflyIII\Http\Controllers\Auth;
|
<?php namespace FireflyIII\Http\Controllers\Auth;
|
||||||
|
|
||||||
use Auth;
|
use Auth;
|
||||||
|
use Config;
|
||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
use FireflyIII\Models\Role;
|
use FireflyIII\Models\Role;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
@@ -8,13 +9,12 @@ use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
|
|||||||
use Illuminate\Foundation\Auth\ThrottlesLogins;
|
use Illuminate\Foundation\Auth\ThrottlesLogins;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Mail\Message;
|
use Illuminate\Mail\Message;
|
||||||
|
use Log;
|
||||||
use Mail;
|
use Mail;
|
||||||
use Request as Rq;
|
use Request as Rq;
|
||||||
use Session;
|
use Session;
|
||||||
use Twig;
|
use Twig;
|
||||||
use Validator;
|
use Validator;
|
||||||
use Log;
|
|
||||||
use Config;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class AuthController
|
* Class AuthController
|
||||||
@@ -165,9 +165,7 @@ class AuthController extends Controller
|
|||||||
$data['password'] = bcrypt($data['password']);
|
$data['password'] = bcrypt($data['password']);
|
||||||
|
|
||||||
// is user email domain blocked?
|
// is user email domain blocked?
|
||||||
$parts = explode('@', $data['email']);
|
if ($this->isBlockedDomain($data['email'])) {
|
||||||
if (isset($parts[1]) && in_array($parts[1], Config::get('mail.blocked_domains'))) {
|
|
||||||
|
|
||||||
$validator->getMessageBag()->add('email', trans('validation.invalid_domain'));
|
$validator->getMessageBag()->add('email', trans('validation.invalid_domain'));
|
||||||
$this->throwValidationException(
|
$this->throwValidationException(
|
||||||
$request, $validator
|
$request, $validator
|
||||||
@@ -178,8 +176,8 @@ class AuthController extends Controller
|
|||||||
|
|
||||||
// get the email address
|
// get the email address
|
||||||
if (Auth::user() instanceof User) {
|
if (Auth::user() instanceof User) {
|
||||||
$email = Auth::user()->email;
|
$email = Auth::user()->email;
|
||||||
$address = route('index');
|
$address = route('index');
|
||||||
$ipAddress = $request->ip();
|
$ipAddress = $request->ip();
|
||||||
// send email.
|
// send email.
|
||||||
try {
|
try {
|
||||||
@@ -188,7 +186,7 @@ class AuthController extends Controller
|
|||||||
$message->to($email, $email)->subject('Welcome to Firefly III! ');
|
$message->to($email, $email)->subject('Welcome to Firefly III! ');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} catch(\Swift_TransportException $e) {
|
} catch (\Swift_TransportException $e) {
|
||||||
Log::error($e->getMessage());
|
Log::error($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,6 +211,32 @@ class AuthController extends Controller
|
|||||||
// @codeCoverageIgnoreEnd
|
// @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.
|
* Get a validator for an incoming registration request.
|
||||||
*
|
*
|
||||||
|
@@ -15,7 +15,7 @@ return [
|
|||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'blocked_domains' => ['trbvm.com', 'example.com','mailinator.com'],
|
'blocked_domains' => explode(',', env('BLOCKED_DOMAINS')),
|
||||||
'driver' => env('EMAIL_DRIVER', 'smtp'),
|
'driver' => env('EMAIL_DRIVER', 'smtp'),
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Reference in New Issue
Block a user