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