From 913bf77ba4843c1eb36bd5c9bbb6ffdb795d1aca Mon Sep 17 00:00:00 2001 From: dx7 Date: Wed, 8 Jul 2020 23:58:31 -0300 Subject: [PATCH] Improve email validation error for restricted emails --- .../Controllers/Auth/RegisterController.php | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index bc01b9489..40271f1f5 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -58,8 +58,6 @@ class RegisterController extends Controller $data['email'] = strtolower($data['email']); } - $this->validateEmail($data['email']); - $usernameRules = [ 'required', 'min:2', @@ -94,11 +92,25 @@ class RegisterController extends Controller }, ]; + $emailRules = [ + 'required', + 'string', + 'email', + 'max:255', + 'unique:users', + function ($attribute, $value, $fail) { + $banned = EmailService::isBanned($value); + if($banned) { + return $fail('Email is invalid.'); + } + }, + ]; + $rules = [ 'agecheck' => 'required|accepted', 'name' => 'nullable|string|max:'.config('pixelfed.max_name_length'), 'username' => $usernameRules, - 'email' => 'required|string|email|max:255|unique:users', + 'email' => $emailRules, 'password' => 'required|string|min:12|confirmed', ]; @@ -127,14 +139,6 @@ class RegisterController extends Controller ]); } - public function validateEmail($email) - { - $banned = EmailService::isBanned($email); - if($banned) { - return abort(403, 'Invalid email.'); - } - } - /** * Show the application registration form. *