]> git.mxchange.org Git - friendica.git/blob - mod/regmod.php
Merge pull request #4031 from MrPetovan/task/3878-move-objects-to-model
[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 use Friendica\Model\User;
9
10 require_once 'include/enotify.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         User::sendRegisterOpenEmail(
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 // This does not have to go through user_remove() and save the nickname
70 // permanently against re-registration, as the person was not yet
71 // allowed to have friends on this system
72 function user_deny($hash)
73 {
74         $register = q("SELECT * FROM `register` WHERE `hash` = '%s' LIMIT 1",
75                 dbesc($hash)
76         );
77
78         if (!DBM::is_result($register)) {
79                 return false;
80         }
81
82         $user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
83                 intval($register[0]['uid'])
84         );
85
86         dba::delete('user', array('uid' => $register[0]['uid']));
87         dba::delete('register', array('hash' => $register[0]['hash']));
88
89         notice(sprintf(t('Registration revoked for %s'), $user[0]['username']) . EOL);
90         return true;
91 }
92
93 function regmod_content(App $a)
94 {
95         global $lang;
96
97         $_SESSION['return_url'] = $a->cmd;
98
99         if (!local_user()) {
100                 info(t('Please login.') . EOL);
101                 $o .= '<br /><br />' . login(($a->config['register_policy'] == REGISTER_CLOSED) ? 0 : 1);
102                 return $o;
103         }
104
105         if ((!is_site_admin()) || (x($_SESSION, 'submanage') && intval($_SESSION['submanage']))) {
106                 notice(t('Permission denied.') . EOL);
107                 return '';
108         }
109
110         if ($a->argc != 3) {
111                 killme();
112         }
113
114         $cmd = $a->argv[1];
115         $hash = $a->argv[2];
116
117         if ($cmd === 'deny') {
118                 user_deny($hash);
119                 goaway(System::baseUrl() . "/admin/users/");
120                 killme();
121         }
122
123         if ($cmd === 'allow') {
124                 user_allow($hash);
125                 goaway(System::baseUrl() . "/admin/users/");
126                 killme();
127         }
128 }