]> git.mxchange.org Git - friendica.git/blob - mod/regmod.php
stronger type checking on comparisons
[friendica.git] / mod / regmod.php
1 <?php
2
3
4
5 function regmod_content(&$a) {
6
7         if(! local_user()) {
8                 notice( t('Please login.') . EOL);
9                 $o .= '<br /><br />' . login(($a->config['register_policy'] == REGISTER_CLOSED) ? 0 : 1);
10                 return $o;
11         }
12
13         if($a->argc != 3)
14                 killme();
15
16         $cmd = $a->argv[1];
17         $hash = $a->argv[2];
18
19
20         $register = q("SELECT * FROM `register` WHERE `hash` = '%s' LIMIT 1",
21                 dbesc($hash)
22         );
23
24
25         if(! count($register))
26                 killme();
27
28         $user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
29                 intval($register[0]['uid'])
30         );
31
32         if($cmd === 'deny') {
33
34                 $r = q("DELETE FROM `user` WHERE `uid` = %d LIMIT 1",
35                         intval($register[0]['uid'])
36                 );
37                 $r = q("DELETE FROM `contact` WHERE `uid` = %d LIMIT 1",
38                         intval($register[0]['uid'])
39                 ); 
40                 $r = q("DELETE FROM `profile` WHERE `uid` = %d LIMIT 1",
41                         intval($register[0]['uid'])
42                 ); 
43
44                 $r = q("DELETE FROM `register` WHERE `hash` = '%s' LIMIT 1",
45                         dbesc($register[0]['hash'])
46                 );
47                 notice( t('Registration revoked for ') . $user[0]['username'] . EOL);
48                 return;
49
50         }
51
52         if($cmd === 'allow') {
53
54                 if(! count($user))
55                         killme();
56
57                 $r = q("DELETE FROM `register` WHERE `hash` = '%s' LIMIT 1",
58                         dbesc($register[0]['hash'])
59                 );
60
61
62                 $r = q("UPDATE `user` SET `blocked` = 0, `verified` = 1 WHERE `uid` = %d LIMIT 1",
63                         intval($register[0]['uid'])
64                 );
65                 
66                 $email_tpl = load_view_file("view/register_open_eml.tpl");
67                 $email_tpl = replace_macros($email_tpl, array(
68                                 '$sitename' => $a->config['sitename'],
69                                 '$siteurl' =>  $a->get_baseurl(),
70                                 '$username' => $user[0]['username'],
71                                 '$email' => $user[0]['email'],
72                                 '$password' => $register[0]['password'],
73                                 '$uid' => $user[0]['uid']
74                 ));
75
76                 $res = mail($user[0]['email'], t('Registration details for '). $a->config['sitename'],
77                         $email_tpl,'From: ' . t('Administrator@') . $_SERVER[SERVER_NAME] );
78
79                 if($res) {
80                         notice( t('Account approved.') . EOL );
81                         return;
82                 }
83         }
84 }