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