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