]> git.mxchange.org Git - friendica.git/blob - mod/regmod.php
Merge pull request #3149 from annando/1601-new-diaspora-mention
[friendica.git] / mod / regmod.php
1 <?php
2
3 require_once('include/enotify.php');
4 require_once('include/user.php');
5
6 function user_allow($hash) {
7
8         $a = get_app();
9
10         $register = q("SELECT * FROM `register` WHERE `hash` = '%s' LIMIT 1",
11                 dbesc($hash)
12         );
13
14
15         if (! dbm::is_result($register)) {
16                 return false;
17         }
18
19         $user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
20                 intval($register[0]['uid'])
21         );
22
23         if (! dbm::is_result($user)) {
24                 killme();
25         }
26
27         $r = q("DELETE FROM `register` WHERE `hash` = '%s'",
28                 dbesc($register[0]['hash'])
29         );
30
31
32         $r = q("UPDATE `user` SET `blocked` = 0, `verified` = 1 WHERE `uid` = %d",
33                 intval($register[0]['uid'])
34         );
35
36         $r = q("SELECT * FROM `profile` WHERE `uid` = %d AND `is-default` = 1",
37                 intval($user[0]['uid'])
38         );
39         if (dbm::is_result($r) && $r[0]['net-publish']) {
40                 $url = App::get_baseurl() . '/profile/' . $user[0]['nickname'];
41                 if ($url && strlen(get_config('system','directory'))) {
42                         proc_run(PRIORITY_LOW, "include/directory.php", $url);
43                 }
44         }
45
46         push_lang($register[0]['language']);
47
48         send_register_open_eml(
49                 $user[0]['email'],
50                 $a->config['sitename'],
51                 App::get_baseurl(),
52                 $user[0]['username'],
53                 $register[0]['password']);
54
55         pop_lang();
56
57         if($res) {
58                 info( t('Account approved.') . EOL );
59                 return true;
60         }
61
62 }
63
64
65 // This does not have to go through user_remove() and save the nickname
66 // permanently against re-registration, as the person was not yet
67 // allowed to have friends on this system
68
69 function user_deny($hash) {
70
71         $register = q("SELECT * FROM `register` WHERE `hash` = '%s' LIMIT 1",
72                 dbesc($hash)
73         );
74
75         if(! dbm::is_result($register))
76                 return false;
77
78         $user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
79                 intval($register[0]['uid'])
80         );
81
82         $r = q("DELETE FROM `user` WHERE `uid` = %d",
83                 intval($register[0]['uid'])
84         );
85         $r = q("DELETE FROM `contact` WHERE `uid` = %d",
86                 intval($register[0]['uid'])
87         );
88         $r = q("DELETE FROM `profile` WHERE `uid` = %d",
89                 intval($register[0]['uid'])
90         );
91
92         $r = q("DELETE FROM `register` WHERE `hash` = '%s'",
93                 dbesc($register[0]['hash'])
94         );
95         notice( sprintf(t('Registration revoked for %s'), $user[0]['username']) . EOL);
96         return true;
97
98 }
99
100 function regmod_content(App $a) {
101
102         global $lang;
103
104         $_SESSION['return_url'] = $a->cmd;
105
106         if (! local_user()) {
107                 info( t('Please login.') . EOL);
108                 $o .= '<br /><br />' . login(($a->config['register_policy'] == REGISTER_CLOSED) ? 0 : 1);
109                 return $o;
110         }
111
112         if ((!is_site_admin()) || (x($_SESSION,'submanage') && intval($_SESSION['submanage']))) {
113                 notice( t('Permission denied.') . EOL);
114                 return '';
115         }
116
117         if ($a->argc != 3) {
118                 killme();
119         }
120
121         $cmd  = $a->argv[1];
122         $hash = $a->argv[2];
123
124
125
126         if ($cmd === 'deny') {
127                 user_deny($hash);
128                 goaway(App::get_baseurl()."/admin/users/");
129                 killme();
130         }
131
132         if ($cmd === 'allow') {
133                 user_allow($hash);
134                 goaway(App::get_baseurl()."/admin/users/");
135                 killme();
136         }
137 }