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