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