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