]> git.mxchange.org Git - friendica.git/blob - mod/regmod.php
2a418fcda053def513c06560d68866b73572fa21
[friendica.git] / mod / regmod.php
1 <?php
2 /**
3  * @file mod/regmod.php
4  */
5
6 use Friendica\App;
7 use Friendica\Core\Config;
8 use Friendica\Core\L10n;
9 use Friendica\Core\System;
10 use Friendica\Core\Worker;
11 use Friendica\Database\DBM;
12 use Friendica\Model\User;
13 use Friendica\Module\Login;
14
15 require_once 'include/enotify.php';
16
17 function user_allow($hash)
18 {
19         $a = get_app();
20
21         $register = q("SELECT * FROM `register` WHERE `hash` = '%s' LIMIT 1",
22                 dbesc($hash)
23         );
24
25
26         if (!DBM::is_result($register)) {
27                 return false;
28         }
29
30         $user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
31                 intval($register[0]['uid'])
32         );
33
34         if (!DBM::is_result($user)) {
35                 killme();
36         }
37
38         $r = q("DELETE FROM `register` WHERE `hash` = '%s'",
39                 dbesc($register[0]['hash'])
40         );
41
42
43         $r = q("UPDATE `user` SET `blocked` = 0, `verified` = 1 WHERE `uid` = %d",
44                 intval($register[0]['uid'])
45         );
46
47         $r = q("SELECT * FROM `profile` WHERE `uid` = %d AND `is-default` = 1",
48                 intval($user[0]['uid'])
49         );
50         if (DBM::is_result($r) && $r[0]['net-publish']) {
51                 $url = System::baseUrl() . '/profile/' . $user[0]['nickname'];
52                 if ($url && strlen(Config::get('system', 'directory'))) {
53                         Worker::add(PRIORITY_LOW, "Directory", $url);
54                 }
55         }
56
57         L10n::pushLang($register[0]['language']);
58
59         $res = User::sendRegisterOpenEmail(
60                 $user[0]['email'],
61                 Config::get('config', 'sitename'),
62                 System::baseUrl(),
63                 $user[0]['username'],
64                 $register[0]['password']);
65
66         L10n::popLang();
67
68         if ($res) {
69                 info(L10n::t('Account approved.') . EOL);
70                 return true;
71         }
72 }
73
74 // This does not have to go through user_remove() and save the nickname
75 // permanently against re-registration, as the person was not yet
76 // allowed to have friends on this system
77 function user_deny($hash)
78 {
79         $register = q("SELECT * FROM `register` WHERE `hash` = '%s' LIMIT 1",
80                 dbesc($hash)
81         );
82
83         if (!DBM::is_result($register)) {
84                 return false;
85         }
86
87         $user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
88                 intval($register[0]['uid'])
89         );
90
91         dba::delete('user', ['uid' => $register[0]['uid']]);
92         dba::delete('register', ['hash' => $register[0]['hash']]);
93
94         notice(L10n::t('Registration revoked for %s', $user[0]['username']) . EOL);
95         return true;
96 }
97
98 function regmod_content(App $a)
99 {
100         if (!local_user()) {
101                 info(L10n::t('Please login.') . EOL);
102                 $o = '<br /><br />' . Login::form($a->query_string, Config::get('config', 'register_policy') === REGISTER_CLOSED ? 0 : 1);
103                 return $o;
104         }
105
106         if ((!is_site_admin()) || (x($_SESSION, 'submanage') && intval($_SESSION['submanage']))) {
107                 notice(L10n::t('Permission denied.') . EOL);
108                 return '';
109         }
110
111         if ($a->argc != 3) {
112                 killme();
113         }
114
115         $cmd = $a->argv[1];
116         $hash = $a->argv[2];
117
118         if ($cmd === 'deny') {
119                 user_deny($hash);
120                 goaway(System::baseUrl() . "/admin/users/");
121                 killme();
122         }
123
124         if ($cmd === 'allow') {
125                 user_allow($hash);
126                 goaway(System::baseUrl() . "/admin/users/");
127                 killme();
128         }
129 }