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