]> git.mxchange.org Git - friendica.git/commitdiff
Use username_min/max_length config keys in Model\User::create
authorHypolite Petovan <hypolite@mrpetovan.com>
Sat, 20 Oct 2018 20:33:54 +0000 (16:33 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sat, 20 Oct 2018 20:33:54 +0000 (16:33 -0400)
src/Model/User.php

index 63aaa1e3de2c59312e1033bbd2ad6d5807e44210..71c1306b8e1ece46f35d99a9036a4f9f35f98691 100644 (file)
@@ -466,19 +466,23 @@ class User
                // collapse multiple spaces in name
                $username = preg_replace('/ +/', ' ', $username);
 
-               if (mb_strlen($username) > 48) {
-                       throw new Exception(L10n::t('Please use a shorter name.'));
+               $username_min_length = max(1, min(255, intval(Config::get('system', 'username_min_length', 0))));
+               $username_max_length = max(1, min(255, intval(Config::get('system', 'username_max_length', 0))));
+
+               if (mb_strlen($username) < $username_min_length) {
+                       throw new Exception(L10n::tt('Username should be at least %s character.', 'Username should be at least %s character.', $username_min_length));
                }
-               if (mb_strlen($username) < 3) {
-                       throw new Exception(L10n::t('Name too short.'));
+
+               if (mb_strlen($username) > $username_max_length) {
+                       throw new Exception(L10n::tt('Username should be at most %s character.', 'Username should be at most %s characters.', $username_max_length));
                }
 
                // So now we are just looking for a space in the full name.
                $loose_reg = Config::get('system', 'no_regfullname');
                if (!$loose_reg) {
                        $username = mb_convert_case($username, MB_CASE_TITLE, 'UTF-8');
-                       if (!strpos($username, ' ')) {
-                               throw new Exception(L10n::t("That doesn't appear to be your full \x28First Last\x29 name."));
+                       if (strpos($username, ' ') === false) {
+                               throw new Exception(L10n::t("That doesn't appear to be your full (First Last) name."));
                        }
                }