X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FUser.php;h=03ddb4605b8f96d02e38f3b4e9822562dc15c132;hb=bd9f36622e056c83e8bfef2920640285ce9672b0;hp=ee5c35af8470d4e8208b1c1ab38d4681b3a20376;hpb=831ea99bd6cc2ca9baf7b9107aa746e6896e4616;p=friendica.git diff --git a/src/Model/User.php b/src/Model/User.php index ee5c35af84..03ddb4605b 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -102,6 +102,29 @@ class User private static $owner; + /** + * Returns the numeric account type by their string + * + * @param string $accounttype as string constant + * @return int|null Numeric account type - or null when not set + */ + public static function getAccountTypeByString(string $accounttype) + { + switch ($accounttype) { + case 'person': + return User::ACCOUNT_TYPE_PERSON; + case 'organisation': + return User::ACCOUNT_TYPE_ORGANISATION; + case 'news': + return User::ACCOUNT_TYPE_NEWS; + case 'community': + return User::ACCOUNT_TYPE_COMMUNITY; + default: + return null; + break; + } + } + /** * Fetch the system account * @@ -121,6 +144,26 @@ class User $system['sprvkey'] = $system['uprvkey'] = $system['prvkey']; $system['spubkey'] = $system['upubkey'] = $system['pubkey']; $system['nickname'] = $system['nick']; + + // Ensure that the user contains data + $user = DBA::selectFirst('user', ['prvkey'], ['uid' => 0]); + if (empty($user['prvkey'])) { + $fields = [ + 'username' => $system['name'], + 'nickname' => $system['nick'], + 'register_date' => $system['created'], + 'pubkey' => $system['pubkey'], + 'prvkey' => $system['prvkey'], + 'spubkey' => $system['spubkey'], + 'sprvkey' => $system['sprvkey'], + 'verified' => true, + 'page-flags' => User::PAGE_FLAGS_SOAPBOX, + 'account-type' => User::ACCOUNT_TYPE_RELAY, + ]; + + DBA::update('user', $fields, ['uid' => 0]); + } + return $system; } @@ -192,7 +235,7 @@ class User // List of possible actor names $possible_accounts = ['friendica', 'actor', 'system', 'internal']; foreach ($possible_accounts as $name) { - if (!DBA::exists('user', ['nickname' => $name, 'account_removed' => false, 'expire']) && + if (!DBA::exists('user', ['nickname' => $name, 'account_removed' => false, 'expire' => false]) && !DBA::exists('userd', ['username' => $name])) { DI::config()->set('system', 'actor_name', $name); return $name; @@ -221,7 +264,7 @@ class User */ public static function getById($uid, array $fields = []) { - return DBA::selectFirst('user', $fields, ['uid' => $uid]); + return !empty($uid) ? DBA::selectFirst('user', $fields, ['uid' => $uid]) : []; } /** @@ -516,7 +559,7 @@ class User * @return array * @throws HTTPException\NotFoundException */ - private static function getAuthenticationInfo($user_info) + public static function getAuthenticationInfo($user_info) { $user = null; @@ -979,7 +1022,7 @@ class User $photo_failure = false; $filename = basename($photo); - $curlResult = DI::httpRequest()->get($photo, true); + $curlResult = DI::httpRequest()->get($photo); if ($curlResult->isSuccess()) { $img_str = $curlResult->getBody(); $type = $curlResult->getContentType(); @@ -1488,7 +1531,9 @@ class User $condition['blocked'] = false; break; case 'blocked': + $condition['account_removed'] = false; $condition['blocked'] = true; + $condition['verified'] = true; break; case 'removed': $condition['account_removed'] = true;