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