Skip to content

Commit

Permalink
Merge pull request #1350 from HDInnovations/analysis-YjKodY
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
HDVinnie authored May 21, 2020
2 parents 163bedd + bf08470 commit a060c5d
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 28 deletions.
4 changes: 3 additions & 1 deletion app/Console/Commands/EmailBlacklistUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ public function handle()

if ($count === false) {
$this->warn('No domains retrieved. Check the email.blacklist.source key for validation config.');

return;
}
if ($count === 0) {
$this->info('Advice: Blacklist was retrieved from source but 0 domains were listed.');

return;
}
$this->info("{$count} domains retrieved. Cache updated. You are good to go.");
}
}
}
2 changes: 1 addition & 1 deletion app/Helpers/EmailBlacklistUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ public static function update()

return $count;
}
}
}
10 changes: 5 additions & 5 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ public function register(Request $request, $code = null)
$v = validator($request->all(), [
'username' => 'required|alpha_dash|string|between:3,25|unique:users',
'password' => 'required|string|between:8,16',
'email' => 'required|string|email|max:70|blacklist|unique:users'
'email' => 'required|string|email|max:70|blacklist|unique:users',
]);
} else {
$v = validator($request->all(), [
'username' => 'required|alpha_dash|string|between:3,25|unique:users',
'password' => 'required|string|between:8,16',
'email' => 'required|string|email|max:70|blacklist|unique:users',
'email' => 'required|string|email|max:70|blacklist|unique:users',
'captcha' => 'hiddencaptcha',
]);
}
Expand All @@ -112,14 +112,14 @@ public function register(Request $request, $code = null)
$v = validator($request->all(), [
'username' => 'required|alpha_dash|string|between:3,25|unique:users',
'password' => 'required|string|between:8,16',
'email' => 'required|string|email|max:70|unique:users'
'email' => 'required|string|email|max:70|unique:users',
]);
} else {
$v = validator($request->all(), [
'username' => 'required|alpha_dash|string|between:3,25|unique:users',
'password' => 'required|string|between:6,16',
'email' => 'required|string|email|max:70|unique:users',
'captcha' => 'hiddencaptcha',
'email' => 'required|string|email|max:70|unique:users',
'captcha' => 'hiddencaptcha',
]);
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Staff/ApplicationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ public function approve(Request $request, $id)

if (config('email-blacklist.enabled') == true) {
$v = validator($request->all(), [
'email' => 'required|string|email|max:70|blacklist|unique:users|unique:invites',
'email' => 'required|string|email|max:70|blacklist|unique:users|unique:invites',
'approve' => 'required',
]);
} else {
$v = validator($request->all(), [
'email' => 'required|string|email|max:70|unique:users|unique:invites',
'email' => 'required|string|email|max:70|unique:users|unique:invites',
'approve' => 'required',
]);
}
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,11 @@ protected function changeEmail(Request $request, $username)

if (config('email-blacklist.enabled') == true) {
$v = validator($request->all(), [
'email' => 'required|string|email|max:70|blacklist|unique:users'
'email' => 'required|string|email|max:70|blacklist|unique:users',
]);
} else {
$v = validator($request->all(), [
'email' => 'required|string|email|max:70|unique:users'
'email' => 'required|string|email|max:70|unique:users',
]);
}

Expand Down
6 changes: 3 additions & 3 deletions app/Providers/EmailBlacklistServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public function register()
public function boot()
{
// Add custom validation rules
Validator::extend("blacklist", "App\Validators\EmailBlacklistValidator@validate");
Validator::extend('blacklist', "App\Validators\EmailBlacklistValidator@validate");

// Add custom validation messages
Validator::replacer("blacklist", "App\Validators\EmailBlacklistValidator@message");
Validator::replacer('blacklist', "App\Validators\EmailBlacklistValidator@message");
}
}
}
22 changes: 13 additions & 9 deletions app/Validators/EmailValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@
use Illuminate\Support\Str;
use Psr\SimpleCache\InvalidArgumentException;

class EmailBlacklistValidator
class EmailValidator
{
/**
* Array of blacklisted domains
* Array of blacklisted domains.
*/
private $domains = [];

/**
* Generate the error message on validation failure
* Generate the error message on validation failure.
*
* @param $message
* @param $attribute
* @param $rule
* @param $parameters
*
* @return string
*/
public function message($message, $attribute, $rule, $parameters)
Expand All @@ -44,29 +46,30 @@ public function message($message, $attribute, $rule, $parameters)
* @param string $value
* @param array $parameters
*
* @return bool.
*
* @throws \Exception
*
* @return bool.
*/
public function validate($attribute, $value, $parameters)
{
// Load blacklisted domains
$this->refresh();

// Extract domain from supplied email address
$domain = Str::after(strtolower($value), "@");
$domain = Str::after(strtolower($value), '@');

// Run validation check
return ! in_array($domain, $this->domains);
}

/**
* Retrive latest selection of blacklisted domains and cache them
* Retrive latest selection of blacklisted domains and cache them.
*
* @param null
*
* @return void
* @throws \Exception
*
* @return void
*/
public function refresh()
{
Expand All @@ -78,6 +81,7 @@ public function refresh()
protected function shouldUpdate()
{
$autoupdate = config('email-blacklist.auto-update');

try {
if ($autoupdate && ! cache()->has(config('email-blacklist.cache-key'))) {
EmailBlacklistUpdater::update();
Expand All @@ -95,4 +99,4 @@ protected function appendCustomDomains()
$append_domains = explode('|', strtolower($append_list));
$this->domains = array_merge($this->domains, $append_domains);
}
}
}
10 changes: 5 additions & 5 deletions config/email-blacklist.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
| Example: "example.com|example.net|foobar.com".
|
*/
'enabled' => true,
'source' => 'https://raw.githubusercontent.com/ivolo/disposable-email-domains/master/index.json',
'cache-key' => 'email.domains.blacklist',
'enabled' => true,
'source' => 'https://raw.githubusercontent.com/ivolo/disposable-email-domains/master/index.json',
'cache-key' => 'email.domains.blacklist',
'auto-update' => true,
'append' => null,
];
'append' => null,
];

0 comments on commit a060c5d

Please sign in to comment.