]> git.mxchange.org Git - friendica.git/blob - mod/register.php
Merge remote-tracking branch 'upstream/develop' into develop
[friendica.git] / mod / register.php
1 <?php
2
3 use Friendica\App;
4 use Friendica\Core\Config;
5 use Friendica\Core\PConfig;
6 use Friendica\Core\System;
7 use Friendica\Core\Worker;
8 use Friendica\Model\User;
9
10 require_once 'include/enotify.php';
11 require_once 'include/bbcode.php';
12
13 if(! function_exists('register_post')) {
14 function register_post(App $a) {
15         check_form_security_token_redirectOnErr('/register', 'register');
16
17         global $lang;
18
19         $verified = 0;
20         $blocked  = 1;
21
22         $arr = array('post' => $_POST);
23         call_hooks('register_post', $arr);
24
25         $max_dailies = intval(Config::get('system','max_daily_registrations'));
26         if($max_dailies) {
27                 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
28                 if($r && $r[0]['total'] >= $max_dailies) {
29                         return;
30                 }
31         }
32
33         switch($a->config['register_policy']) {
34
35
36         case REGISTER_OPEN:
37                 $blocked = 0;
38                 $verified = 1;
39                 break;
40
41         case REGISTER_APPROVE:
42                 $blocked = 1;
43                 $verified = 0;
44                 break;
45
46         default:
47         case REGISTER_CLOSED:
48                 if((! x($_SESSION,'authenticated') && (! x($_SESSION,'administrator')))) {
49                         notice( t('Permission denied.') . EOL );
50                         return;
51                 }
52                 $blocked = 1;
53                 $verified = 0;
54                 break;
55         }
56
57
58         $arr = $_POST;
59
60         $arr['blocked'] = $blocked;
61         $arr['verified'] = $verified;
62         $arr['language'] = get_browser_language();
63
64         $result = User::create($arr);
65
66         if(! $result['success']) {
67                 notice($result['message']);
68                 return;
69         }
70
71         $user = $result['user'];
72
73         if($netpublish && $a->config['register_policy'] != REGISTER_APPROVE) {
74                 $url = System::baseUrl() . '/profile/' . $user['nickname'];
75                 Worker::add(PRIORITY_LOW, "Directory", $url);
76         }
77
78         $using_invites = Config::get('system','invitation_only');
79         $num_invites   = Config::get('system','number_invites');
80         $invite_id  = ((x($_POST,'invite_id'))  ? notags(trim($_POST['invite_id']))  : '');
81
82
83         if( $a->config['register_policy'] == REGISTER_OPEN ) {
84
85                 if($using_invites && $invite_id) {
86                         q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
87                         PConfig::set($user['uid'],'system','invites_remaining',$num_invites);
88                 }
89
90                 // Only send a password mail when the password wasn't manually provided
91                 if (!x($_POST,'password1') || !x($_POST,'confirm')) {
92                         $res = User::sendRegisterOpenEmail(
93                                 $user['email'],
94                                 $a->config['sitename'],
95                                 System::baseUrl(),
96                                 $user['username'],
97                                 $result['password']);
98
99                         if($res) {
100                                 info( t('Registration successful. Please check your email for further instructions.') . EOL ) ;
101                                 goaway(System::baseUrl());
102                         } else {
103                                 notice(
104                                         sprintf(
105                                                 t('Failed to send email message. Here your accout details:<br> login: %s<br> password: %s<br><br>You can change your password after login.'),
106                                                  $user['email'],
107                                                  $result['password']
108                                                  ). EOL
109                                 );
110                         }
111                 } else {
112                         info( t('Registration successful.') . EOL ) ;
113                         goaway(System::baseUrl());
114                 }
115         }
116         elseif($a->config['register_policy'] == REGISTER_APPROVE) {
117                 if(! strlen($a->config['admin_email'])) {
118                         notice( t('Your registration can not be processed.') . EOL);
119                         goaway(System::baseUrl());
120                 }
121
122                 $hash = random_string();
123                 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password`, `language`, `note` ) VALUES ( '%s', '%s', %d, '%s', '%s', '%s' ) ",
124                         dbesc($hash),
125                         dbesc(datetime_convert()),
126                         intval($user['uid']),
127                         dbesc($result['password']),
128                         dbesc($lang),
129                         dbesc($_POST['permonlybox'])
130                 );
131
132                 // invite system
133                 if($using_invites && $invite_id) {
134                         q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
135                         PConfig::set($user['uid'],'system','invites_remaining',$num_invites);
136                 }
137
138                 // send email to admins
139                 $admin_mail_list = "'".implode("','", array_map(dbesc, explode(",", str_replace(" ", "", $a->config['admin_email']))))."'";
140                 $adminlist = q("SELECT uid, language, email FROM user WHERE email IN (%s)",
141                         $admin_mail_list
142                 );
143
144                 // send notification to admins
145                 foreach ($adminlist as $admin) {
146                         notification(array(
147                                 'type' => NOTIFY_SYSTEM,
148                                 'event' => 'SYSTEM_REGISTER_REQUEST',
149                                 'source_name' => $user['username'],
150                                 'source_mail' => $user['email'],
151                                 'source_nick' => $user['nickname'],
152                                 'source_link' => System::baseUrl()."/admin/users/",
153                                 'link' => System::baseUrl()."/admin/users/",
154                                 'source_photo' => System::baseUrl() . "/photo/avatar/".$user['uid'].".jpg",
155                                 'to_email' => $admin['email'],
156                                 'uid' => $admin['uid'],
157                                 'language' => ($admin['language']?$admin['language']:'en'),
158                                 'show_in_notification_page' => false
159                         ));
160                 }
161                 // send notification to the user, that the registration is pending
162                 User::sendRegisterPendingEmail(
163                                 $user['email'],
164                                 $a->config['sitename'],
165                                 $user['username']);
166
167                 info( t('Your registration is pending approval by the site owner.') . EOL ) ;
168                 goaway(System::baseUrl());
169
170
171         }
172
173         return;
174 }}
175
176
177
178
179
180
181 if(! function_exists('register_content')) {
182 function register_content(App $a) {
183
184         // logged in users can register others (people/pages/groups)
185         // even with closed registrations, unless specifically prohibited by site policy.
186         // 'block_extended_register' blocks all registrations, period.
187
188         $block = Config::get('system','block_extended_register');
189
190         if(local_user() && ($block)) {
191                 notice("Permission denied." . EOL);
192                 return;
193         }
194
195         if((! local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) {
196                 notice("Permission denied." . EOL);
197                 return;
198         }
199
200         $max_dailies = intval(Config::get('system','max_daily_registrations'));
201         if($max_dailies) {
202                 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
203                 if($r && $r[0]['total'] >= $max_dailies) {
204                         logger('max daily registrations exceeded.');
205                         notice( t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL);
206                         return;
207                 }
208         }
209
210         if(x($_SESSION,'theme'))
211                 unset($_SESSION['theme']);
212         if(x($_SESSION,'mobile-theme'))
213                 unset($_SESSION['mobile-theme']);
214
215
216         $username     = ((x($_POST,'username'))     ? $_POST['username']     : ((x($_GET,'username'))     ? $_GET['username']              : ''));
217         $email        = ((x($_POST,'email'))        ? $_POST['email']        : ((x($_GET,'email'))        ? $_GET['email']                 : ''));
218         $openid_url   = ((x($_POST,'openid_url'))   ? $_POST['openid_url']   : ((x($_GET,'openid_url'))   ? $_GET['openid_url']            : ''));
219         $nickname     = ((x($_POST,'nickname'))     ? $_POST['nickname']     : ((x($_GET,'nickname'))     ? $_GET['nickname']              : ''));
220         $photo        = ((x($_POST,'photo'))        ? $_POST['photo']        : ((x($_GET,'photo'))        ? hex2bin($_GET['photo'])        : ''));
221         $invite_id    = ((x($_POST,'invite_id'))    ? $_POST['invite_id']    : ((x($_GET,'invite_id'))    ? $_GET['invite_id']             : ''));
222
223         $noid = Config::get('system','no_openid');
224
225         if($noid) {
226                 $oidhtml = '';
227                 $fillwith = '';
228                 $fillext = '';
229                 $oidlabel = '';
230         }
231         else {
232                 $oidhtml = '<label for="register-openid" id="label-register-openid" >$oidlabel</label><input type="text" maxlength="60" size="32" name="openid_url" class="openid" id="register-openid" value="$openid" >';
233                 $fillwith = t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
234                 $fillext =  t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
235                 $oidlabel = t("Your OpenID \x28optional\x29: ");
236         }
237
238         // I set this and got even more fake names than before...
239
240         $realpeople = ''; // t('Members of this network prefer to communicate with real people who use their real names.');
241
242         if(Config::get('system','publish_all')) {
243                 $profile_publish_reg = '<input type="hidden" name="profile_publish_reg" value="1" />';
244         }
245         else {
246                 $publish_tpl = get_markup_template("profile_publish.tpl");
247                 $profile_publish = replace_macros($publish_tpl,array(
248                         '$instance'     => 'reg',
249                         '$pubdesc'      => t('Include your profile in member directory?'),
250                         '$yes_selected' => ' checked="checked" ',
251                         '$no_selected'  => '',
252                         '$str_yes'      => t('Yes'),
253                         '$str_no'       => t('No'),
254                 ));
255         }
256
257         $r = q("SELECT count(*) AS `contacts` FROM `contact`");
258         $passwords = !$r[0]["contacts"];
259
260         $license = '';
261
262         $o = get_markup_template("register.tpl");
263
264         $arr = array('template' => $o);
265
266         call_hooks('register_form',$arr);
267
268         $o = $arr['template'];
269
270         $o = replace_macros($o, array(
271                 '$oidhtml' => $oidhtml,
272                 '$invitations' => Config::get('system','invitation_only'),
273                 '$permonly' => $a->config['register_policy'] == REGISTER_APPROVE,
274                 '$permonlybox' => array('permonlybox', t('Note for the admin'), '', t('Leave a message for the admin, why you want to join this node')),
275                 '$invite_desc' => t('Membership on this site is by invitation only.'),
276                 '$invite_label' => t('Your invitation ID: '),
277                 '$invite_id' => $invite_id,
278                 '$realpeople' => $realpeople,
279                 '$regtitle'  => t('Registration'),
280                 '$registertext' =>((x($a->config,'register_text'))
281                         ? bbcode($a->config['register_text'])
282                         : "" ),
283                 '$fillwith'  => $fillwith,
284                 '$fillext'   => $fillext,
285                 '$oidlabel'  => $oidlabel,
286                 '$openid'    => $openid_url,
287                 '$namelabel' => t('Your Full Name ' . "\x28" . 'e.g. Joe Smith, real or real-looking' . "\x29" . ': '),
288                 '$addrlabel' => t('Your Email Address: (Initial information will be send there, so this has to be an existing address.)'),
289                 '$passwords' => $passwords,
290                 '$password1' => array('password1', t('New Password:'), '', t('Leave empty for an auto generated password.')),
291                 '$password2' => array('confirm', t('Confirm:'), '', ''),
292                 '$nickdesc'  => str_replace('$sitename',$a->get_hostname(), t('Choose a profile nickname. This must begin with a text character. Your profile address on this site will then be \'<strong>nickname@$sitename</strong>\'.')),
293                 '$nicklabel' => t('Choose a nickname: '),
294                 '$photo'     => $photo,
295                 '$publish'   => $profile_publish,
296                 '$regbutt'   => t('Register'),
297                 '$username'  => $username,
298                 '$email'     => $email,
299                 '$nickname'  => $nickname,
300                 '$license'   => $license,
301                 '$sitename'  => $a->get_hostname(),
302                 '$importh'   => t('Import'),
303                 '$importt'   => t('Import your profile to this friendica instance'),
304                 '$form_security_token'  => get_form_security_token("register")
305         ));
306         return $o;
307
308 }}
309