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