mirror of
https://github.com/flarum/framework.git
synced 2025-02-02 13:55:37 +08:00
Make sure usernames cannot take the value of nicknames (#1)
This commit is contained in:
parent
02298127b7
commit
ffbb37e956
|
@ -21,7 +21,10 @@ class AddNicknameValidation
|
|||
|
||||
public function __invoke($flarumValidator, Validator $validator)
|
||||
{
|
||||
$nicknameRules = [
|
||||
$idSuffix = $flarumValidator->getUser() ? ','.$flarumValidator->getUser()->id : '';
|
||||
$rules = $validator->getRules();
|
||||
|
||||
$rules['nickname'] = [
|
||||
function ($attribute, $value, $fail) {
|
||||
$regex = $this->settings->get('flarum-nicknames.regex');
|
||||
if ($regex && !preg_match_all("/$regex/", $value)) {
|
||||
|
@ -34,12 +37,11 @@ class AddNicknameValidation
|
|||
];
|
||||
|
||||
if ($this->settings->get('flarum-nicknames.unique')) {
|
||||
$nicknameRules[] = 'unique:users,username';
|
||||
$nicknameRules[] = 'unique:users,nickname';
|
||||
$rules['nickname'][] = 'unique:users,username'.$idSuffix;
|
||||
$rules['nickname'][] = 'unique:users,nickname'.$idSuffix;
|
||||
$rules['username'][] = 'unique:users,nickname'.$idSuffix;
|
||||
}
|
||||
|
||||
$validator->setRules([
|
||||
'nickname' => $nicknameRules,
|
||||
] + $validator->getRules());
|
||||
$validator->setRules($rules);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,10 +24,8 @@ class SaveNicknameToDatabase {
|
|||
|
||||
$nickname = $attributes['nickname'];
|
||||
|
||||
// If unique validation is enabled, the nickname will be checked
|
||||
// against ALL nicknames and usernames, including the username
|
||||
// of the current user. So, to allow users to reset their nickname
|
||||
// back to their username, in this case we'd set it to null.
|
||||
// If the user sets their nickname back to the username
|
||||
// set the nickname to null so that it just falls back to the username
|
||||
if ($user->username === $nickname) {
|
||||
$user->nickname = null;
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue
Block a user