From b09ffa0697c0d500345fd17d33162a02982577a4 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 18 Nov 2020 05:33:17 +0000 Subject: [PATCH] Relocate system user creation --- src/Database/DBStructure.php | 18 ------------------ src/Model/User.php | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/Database/DBStructure.php b/src/Database/DBStructure.php index dbe68aca1..37f55683a 100644 --- a/src/Database/DBStructure.php +++ b/src/Database/DBStructure.php @@ -1075,24 +1075,6 @@ class DBStructure } } -/* if (self::existsTable('user') && DBA::exists('user', ['uid' => 0])) { - $system = User::getSystemAccount(); - $user = [ - "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', $user, ['uid' => 0]); - } -*/ if (self::existsTable('permissionset')) { if (!DBA::exists('permissionset', ['id' => 0])) { DBA::insert('permissionset', ['allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '']); diff --git a/src/Model/User.php b/src/Model/User.php index 1959e9579..2b7018950 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -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; }