]> git.mxchange.org Git - friendica.git/blob - mod/removeme.php
Merge pull request #11761 from tobiasd/20220722-zh-cn
[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\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                 $l10n = DI::l10n()->withLang($admin['language']);
61
62                 $email = DI::emailer()
63                         ->newSystemMail()
64                         ->withMessage(
65                                 $l10n->t('[Friendica System Notify]') . ' ' . $l10n->t('User deleted their account'),
66                                 $l10n->t('On your Friendica node an user deleted their account. Please ensure that their data is removed from the backups.'),
67                                 $l10n->t('The user id is %d', local_user()))
68                         ->forUser($admin)
69                         ->withRecipient($admin['email'])
70                         ->build();
71                 DI::emailer()->send($email);
72         }
73
74         if (User::getIdFromPasswordAuthentication($a->getLoggedInUserId(), trim($_POST['qxz_password']))) {
75                 User::remove($a->getLoggedInUserId());
76
77                 unset($_SESSION['authenticated']);
78                 unset($_SESSION['uid']);
79                 DI::baseUrl()->redirect();
80                 // NOTREACHED
81         }
82 }
83
84 function removeme_content(App $a)
85 {
86         if (!local_user()) {
87                 DI::baseUrl()->redirect();
88         }
89
90         $hash = Strings::getRandomHex();
91
92         require_once("mod/settings.php");
93         settings_init($a);
94
95         $_SESSION['remove_account_verify'] = $hash;
96
97         $tpl = Renderer::getMarkupTemplate('removeme.tpl');
98         $o = Renderer::replaceMacros($tpl, [
99                 '$basedir' => DI::baseUrl()->get(),
100                 '$hash' => $hash,
101                 '$title' => DI::l10n()->t('Remove My Account'),
102                 '$desc' => DI::l10n()->t('This will completely remove your account. Once this has been done it is not recoverable.'),
103                 '$passwd' => DI::l10n()->t('Please enter your password for verification:'),
104                 '$submit' => DI::l10n()->t('Remove My Account')
105         ]);
106
107         return $o;
108 }