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