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