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