]> git.mxchange.org Git - friendica.git/blob - mod/regmod.php
Fix formatting and add documentation
[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
9 require_once('include/user.php');
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         send_register_open_eml(
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         $_SESSION['return_url'] = $a->cmd;
99
100         if (!local_user()) {
101                 info(t('Please login.') . EOL);
102                 $o .= '<br /><br />' . login(($a->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(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 }