Browse Source

Change rules for username

Consecutive spaces are now an error. They used to be automatically converted to a single space.
Visman 4 năm trước cách đây
mục cha
commit
d18aeff528

+ 1 - 1
app/Models/Pages/Admin/Users/NewUser.php

@@ -27,7 +27,7 @@ class NewUser extends Users
                 ])->addRules([
                     'token'    => 'token:AdminUsersNew',
                     'email'    => 'required|string:trim|email:noban,unique',
-                    'username' => 'required|string:trim,spaces|username',
+                    'username' => 'required|string:trim|username',
                     'password' => 'required|string|min:16|password',
                 ])->addAliases([
                     'email'    => 'Email',

+ 1 - 1
app/Models/Pages/PostValidatorTrait.php

@@ -98,7 +98,7 @@ trait PostValidatorTrait
 
         if ($this->user->isGuest) {
             $ruleEmail    = ('1' == $this->c->config->p_force_guest_email ? 'required|' : '') . 'string:trim|email:noban';
-            $ruleUsername = 'required|string:trim,spaces|username';
+            $ruleUsername = 'required|string:trim|username';
         } else {
             $ruleEmail    = 'absent';
             $ruleUsername = 'absent';

+ 1 - 1
app/Models/Pages/Profile/Edit.php

@@ -37,7 +37,7 @@ class Edit extends Profile
 
         if ('POST' === $method) {
             if ($this->rules->rename) {
-                $ruleUsername = 'required|string:trim,spaces|username';
+                $ruleUsername = 'required|string:trim|username';
             } else {
                 $ruleUsername = 'absent';
             }

+ 1 - 1
app/Models/Pages/Register.php

@@ -27,7 +27,7 @@ class Register extends Page
                 'agree'    => 'required|token:Register',
                 'on'       => 'integer',
                 'email'    => 'required_with:on|string:trim|email:noban,unique',
-                'username' => 'required_with:on|string:trim,spaces|username',
+                'username' => 'required_with:on|string:trim|username',
                 'password' => 'required_with:on|string|min:16|password',
                 'register' => 'required|string',
             ])->addAliases([

+ 3 - 0
app/Models/Validators/Username.php

@@ -38,6 +38,9 @@ class Username extends RulesValidator
             // 2-25 символов, буквы, цифры, пробел, подчеркивание, точка и тире
             if (! \preg_match('%^(?=.{2,25}$)\p{L}[\p{L}\p{N}\x20\._-]+$%uD', $username)) {
                 $v->addError('Login format');
+            // идущие подряд пробелы
+            } elseif (\preg_match('%\s{2,}%u', $username)) {
+                $v->addError('Username contains consecutive spaces');
             // цензура
             } elseif ($this->c->censorship->censor($username) !== $username) {
                 $v->addError('Username censor');

+ 3 - 0
app/lang/en/validator.po

@@ -50,3 +50,6 @@ msgstr "Please update your browser."
 
 msgid "Bad browser"
 msgstr "Please update your browser."
+
+msgid "Username contains consecutive spaces"
+msgstr "Username contains consecutive spaces."

+ 3 - 0
app/lang/ru/validator.po

@@ -50,3 +50,6 @@ msgstr "Обновите свой браузер."
 
 msgid "Bad browser"
 msgstr "Обновите свой браузер."
+
+msgid "Username contains consecutive spaces"
+msgstr "В имени пользователя есть идущие подряд пробелы."