]> git.mxchange.org Git - friendica.git/blob - mod/regmod.php
76ea4062ede8becd5789b1b54a8f3324ce4148ee
[friendica.git] / mod / regmod.php
1 <?php
2
3 function user_allow($hash) {
4
5         $a = get_app();
6
7         $register = q("SELECT * FROM `register` WHERE `hash` = '%s' LIMIT 1",
8                 dbesc($hash)
9         );
10
11
12         if(! count($register))
13                 return false;
14
15         $user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
16                 intval($register[0]['uid'])
17         );
18         
19         if(! count($user))
20                 killme();
21
22         $r = q("DELETE FROM `register` WHERE `hash` = '%s' LIMIT 1",
23                 dbesc($register[0]['hash'])
24         );
25
26
27         $r = q("UPDATE `user` SET `blocked` = 0, `verified` = 1 WHERE `uid` = %d LIMIT 1",
28                 intval($register[0]['uid'])
29         );
30         
31         $r = q("SELECT * FROM `profile` WHERE `uid` = %d AND `is-default` = 1",
32                 intval($user[0]['uid'])
33         );
34         if(count($r) && $r[0]['net-publish']) {
35                 $url = $a->get_baseurl() . '/profile/' . $user[0]['nickname'];
36                 if($url && strlen(get_config('system','directory_submit_url')))
37                         proc_run('php',"include/directory.php","$url");
38         }
39
40         push_lang($register[0]['language']);
41
42         $email_tpl = get_intltext_template("register_open_eml.tpl");
43         $email_tpl = replace_macros($email_tpl, array(
44                         '$sitename' => $a->config['sitename'],
45                         '$siteurl' =>  $a->get_baseurl(),
46                         '$username' => $user[0]['username'],
47                         '$email' => $user[0]['email'],
48                         '$password' => $register[0]['password'],
49                         '$uid' => $user[0]['uid']
50         ));
51
52         $res = mail($user[0]['email'], sprintf(t('Registration details for %s'), $a->config['sitename']),
53                 $email_tpl,
54                         'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n"
55                         . 'Content-type: text/plain; charset=UTF-8' . "\n"
56                         . 'Content-transfer-encoding: 8bit' );
57
58         pop_lang();
59
60         if($res) {
61                 info( t('Account approved.') . EOL );
62                 return true;
63         }       
64
65 }
66
67 function user_deny($hash) {
68
69         $register = q("SELECT * FROM `register` WHERE `hash` = '%s' LIMIT 1",
70                 dbesc($hash)
71         );
72
73         if(! count($register))
74                 return false;
75
76         $user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
77                 intval($register[0]['uid'])
78         );
79         
80         $r = q("DELETE FROM `user` WHERE `uid` = %d LIMIT 1",
81                 intval($register[0]['uid'])
82         );
83         $r = q("DELETE FROM `contact` WHERE `uid` = %d LIMIT 1",
84                 intval($register[0]['uid'])
85         ); 
86         $r = q("DELETE FROM `profile` WHERE `uid` = %d LIMIT 1",
87                 intval($register[0]['uid'])
88         ); 
89
90         $r = q("DELETE FROM `register` WHERE `hash` = '%s' LIMIT 1",
91                 dbesc($register[0]['hash'])
92         );
93         notice( sprintf(t('Registration revoked for %s'), $user[0]['username']) . EOL);
94         return true;
95         
96 }
97
98 function regmod_content(&$a) {
99
100         global $lang;
101
102         $_SESSION['return_url'] = $a->cmd;
103
104         if(! local_user()) {
105                 info( t('Please login.') . EOL);
106                 $o .= '<br /><br />' . login(($a->config['register_policy'] == REGISTER_CLOSED) ? 0 : 1);
107                 return $o;
108         }
109
110         if(!is_site_admin()) {
111                 notice( t('Permission denied.') . EOL);
112                 return '';
113         }
114
115         if($a->argc != 3)
116                 killme();
117
118         $cmd  = $a->argv[1];
119         $hash = $a->argv[2];
120
121
122
123         if($cmd === 'deny') {
124                 if (!user_deny($hash)) killme();
125         }
126
127         if($cmd === 'allow') {
128                 if (!user_allow($hash)) killme();
129         }
130 }