3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module\Settings;
25 use Friendica\Content\Widget;
26 use Friendica\Core\Config\Capability\IManageConfigValues;
27 use Friendica\Core\L10n;
28 use Friendica\Core\Renderer;
29 use Friendica\Core\Session\Capability\IHandleUserSessions;
30 use Friendica\Database\Database;
32 use Friendica\Model\User;
33 use Friendica\Model\User\Cookie;
34 use Friendica\Module\BaseSettings;
35 use Friendica\Module\Response;
36 use Friendica\Navigation\SystemMessages;
37 use Friendica\Util\Emailer;
38 use Friendica\Util\Profiler;
39 use Friendica\Util\Strings;
40 use Psr\Log\LoggerInterface;
42 class RemoveMe extends BaseSettings
44 /** @var IManageConfigValues */
50 /** @var SystemMessages */
51 private $systemMessages;
55 public function __construct(Cookie $cookie, SystemMessages $systemMessages, Emailer $emailer, Database $database, IManageConfigValues $config, IHandleUserSessions $session, App\Page $page, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
57 parent::__construct($session, $page, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
59 $this->config = $config;
60 $this->database = $database;
61 $this->emailer = $emailer;
62 $this->systemMessages = $systemMessages;
63 $this->cookie = $cookie;
66 protected function post(array $request = [])
68 if (!$this->session->getLocalUserId()) {
72 if ($this->session->getSubManagedUserId()) {
76 $hash = $this->session->pop('remove_account_verify');
77 if (empty($hash) || empty($request[$hash])) {
82 $userId = User::getIdFromPasswordAuthentication($this->session->getLocalUserId(), trim($request[$hash]));
83 } catch (\Throwable $e) {
84 $this->systemMessages->addNotice($e->getMessage());
88 // send notification to admins so that they can clean up the backups
89 foreach (User::getAdminListForEmailing(['uid', 'language', 'email']) as $admin) {
90 $l10n = $this->l10n->withLang($admin['language'] ?: 'en');
92 $email = $this->emailer
95 $l10n->t('[Friendica System Notify]') . ' ' . $l10n->t('User deleted their account'),
96 $l10n->t('On your Friendica node an user deleted their account. Please ensure that their data is removed from the backups.'),
97 $l10n->t('The user id is %d', $this->session->getLocalUserId()))
99 ->withRecipient($admin['email'])
101 $this->emailer->send($email);
104 User::remove($userId);
106 $this->session->clear();
107 $this->cookie->clear();
109 $this->systemMessages->addInfo($this->t('Your user account has been successfully removed. Bye bye!'));
110 $this->baseUrl->redirect();
113 protected function content(array $request = []): string
117 if (!$this->session->getLocalUserId()) {
118 $this->systemMessages->addNotice($this->t('Permission denied.'));
119 $this->baseUrl->redirect();
122 $hash = Strings::getRandomHex();
124 $this->session->set('remove_account_verify', $hash);
126 $tpl = Renderer::getMarkupTemplate('settings/removeme.tpl');
127 return Renderer::replaceMacros($tpl, [
129 'title' => DI::l10n()->t('Remove My Account'),
130 'desc' => DI::l10n()->t('This will completely remove your account. Once this has been done it is not recoverable.'),
133 '$hovercard' => Widget\Hovercard::getHTML(User::getOwnerDataById($this->session->getLocalUserId())),
135 '$password' => [$hash, $this->t('Please enter your password for verification:'), null, null, true],