3 * @copyright Copyright (C) 2010-2022, 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\Core\Config\Capability\IManageConfigValues;
26 use Friendica\Core\L10n;
27 use Friendica\Core\Renderer;
28 use Friendica\Core\Session\Capability\IHandleUserSessions;
29 use Friendica\Database\Database;
31 use Friendica\Model\User;
32 use Friendica\Model\User\Cookie;
33 use Friendica\Module\BaseSettings;
34 use Friendica\Module\Response;
35 use Friendica\Navigation\SystemMessages;
36 use Friendica\Util\Emailer;
37 use Friendica\Util\Profiler;
38 use Friendica\Util\Strings;
39 use Psr\Log\LoggerInterface;
41 class RemoveMe extends BaseSettings
43 /** @var IHandleUserSessions */
45 /** @var IManageConfigValues */
51 /** @var SystemMessages */
52 private $systemMessages;
56 public function __construct(Cookie $cookie, SystemMessages $systemMessages, Emailer $emailer, Database $database, IManageConfigValues $config, IHandleUserSessions $session, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
58 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
60 $this->session = $session;
61 $this->config = $config;
62 $this->database = $database;
63 $this->emailer = $emailer;
64 $this->systemMessages = $systemMessages;
65 $this->cookie = $cookie;
68 protected function post(array $request = [])
70 if (!$this->session->getLocalUserId()) {
74 if ($this->session->getSubManagedUserId()) {
78 $hash = $this->session->pop('remove_account_verify');
79 if (empty($hash) || empty($request[$hash])) {
84 $userId = User::getIdFromPasswordAuthentication($this->session->getLocalUserId(), trim($request[$hash]));
85 } catch (\Throwable $e) {
86 $this->systemMessages->addNotice($e->getMessage());
90 // send notification to admins so that they can clean up the backups
91 $admin_mails = explode(',', $this->config->get('config', 'admin_email'));
92 foreach ($admin_mails as $mail) {
93 $admin = $this->database->selectFirst('user', ['uid', 'language', 'email', 'username'], ['email' => trim($mail)]);
98 $l10n = $this->l10n->withLang($admin['language']);
100 $email = $this->emailer
103 $l10n->t('[Friendica System Notify]') . ' ' . $l10n->t('User deleted their account'),
104 $l10n->t('On your Friendica node an user deleted their account. Please ensure that their data is removed from the backups.'),
105 $l10n->t('The user id is %d', $this->session->getLocalUserId()))
107 ->withRecipient($admin['email'])
109 $this->emailer->send($email);
112 User::remove($userId);
114 $this->session->clear();
115 $this->cookie->clear();
117 $this->systemMessages->addInfo($this->t('Your user account has been successfully removed. Bye bye!'));
118 $this->baseUrl->redirect();
121 protected function content(array $request = []): string
125 if (!$this->session->getLocalUserId()) {
126 $this->systemMessages->addNotice($this->t('Permission denied.'));
127 $this->baseUrl->redirect();
130 $hash = Strings::getRandomHex();
132 $this->session->set('remove_account_verify', $hash);
134 $tpl = Renderer::getMarkupTemplate('settings/removeme.tpl');
135 return Renderer::replaceMacros($tpl, [
137 'title' => DI::l10n()->t('Remove My Account'),
138 'desc' => DI::l10n()->t('This will completely remove your account. Once this has been done it is not recoverable.'),
140 '$password' => [$hash, $this->t('Please enter your password for verification:'), null, null, true],