2010-07-01 23:48:07 +00:00
|
|
|
<?php
|
|
|
|
|
2012-10-26 01:42:42 +00:00
|
|
|
|
|
|
|
function register_init(&$a) {
|
|
|
|
|
|
|
|
$result = null;
|
|
|
|
$cmd = ((argc() > 1) ? argv(1) : '');
|
|
|
|
|
2013-11-20 23:20:12 +00:00
|
|
|
// Provide a stored request for somebody desiring a connection
|
|
|
|
// when they first need to register someplace. Once they've
|
|
|
|
// created a channel, we'll try to revive the connection request
|
|
|
|
// and process it.
|
|
|
|
|
|
|
|
if($_REQUEST['connect'])
|
|
|
|
$_SESSION['connect'] = $_REQUEST['connect'];
|
|
|
|
|
2012-10-26 01:42:42 +00:00
|
|
|
switch($cmd) {
|
|
|
|
case 'invite_check.json':
|
|
|
|
$result = check_account_invite($_REQUEST['invite_code']);
|
|
|
|
break;
|
|
|
|
case 'email_check.json':
|
|
|
|
$result = check_account_email($_REQUEST['email']);
|
|
|
|
break;
|
|
|
|
case 'password_check.json':
|
|
|
|
$result = check_account_password($_REQUEST['password']);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if($result) {
|
|
|
|
json_return_and_die($result);
|
|
|
|
}
|
|
|
|
}
|
2011-05-24 03:30:37 +00:00
|
|
|
|
2010-07-01 23:48:07 +00:00
|
|
|
|
2012-10-26 01:42:42 +00:00
|
|
|
function register_post(&$a) {
|
2011-12-21 04:12:29 +00:00
|
|
|
|
|
|
|
$max_dailies = intval(get_config('system','max_daily_registrations'));
|
2012-10-26 01:42:42 +00:00
|
|
|
if($max_dailies) {
|
2013-02-01 01:55:52 +00:00
|
|
|
$r = q("select count(account_id) as total from account where account_created > UTC_TIMESTAMP() - INTERVAL 1 day");
|
2011-12-21 04:12:29 +00:00
|
|
|
if($r && $r[0]['total'] >= $max_dailies) {
|
2012-10-26 01:42:42 +00:00
|
|
|
notice( t('Maximum daily site registrations exceeded. Please try again tomorrow.') . EOL);
|
2011-12-21 04:12:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-26 01:42:42 +00:00
|
|
|
if(! x($_POST,'tos')) {
|
|
|
|
notice( t('Please indicate acceptance of the Terms of Service. Registration failed.') . EOL);
|
|
|
|
return;
|
2010-07-01 23:48:07 +00:00
|
|
|
}
|
|
|
|
|
2013-01-03 21:50:23 +00:00
|
|
|
$policy = get_config('system','register_policy');
|
2010-08-12 22:44:13 +00:00
|
|
|
|
2014-07-10 04:10:56 +00:00
|
|
|
$email_verify = get_config('system','verify_email');
|
|
|
|
|
|
|
|
|
2012-10-26 01:42:42 +00:00
|
|
|
switch($policy) {
|
2012-06-01 22:42:13 +00:00
|
|
|
|
2012-10-26 01:42:42 +00:00
|
|
|
case REGISTER_OPEN:
|
2014-07-10 04:10:56 +00:00
|
|
|
$flags = ACCOUNT_OK;
|
2012-10-26 01:42:42 +00:00
|
|
|
break;
|
2012-06-01 22:42:13 +00:00
|
|
|
|
2012-10-26 01:42:42 +00:00
|
|
|
case REGISTER_APPROVE:
|
2014-07-10 04:10:56 +00:00
|
|
|
$flags = ACCOUNT_BLOCKED | ACCOUNT_PENDING;
|
2012-10-26 01:42:42 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
case REGISTER_CLOSED:
|
|
|
|
if(! is_site_admin()) {
|
|
|
|
notice( t('Permission denied.') . EOL );
|
|
|
|
return;
|
|
|
|
}
|
2014-07-10 04:10:56 +00:00
|
|
|
$flags = ACCOUNT_BLOCKED;
|
2012-10-26 01:42:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-07-10 04:13:48 +00:00
|
|
|
if($email_verify && $policy == REGISTER_OPEN)
|
2014-07-10 04:10:56 +00:00
|
|
|
$flags = $flags | ACCOUNT_UNVERIFIED;
|
|
|
|
|
2013-09-05 05:23:53 +00:00
|
|
|
|
|
|
|
if((! $_POST['password']) || ($_POST['password'] !== $_POST['password2'])) {
|
|
|
|
notice( t('Passwords do not match.') . EOL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-26 01:42:42 +00:00
|
|
|
$arr = $_POST;
|
|
|
|
$arr['account_flags'] = $flags;
|
|
|
|
|
|
|
|
$result = create_account($arr);
|
2011-01-05 07:18:52 +00:00
|
|
|
|
2012-06-01 02:06:17 +00:00
|
|
|
if(! $result['success']) {
|
|
|
|
notice($result['message']);
|
2010-07-01 23:48:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-10-26 01:42:42 +00:00
|
|
|
require_once('include/security.php');
|
2010-07-01 23:48:07 +00:00
|
|
|
|
2011-02-23 22:04:00 +00:00
|
|
|
|
2012-10-26 01:42:42 +00:00
|
|
|
$using_invites = intval(get_config('system','invitation_only'));
|
|
|
|
$num_invites = intval(get_config('system','number_invites'));
|
|
|
|
$invite_code = ((x($_POST,'invite_code')) ? notags(trim($_POST['invite_code'])) : '');
|
2011-07-20 06:10:09 +00:00
|
|
|
|
2012-10-26 01:42:42 +00:00
|
|
|
if($using_invites && $invite_code) {
|
|
|
|
q("delete * from register where hash = '%s' limit 1", dbesc($invite_code));
|
|
|
|
set_pconfig($result['account']['account_id'],'system','invites_remaining',$num_invites);
|
|
|
|
}
|
2011-07-18 04:12:31 +00:00
|
|
|
|
2012-10-26 01:42:42 +00:00
|
|
|
if($policy == REGISTER_OPEN ) {
|
2014-07-10 04:10:56 +00:00
|
|
|
if($email_verify) {
|
|
|
|
$res = verify_email_address($result);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$res = send_verification_email($result['email'],$result['password']);
|
|
|
|
}
|
2012-10-26 01:42:42 +00:00
|
|
|
if($res) {
|
|
|
|
info( t('Registration successful. Please check your email for validation instructions.') . EOL ) ;
|
2011-07-18 04:12:31 +00:00
|
|
|
}
|
2012-10-26 01:42:42 +00:00
|
|
|
}
|
|
|
|
elseif($policy == REGISTER_APPROVE) {
|
|
|
|
$res = send_reg_approval_email($result);
|
2010-07-29 06:15:10 +00:00
|
|
|
if($res) {
|
2012-10-26 01:42:42 +00:00
|
|
|
info( t('Your registration is pending approval by the site owner.') . EOL ) ;
|
2010-07-29 06:15:10 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
notice( t('Your registration can not be processed.') . EOL);
|
|
|
|
}
|
2012-10-26 01:42:42 +00:00
|
|
|
goaway(z_root());
|
|
|
|
}
|
2010-07-29 06:15:10 +00:00
|
|
|
|
2014-07-10 04:10:56 +00:00
|
|
|
if($email_verify) {
|
|
|
|
goaway(z_root());
|
|
|
|
}
|
|
|
|
|
2012-10-26 01:42:42 +00:00
|
|
|
authenticate_success($result['account'],true,false,true);
|
2010-07-29 06:15:10 +00:00
|
|
|
|
2012-10-26 01:42:42 +00:00
|
|
|
if(! strlen($next_page = get_config('system','workflow_register_next')))
|
2012-10-30 04:59:49 +00:00
|
|
|
$next_page = 'new_channel';
|
2011-05-24 03:30:37 +00:00
|
|
|
|
2012-10-26 01:42:42 +00:00
|
|
|
$_SESSION['workflow'] = true;
|
|
|
|
|
|
|
|
goaway(z_root() . '/' . $next_page);
|
2010-07-29 06:15:10 +00:00
|
|
|
|
2012-10-26 01:42:42 +00:00
|
|
|
}
|
2011-02-23 09:37:15 +00:00
|
|
|
|
2010-07-01 23:48:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function register_content(&$a) {
|
|
|
|
|
2013-12-26 00:53:59 +00:00
|
|
|
$registration_is = '';
|
|
|
|
$other_sites = '';
|
2011-12-10 00:50:13 +00:00
|
|
|
|
2012-10-26 01:42:42 +00:00
|
|
|
if(get_config('system','register_policy') == REGISTER_CLOSED) {
|
2013-12-23 04:07:18 +00:00
|
|
|
require_once('mod/pubsites.php');
|
|
|
|
return pubsites_content($a);
|
2010-07-11 10:35:33 +00:00
|
|
|
}
|
|
|
|
|
2013-12-26 00:53:59 +00:00
|
|
|
if(get_config('system','register_policy') == REGISTER_APPROVE) {
|
|
|
|
$registration_is = t('Registration on this site/hub is by approval only.');
|
|
|
|
$other_sites = t('<a href="pubsites">Register at another affiliated site/hub</a>');
|
|
|
|
}
|
|
|
|
|
2011-12-21 04:12:29 +00:00
|
|
|
$max_dailies = intval(get_config('system','max_daily_registrations'));
|
2012-10-26 01:42:42 +00:00
|
|
|
if($max_dailies) {
|
2013-02-01 01:55:52 +00:00
|
|
|
$r = q("select count(account_id) as total from account where account_created > UTC_TIMESTAMP() - INTERVAL 1 day");
|
2011-12-21 04:12:29 +00:00
|
|
|
if($r && $r[0]['total'] >= $max_dailies) {
|
|
|
|
logger('max daily registrations exceeded.');
|
|
|
|
notice( t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-26 01:42:42 +00:00
|
|
|
// Configurable terms of service link
|
2011-01-07 12:33:34 +00:00
|
|
|
|
2012-10-26 01:42:42 +00:00
|
|
|
$tosurl = get_config('system','tos_url');
|
|
|
|
if(! $tosurl)
|
|
|
|
$tosurl = $a->get_baseurl() . '/help/TermsOfService';
|
2011-01-07 12:33:34 +00:00
|
|
|
|
2012-10-26 01:42:42 +00:00
|
|
|
$toslink = '<a href="' . $tosurl . '" >' . t('Terms of Service') . '</a>';
|
2010-11-16 04:10:19 +00:00
|
|
|
|
2012-10-26 01:42:42 +00:00
|
|
|
// Configurable whether to restrict age or not - default is based on international legal requirements
|
|
|
|
// This can be relaxed if you are on a restricted server that does not share with public servers
|
2010-11-29 04:58:23 +00:00
|
|
|
|
2012-10-26 01:42:42 +00:00
|
|
|
if(get_config('system','no_age_restriction'))
|
|
|
|
$label_tos = sprintf( t('I accept the %s for this website'), $toslink);
|
|
|
|
else
|
|
|
|
$label_tos = sprintf( t('I am over 13 years of age and accept the %s for this website'), $toslink);
|
2011-03-11 22:48:58 +00:00
|
|
|
|
2012-10-26 01:42:42 +00:00
|
|
|
$enable_tos = 1 - intval(get_config('system','no_termsofservice'));
|
|
|
|
|
|
|
|
$email = ((x($_REQUEST,'email')) ? strip_tags(trim($_REQUEST['email'])) : "" );
|
|
|
|
$password = ((x($_REQUEST,'password')) ? trim($_REQUEST['password']) : "" );
|
|
|
|
$password2 = ((x($_REQUEST,'password2')) ? trim($_REQUEST['password2']) : "" );
|
|
|
|
$invite_code = ((x($_REQUEST,'invite_code')) ? strip_tags(trim($_REQUEST['invite_code'])) : "" );
|
2011-03-08 12:06:37 +00:00
|
|
|
|
2011-02-22 00:50:06 +00:00
|
|
|
|
2014-09-12 03:03:36 +00:00
|
|
|
require_once('include/bbcode.php');
|
2013-12-26 00:53:59 +00:00
|
|
|
|
2012-10-26 01:42:42 +00:00
|
|
|
$o = replace_macros(get_markup_template('register.tpl'), array(
|
2011-02-22 00:50:06 +00:00
|
|
|
|
2012-10-26 01:42:42 +00:00
|
|
|
'$title' => t('Registration'),
|
2013-12-26 00:53:59 +00:00
|
|
|
'$reg_is' => $registration_is,
|
2014-09-12 03:03:36 +00:00
|
|
|
'$registertext' => bbcode(get_config('system','register_text')),
|
2013-12-26 00:53:59 +00:00
|
|
|
'$other_sites' => $other_sites,
|
2012-10-26 01:42:42 +00:00
|
|
|
'$invitations' => get_config('system','invitation_only'),
|
|
|
|
'$invite_desc' => t('Membership on this site is by invitation only.'),
|
|
|
|
'$label_invite' => t('Please enter your invitation code'),
|
|
|
|
'$invite_code' => $invite_code,
|
|
|
|
|
|
|
|
'$label_email' => t('Your email address'),
|
|
|
|
'$label_pass1' => t('Choose a password'),
|
|
|
|
'$label_pass2' => t('Please re-enter your password'),
|
|
|
|
'$label_tos' => $label_tos,
|
|
|
|
'$enable_tos' => $enable_tos,
|
|
|
|
'$email' => $email,
|
|
|
|
'$pass1' => $password,
|
|
|
|
'$pass2' => $password2,
|
|
|
|
'$submit' => t('Register')
|
2010-07-20 02:09:58 +00:00
|
|
|
));
|
2012-10-26 01:42:42 +00:00
|
|
|
|
2010-07-01 23:48:07 +00:00
|
|
|
return $o;
|
|
|
|
|
2012-10-26 01:42:42 +00:00
|
|
|
}
|
2010-07-01 23:48:07 +00:00
|
|
|
|