]> git.mxchange.org Git - friendica.git/blob - mod/removeme.php
Merge pull request #12025 from annando/no-boot-src-module
[friendica.git] / mod / removeme.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
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.
11  *
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.
16  *
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/>.
19  *
20  */
21
22 use Friendica\App;
23 use Friendica\Core\Renderer;
24 use Friendica\Core\Session;
25 use Friendica\Database\DBA;
26 use Friendica\DI;
27 use Friendica\Model\User;
28 use Friendica\Util\Strings;
29
30 function removeme_post(App $a)
31 {
32         if (!Session::getLocalUser()) {
33                 return;
34         }
35
36         if (!empty($_SESSION['submanage'])) {
37                 return;
38         }
39
40         if (empty($_POST['qxz_password'])) {
41                 return;
42         }
43
44         if (empty($_POST['verify'])) {
45                 return;
46         }
47
48         if ($_POST['verify'] !== $_SESSION['remove_account_verify']) {
49                 return;
50         }
51
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)) {
58                         continue;
59                 }
60
61                 $l10n = DI::l10n()->withLang($admin['language']);
62
63                 $email = DI::emailer()
64                         ->newSystemMail()
65                         ->withMessage(
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()))
69                         ->forUser($admin)
70                         ->withRecipient($admin['email'])
71                         ->build();
72                 DI::emailer()->send($email);
73         }
74
75         if (User::getIdFromPasswordAuthentication($a->getLoggedInUserId(), trim($_POST['qxz_password']))) {
76                 User::remove($a->getLoggedInUserId());
77
78                 unset($_SESSION['authenticated']);
79                 unset($_SESSION['uid']);
80                 DI::baseUrl()->redirect();
81                 // NOTREACHED
82         }
83 }
84
85 function removeme_content(App $a)
86 {
87         if (!Session::getLocalUser()) {
88                 DI::baseUrl()->redirect();
89         }
90
91         $hash = Strings::getRandomHex();
92
93         require_once("mod/settings.php");
94         settings_init($a);
95
96         $_SESSION['remove_account_verify'] = $hash;
97
98         $tpl = Renderer::getMarkupTemplate('removeme.tpl');
99         $o = Renderer::replaceMacros($tpl, [
100                 '$basedir' => DI::baseUrl()->get(),
101                 '$hash' => $hash,
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')
106         ]);
107
108         return $o;
109 }