]> git.mxchange.org Git - friendica.git/blob - mod/regmod.php
Merge commit 'upstream/master'
[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
68 // This does not have to go through user_remove() and save the nickname
69 // permanently against re-registration, as the person was not yet
70 // allowed to have friends on this system
71
72 function user_deny($hash) {
73
74         $register = q("SELECT * FROM `register` WHERE `hash` = '%s' LIMIT 1",
75                 dbesc($hash)
76         );
77
78         if(! count($register))
79                 return false;
80
81         $user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
82                 intval($register[0]['uid'])
83         );
84         
85         $r = q("DELETE FROM `user` WHERE `uid` = %d LIMIT 1",
86                 intval($register[0]['uid'])
87         );
88         $r = q("DELETE FROM `contact` WHERE `uid` = %d LIMIT 1",
89                 intval($register[0]['uid'])
90         ); 
91         $r = q("DELETE FROM `profile` WHERE `uid` = %d LIMIT 1",
92                 intval($register[0]['uid'])
93         ); 
94
95         $r = q("DELETE FROM `register` WHERE `hash` = '%s' LIMIT 1",
96                 dbesc($register[0]['hash'])
97         );
98         notice( sprintf(t('Registration revoked for %s'), $user[0]['username']) . EOL);
99         return true;
100         
101 }
102
103 function regmod_content(&$a) {
104
105         global $lang;
106
107         $_SESSION['return_url'] = $a->cmd;
108
109         if(! local_user()) {
110                 info( t('Please login.') . EOL);
111                 $o .= '<br /><br />' . login(($a->config['register_policy'] == REGISTER_CLOSED) ? 0 : 1);
112                 return $o;
113         }
114
115         if((!is_site_admin()) || (x($_SESSION,'submanage') && intval($_SESSION['submanage']))) {
116                 notice( t('Permission denied.') . EOL);
117                 return '';
118         }
119
120         if($a->argc != 3)
121                 killme();
122
123         $cmd  = $a->argv[1];
124         $hash = $a->argv[2];
125
126
127
128         if($cmd === 'deny') {
129                 if (!user_deny($hash)) killme();
130         }
131
132         if($cmd === 'allow') {
133                 if (!user_allow($hash)) killme();
134         }
135 }