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/>.
23 use Friendica\Core\Renderer;
24 use Friendica\Core\Session;
25 use Friendica\Database\DBA;
27 use Friendica\Model\User;
28 use Friendica\Util\Strings;
30 function removeme_post(App $a)
32 if (!Session::getLocalUser()) {
36 if (!empty($_SESSION['submanage'])) {
40 if (empty($_POST['qxz_password'])) {
44 if (empty($_POST['verify'])) {
48 if ($_POST['verify'] !== $_SESSION['remove_account_verify']) {
52 // send notification to admins so that they can clean um the backups
53 // send email to admins
54 $admin_mails = explode(",", str_replace(" ", "", DI::config()->get('config', 'admin_email')));
55 foreach ($admin_mails as $mail) {
56 $admin = DBA::selectFirst('user', ['uid', 'language', 'email', 'username'], ['email' => $mail]);
57 if (!DBA::isResult($admin)) {
61 $l10n = DI::l10n()->withLang($admin['language']);
63 $email = DI::emailer()
66 $l10n->t('[Friendica System Notify]') . ' ' . $l10n->t('User deleted their account'),
67 $l10n->t('On your Friendica node an user deleted their account. Please ensure that their data is removed from the backups.'),
68 $l10n->t('The user id is %d', Session::getLocalUser()))
70 ->withRecipient($admin['email'])
72 DI::emailer()->send($email);
75 if (User::getIdFromPasswordAuthentication($a->getLoggedInUserId(), trim($_POST['qxz_password']))) {
76 User::remove($a->getLoggedInUserId());
78 unset($_SESSION['authenticated']);
79 unset($_SESSION['uid']);
80 DI::baseUrl()->redirect();
85 function removeme_content(App $a)
87 if (!Session::getLocalUser()) {
88 DI::baseUrl()->redirect();
91 $hash = Strings::getRandomHex();
93 require_once("mod/settings.php");
96 $_SESSION['remove_account_verify'] = $hash;
98 $tpl = Renderer::getMarkupTemplate('removeme.tpl');
99 $o = Renderer::replaceMacros($tpl, [
100 '$basedir' => DI::baseUrl()->get(),
102 '$title' => DI::l10n()->t('Remove My Account'),
103 '$desc' => DI::l10n()->t('This will completely remove your account. Once this has been done it is not recoverable.'),
104 '$passwd' => DI::l10n()->t('Please enter your password for verification:'),
105 '$submit' => DI::l10n()->t('Remove My Account')