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