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