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