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