]> 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 eda724efc7e4df81a4e6fae7f69a9e85470ed443..03ddb4605b8f96d02e38f3b4e9822562dc15c132 100644 (file)
@@ -144,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;
        }
 
@@ -215,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;
@@ -244,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]) : [];
        }
 
        /**
@@ -539,7 +559,7 @@ class User
         * @return array
         * @throws HTTPException\NotFoundException
         */
-       private static function getAuthenticationInfo($user_info)
+       public static function getAuthenticationInfo($user_info)
        {
                $user = null;
 
@@ -1511,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;