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