]> git.mxchange.org Git - friendica.git/blob - mod/removeme.php
The central item fetch does work now and the API now uses these functions
[friendica.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 use Friendica\Database\DBM;
10
11 require_once 'include/enotify.php';
12
13 function removeme_post(App $a)
14 {
15         if (!local_user()) {
16                 return;
17         }
18
19         if (x($_SESSION, 'submanage') && intval($_SESSION['submanage'])) {
20                 return;
21         }
22
23         if ((!x($_POST, 'qxz_password')) || (!strlen(trim($_POST['qxz_password'])))) {
24                 return;
25         }
26
27         if ((!x($_POST, 'verify')) || (!strlen(trim($_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(" ", "", $a->config['admin_email']));
38         foreach ($admin_mails as $mail) {
39                 $admin = dba::selectFirst('user', ['uid', 'language', 'email'], ['email' => $mail]);
40                 if (!DBM::is_result($admin)) {
41                         continue;
42                 }
43                 notification([
44                         'type'         => SYSTEM_EMAIL,
45                         'subject'      => L10n::t('[Friendica System Notify]') . ' ' . L10n::t('User deleted their account'),
46                         'preamble'     => L10n::t('On your Friendica node an user deleted their account. Please ensure that their data is removed from the backups.'),
47                         'body'         => L10n::t('The user id is %d', local_user()),
48                         'to_email'     => $admin['email'],
49                         'uid'          => $admin['uid'],
50                         'language'     => $admin['language'] ? $admin['language'] : 'en',
51                         'show_in_notification_page' => false
52                 ]);
53         }
54
55         if (User::authenticate($a->user, trim($_POST['qxz_password']))) {
56                 User::remove($a->user['uid']);
57                 // NOTREACHED
58         }
59 }
60
61 function removeme_content(App $a)
62 {
63         if (!local_user()) {
64                 goaway(System::baseUrl());
65         }
66
67         $hash = random_string();
68
69         require_once("mod/settings.php");
70         settings_init($a);
71
72         $_SESSION['remove_account_verify'] = $hash;
73
74         $tpl = get_markup_template('removeme.tpl');
75         $o = replace_macros($tpl, [
76                 '$basedir' => System::baseUrl(),
77                 '$hash' => $hash,
78                 '$title' => L10n::t('Remove My Account'),
79                 '$desc' => L10n::t('This will completely remove your account. Once this has been done it is not recoverable.'),
80                 '$passwd' => L10n::t('Please enter your password for verification:'),
81                 '$submit' => L10n::t('Remove My Account')
82         ]);
83
84         return $o;
85 }