mirror of
https://github.com/pixelfed/pixelfed.git
synced 2025-01-30 16:30:45 +00:00
Merge pull request #2316 from dx7/improve-username-email-validation
Improve error messages for username and email restricted on register page
This commit is contained in:
commit
c6539bed90
1 changed files with 20 additions and 21 deletions
|
@ -58,9 +58,6 @@ class RegisterController extends Controller
|
||||||
$data['email'] = strtolower($data['email']);
|
$data['email'] = strtolower($data['email']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->validateUsername($data['username']);
|
|
||||||
$this->validateEmail($data['email']);
|
|
||||||
|
|
||||||
$usernameRules = [
|
$usernameRules = [
|
||||||
'required',
|
'required',
|
||||||
'min:2',
|
'min:2',
|
||||||
|
@ -87,6 +84,25 @@ class RegisterController extends Controller
|
||||||
if(!ctype_alnum($val)) {
|
if(!ctype_alnum($val)) {
|
||||||
return $fail('Username is invalid. Username must be alpha-numeric and may contain dashes (-), periods (.) and underscores (_).');
|
return $fail('Username is invalid. Username must be alpha-numeric and may contain dashes (-), periods (.) and underscores (_).');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$restricted = RestrictedNames::get();
|
||||||
|
if (in_array($value, $restricted)) {
|
||||||
|
return $fail('Username cannot be used.');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
$emailRules = [
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
'email',
|
||||||
|
'max:255',
|
||||||
|
'unique:users',
|
||||||
|
function ($attribute, $value, $fail) {
|
||||||
|
$banned = EmailService::isBanned($value);
|
||||||
|
if($banned) {
|
||||||
|
return $fail('Email is invalid.');
|
||||||
|
}
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -94,7 +110,7 @@ class RegisterController extends Controller
|
||||||
'agecheck' => 'required|accepted',
|
'agecheck' => 'required|accepted',
|
||||||
'name' => 'nullable|string|max:'.config('pixelfed.max_name_length'),
|
'name' => 'nullable|string|max:'.config('pixelfed.max_name_length'),
|
||||||
'username' => $usernameRules,
|
'username' => $usernameRules,
|
||||||
'email' => 'required|string|email|max:255|unique:users',
|
'email' => $emailRules,
|
||||||
'password' => 'required|string|min:12|confirmed',
|
'password' => 'required|string|min:12|confirmed',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -123,23 +139,6 @@ class RegisterController extends Controller
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validateUsername($username)
|
|
||||||
{
|
|
||||||
$restricted = RestrictedNames::get();
|
|
||||||
|
|
||||||
if (in_array($username, $restricted)) {
|
|
||||||
return abort(403);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function validateEmail($email)
|
|
||||||
{
|
|
||||||
$banned = EmailService::isBanned($email);
|
|
||||||
if($banned) {
|
|
||||||
return abort(403, 'Invalid email.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the application registration form.
|
* Show the application registration form.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue