X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FUser.php;h=bcd555a0ec11c46a8b1bbc6cc858074c22b67c62;hb=9c0342b907c279fe335676a1cbeacae8a5ac5c85;hp=ee5c35af8470d4e8208b1c1ab38d4681b3a20376;hpb=9c675c3f01acf30571f6c3e3d9d450be23a9b59a;p=friendica.git diff --git a/src/Model/User.php b/src/Model/User.php index ee5c35af84..bcd555a0ec 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -41,6 +41,7 @@ use Friendica\Util\Crypto; use Friendica\Util\DateTimeFormat; use Friendica\Util\Images; use Friendica\Util\Network; +use Friendica\Util\Proxy; use Friendica\Util\Strings; use Friendica\Worker\Delivery; use ImagickException; @@ -102,6 +103,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 +145,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; } @@ -149,11 +193,12 @@ class User $system['name'] = 'System Account'; $system['addr'] = $system_actor_name . '@' . DI::baseUrl()->getHostname(); $system['nick'] = $system_actor_name; - $system['avatar'] = DI::baseUrl() . Contact::DEFAULT_AVATAR_PHOTO; - $system['photo'] = DI::baseUrl() . Contact::DEFAULT_AVATAR_PHOTO; - $system['thumb'] = DI::baseUrl() . Contact::DEFAULT_AVATAR_THUMB; - $system['micro'] = DI::baseUrl() . Contact::DEFAULT_AVATAR_MICRO; $system['url'] = DI::baseUrl() . '/friendica'; + + $system['avatar'] = $system['photo'] = Contact::getDefaultAvatar($system, Proxy::SIZE_SMALL); + $system['thumb'] = Contact::getDefaultAvatar($system, Proxy::SIZE_THUMB); + $system['micro'] = Contact::getDefaultAvatar($system, Proxy::SIZE_MICRO); + $system['nurl'] = Strings::normaliseLink($system['url']); $system['pubkey'] = $keys['pubkey']; $system['prvkey'] = $keys['prvkey']; @@ -192,7 +237,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 +266,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 +561,7 @@ class User * @return array * @throws HTTPException\NotFoundException */ - private static function getAuthenticationInfo($user_info) + public static function getAuthenticationInfo($user_info) { $user = null; @@ -979,7 +1024,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 +1533,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;