X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FUser.php;h=11d55e7f7e26529fa507f8ddacd2b5a60124b385;hb=c5ca5bfdf84f6fb5e4ba4d8509df25c58aeb516a;hp=b0ece93464ca70fc5518323056006cfbdf16a372;hpb=843502badcf6737dae1f8ea7a0b9ebe2984caa9a;p=friendica.git diff --git a/src/Model/User.php b/src/Model/User.php index b0ece93464..11d55e7f7e 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -35,6 +35,7 @@ use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\DI; +use Friendica\Module; use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Security\TwoFactor\Model\AppSpecificPassword; use Friendica\Network\HTTPException; @@ -528,7 +529,7 @@ class User // Addons can create users, and since this 'catch' branch should only // execute if getAuthenticationInfo can't find an existing user, that's // exactly what will happen here. Creating a numeric username would create - // abiguity with user IDs, possibly opening up an attack vector. + // ambiguity with user IDs, possibly opening up an attack vector. // So let's be very careful about that. if (empty($username) || is_numeric($username)) { throw $e; @@ -683,7 +684,7 @@ class User if ($user['last-activity'] != $current_day) { User::update(['last-activity' => $current_day], $uid); - // Set the last actitivy for all identities of the user + // Set the last activity for all identities of the user DBA::update('user', ['last-activity' => $current_day], ['parent-uid' => $uid, 'account_removed' => false]); } } @@ -815,14 +816,14 @@ class User * Empties the password reset token field just in case. * * @param int $uid - * @param string $pasword_hashed + * @param string $password_hashed * @return bool * @throws Exception */ - private static function updatePasswordHashed(int $uid, string $pasword_hashed): bool + private static function updatePasswordHashed(int $uid, string $password_hashed): bool { $fields = [ - 'password' => $pasword_hashed, + 'password' => $password_hashed, 'pwdreset' => null, 'pwdreset_time' => null, 'legacy_password' => false @@ -850,7 +851,7 @@ class User * Checks if a nickname is in the list of the forbidden nicknames * * Check if a nickname is forbidden from registration on the node by the - * admin. Forbidden nicknames (e.g. role namess) can be configured in the + * admin. Forbidden nicknames (e.g. role names) can be configured in the * admin panel. * * @param string $nickname The nickname that should be checked @@ -1231,7 +1232,7 @@ class User $resource_id = Photo::newResource(); - // Not using Photo::PROFILE_PHOTOS here, so that it is discovered as translateble string + // Not using Photo::PROFILE_PHOTOS here, so that it is discovered as translatable string $profile_album = DI::l10n()->t('Profile Photos'); $r = Photo::store($image, $uid, 0, $resource_id, $filename, $profile_album, 4); @@ -1266,6 +1267,8 @@ class User Hook::callAll('register_account', $uid); + self::setRegisterMethodByUserCount(); + $return['user'] = $user; return $return; } @@ -1374,7 +1377,7 @@ class User * permanently against re-registration, as the person was not yet * allowed to have friends on this system * - * @return bool True, if the deny was successfull + * @return bool True, if the deny was successful * @throws Exception */ public static function deny(string $hash): bool @@ -1610,6 +1613,7 @@ class User // Remove the user relevant data Worker::add(Worker::PRIORITY_NEGLIGIBLE, 'RemoveUser', $uid); + self::setRegisterMethodByUserCount(); return true; } @@ -1788,7 +1792,7 @@ class User * * @param int $start Start count (Default is 0) * @param int $count Count of the items per page (Default is @see Pager::ITEMS_PER_PAGE) - * @param string $type The type of users, which should get (all, bocked, removed) + * @param string $type The type of users, which should get (all, blocked, removed) * @param string $order Order of the user list (Default is 'contact.name') * @param bool $descending Order direction (Default is ascending) * @return array|bool The list of the users @@ -1877,4 +1881,29 @@ class User return true; }); } + + public static function setRegisterMethodByUserCount() + { + $max_registered_users = DI::config()->get('config', 'max_registered_users'); + if ($max_registered_users <= 0) { + return; + } + + $register_policy = DI::config()->get('config', 'register_policy'); + if (!in_array($register_policy, [Module\Register::OPEN, Module\Register::CLOSED])) { + Logger::debug('Unsupported register policy.', ['policy' => $register_policy]); + return; + } + + $users = DBA::count('user', ['blocked' => false, 'account_removed' => false, 'account_expired' => false]); + if (($users >= $max_registered_users) && ($register_policy == Module\Register::OPEN)) { + DI::config()->set('config', 'register_policy', Module\Register::CLOSED); + Logger::notice('Max users reached, registration is closed.', ['users' => $users, 'max' => $max_registered_users]); + } elseif (($users < $max_registered_users) && ($register_policy == Module\Register::CLOSED)) { + DI::config()->set('config', 'register_policy', Module\Register::OPEN); + Logger::notice('Below maximum users, registration is opened.', ['users' => $users, 'max' => $max_registered_users]); + } else { + Logger::debug('Unchanged register policy', ['policy' => $register_policy, 'users' => $users, 'max' => $max_registered_users]); + } + } }