Avoid notices whwn creating events
[friendica.git/.git] / mod / removeme.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, 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\Database\DBA;
25 use Friendica\DI;
26 use Friendica\Model\User;
27 use Friendica\Util\Strings;
28
29 function removeme_post(App $a)
30 {
31         if (!local_user()) {
32                 return;
33         }
34
35         if (!empty($_SESSION['submanage'])) {
36                 return;
37         }
38
39         if (empty($_POST['qxz_password'])) {
40                 return;
41         }
42
43         if (empty($_POST['verify'])) {
44                 return;
45         }
46
47         if ($_POST['verify'] !== $_SESSION['remove_account_verify']) {
48                 return;
49         }
50
51         // send notification to admins so that they can clean um the backups
52         // send email to admins
53         $admin_mails = explode(",", str_replace(" ", "", DI::config()->get('config', 'admin_email')));
54         foreach ($admin_mails as $mail) {
55                 $admin = DBA::selectFirst('user', ['uid', 'language', 'email', 'username'], ['email' => $mail]);
56                 if (!DBA::isResult($admin)) {
57                         continue;
58                 }
59
60                 $email = DI::emailer()
61                         ->newSystemMail()
62                         ->withMessage(
63                                 DI::l10n()->t('[Friendica System Notify]') . ' ' . DI::l10n()->t('User deleted their account'),
64                                 DI::l10n()->t('On your Friendica node an user deleted their account. Please ensure that their data is removed from the backups.'),
65                                 DI::l10n()->t('The user id is %d', local_user()))
66                         ->forUser($admin)
67                         ->withRecipient($admin['email'])
68                         ->build();
69                 DI::emailer()->send($email);
70         }
71
72         if (User::getIdFromPasswordAuthentication($a->user, trim($_POST['qxz_password']))) {
73                 User::remove($a->user['uid']);
74
75                 unset($_SESSION['authenticated']);
76                 unset($_SESSION['uid']);
77                 DI::baseUrl()->redirect();
78                 // NOTREACHED
79         }
80 }
81
82 function removeme_content(App $a)
83 {
84         if (!local_user()) {
85                 DI::baseUrl()->redirect();
86         }
87
88         $hash = Strings::getRandomHex();
89
90         require_once("mod/settings.php");
91         settings_init($a);
92
93         $_SESSION['remove_account_verify'] = $hash;
94
95         $tpl = Renderer::getMarkupTemplate('removeme.tpl');
96         $o = Renderer::replaceMacros($tpl, [
97                 '$basedir' => DI::baseUrl()->get(),
98                 '$hash' => $hash,
99                 '$title' => DI::l10n()->t('Remove My Account'),
100                 '$desc' => DI::l10n()->t('This will completely remove your account. Once this has been done it is not recoverable.'),
101                 '$passwd' => DI::l10n()->t('Please enter your password for verification:'),
102                 '$submit' => DI::l10n()->t('Remove My Account')
103         ]);
104
105         return $o;
106 }