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