]> git.mxchange.org Git - friendica.git/blob - mod/removeme.php
Merge pull request #8236 from annando/a11y-1
[friendica.git] / mod / removeme.php
1 <?php
2 /**
3  * @file mod/removeme.php
4  */
5
6 use Friendica\App;
7 use Friendica\Core\Renderer;
8 use Friendica\Database\DBA;
9 use Friendica\DI;
10 use Friendica\Model\User;
11 use Friendica\Util\Strings;
12
13 function removeme_post(App $a)
14 {
15         if (!local_user()) {
16                 return;
17         }
18
19         if (!empty($_SESSION['submanage'])) {
20                 return;
21         }
22
23         if (empty($_POST['qxz_password'])) {
24                 return;
25         }
26
27         if (empty($_POST['verify'])) {
28                 return;
29         }
30
31         if ($_POST['verify'] !== $_SESSION['remove_account_verify']) {
32                 return;
33         }
34
35         // send notification to admins so that they can clean um the backups
36         // send email to admins
37         $admin_mails = explode(",", str_replace(" ", "", DI::config()->get('config', 'admin_email')));
38         foreach ($admin_mails as $mail) {
39                 $admin = DBA::selectFirst('user', ['uid', 'language', 'email', 'username'], ['email' => $mail]);
40                 if (!DBA::isResult($admin)) {
41                         continue;
42                 }
43
44                 $email = DI::emailer()
45                         ->newSystemMail()
46                         ->withMessage(
47                                 DI::l10n()->t('[Friendica System Notify]') . ' ' . DI::l10n()->t('User deleted their account'),
48                                 DI::l10n()->t('On your Friendica node an user deleted their account. Please ensure that their data is removed from the backups.'),
49                                 DI::l10n()->t('The user id is %d', local_user()))
50                         ->forUser($admin)
51                         ->withRecipient($admin['email'])
52                         ->build();
53                 DI::emailer()->send($email);
54         }
55
56         if (User::getIdFromPasswordAuthentication($a->user, trim($_POST['qxz_password']))) {
57                 User::remove($a->user['uid']);
58
59                 unset($_SESSION['authenticated']);
60                 unset($_SESSION['uid']);
61                 DI::baseUrl()->redirect();
62                 // NOTREACHED
63         }
64 }
65
66 function removeme_content(App $a)
67 {
68         if (!local_user()) {
69                 DI::baseUrl()->redirect();
70         }
71
72         $hash = Strings::getRandomHex();
73
74         require_once("mod/settings.php");
75         settings_init($a);
76
77         $_SESSION['remove_account_verify'] = $hash;
78
79         $tpl = Renderer::getMarkupTemplate('removeme.tpl');
80         $o = Renderer::replaceMacros($tpl, [
81                 '$basedir' => DI::baseUrl()->get(),
82                 '$hash' => $hash,
83                 '$title' => DI::l10n()->t('Remove My Account'),
84                 '$desc' => DI::l10n()->t('This will completely remove your account. Once this has been done it is not recoverable.'),
85                 '$passwd' => DI::l10n()->t('Please enter your password for verification:'),
86                 '$submit' => DI::l10n()->t('Remove My Account')
87         ]);
88
89         return $o;
90 }