X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FUser.php;h=278b541fa897222f24fd45165aa92aae15a2e93e;hb=531ef6e6e2a7c5968036ce1e7b8a0caaca7accea;hp=e6f20f738732d32524ced00a71f615224a5cc1a5;hpb=8c328a3c60d3bcbc8b091158383bf829064d2c9c;p=friendica.git diff --git a/src/Model/User.php b/src/Model/User.php index e6f20f7387..278b541fa8 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -34,13 +34,14 @@ use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\DI; -use Friendica\Model\TwoFactor\AppSpecificPassword; +use Friendica\Security\TwoFactor\Model\AppSpecificPassword; use Friendica\Network\HTTPException; use Friendica\Object\Image; 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; @@ -96,6 +97,7 @@ class User const ACCOUNT_TYPE_NEWS = 2; const ACCOUNT_TYPE_COMMUNITY = 3; const ACCOUNT_TYPE_RELAY = 4; + const ACCOUNT_TYPE_DELETED = 127; /** * @} */ @@ -144,6 +146,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; } @@ -172,11 +194,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']; @@ -215,7 +238,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 +267,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]) : []; } /** @@ -348,12 +371,12 @@ class User /** * Get owner data by user id * - * @param int $uid - * @param boolean $check_valid Test if data is invalid and correct it + * @param int $uid + * @param boolean $repairMissing Repair the owner data if it's missing * @return boolean|array * @throws Exception */ - public static function getOwnerDataById(int $uid, bool $check_valid = true) + public static function getOwnerDataById(int $uid, bool $repairMissing = true) { if ($uid == 0) { return self::getSystemAccount(); @@ -365,7 +388,7 @@ class User $owner = DBA::selectFirst('owner-view', [], ['uid' => $uid]); if (!DBA::isResult($owner)) { - if (!DBA::exists('user', ['uid' => $uid]) || !$check_valid) { + if (!DBA::exists('user', ['uid' => $uid]) || !$repairMissing) { return false; } Contact::createSelfFromUserId($uid); @@ -376,7 +399,7 @@ class User return false; } - if (!$check_valid) { + if (!$repairMissing || $owner['account_expired']) { return $owner; } @@ -539,7 +562,7 @@ class User * @return array * @throws HTTPException\NotFoundException */ - private static function getAuthenticationInfo($user_info) + public static function getAuthenticationInfo($user_info) { $user = null; @@ -1002,16 +1025,16 @@ 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(); - $contType = $curlResult->getContentType(); + $type = $curlResult->getContentType(); } else { $img_str = ''; - $contType = ''; + $type = ''; } - $type = Images::getMimeTypeByData($img_str, $photo, $contType); + $type = Images::getMimeTypeByData($img_str, $photo, $type); $Image = new Image($img_str, $type); if ($Image->isValid()) { @@ -1136,6 +1159,9 @@ class User return false; } + // Delete the avatar + Photo::delete(['uid' => $register['uid']]); + return DBA::delete('user', ['uid' => $register['uid']]) && Register::deleteByHash($register['hash']); } @@ -1327,7 +1353,7 @@ class User */ public static function remove(int $uid) { - if (!$uid) { + if (empty($uid)) { return false; } @@ -1341,6 +1367,9 @@ class User // unique), so it cannot be re-registered in the future. DBA::insert('userd', ['username' => $user['nickname']]); + // Remove all personal settings, especially connector settings + DBA::delete('pconfig', ['uid' => $uid]); + // The user and related data will be deleted in Friendica\Worker\ExpireAndRemoveUsers DBA::update('user', ['account_removed' => true, 'account_expires_on' => DateTimeFormat::utc('now + 7 day')], ['uid' => $uid]); Worker::add(PRIORITY_HIGH, 'Notifier', Delivery::REMOVAL, $uid); @@ -1511,7 +1540,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;