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