]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/User.php
Cast field data when ATTR_EMULATE_PREPARES is enabled
[friendica.git] / src / Model / User.php
index 73636a9953762bb4726e9db45a2a3ca10bac4efa..03ddb4605b8f96d02e38f3b4e9822562dc15c132 100644 (file)
@@ -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]) : [];
        }
 
        /**
@@ -366,7 +409,7 @@ class User
                if (!$repair) {
                        // Check if "addr" is present and correct
                        $addr = $owner['nickname'] . '@' . substr(DI::baseUrl(), strpos(DI::baseUrl(), '://') + 3);
-                       $repair = ($addr != $owner['addr']);
+                       $repair = ($addr != $owner['addr']) || empty($owner['prvkey']) || empty($owner['pubkey']);
                }
 
                if (!$repair) {
@@ -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;