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