2012-07-21 23:43:31 +00:00
|
|
|
<?php
|
|
|
|
|
2012-07-22 01:03:22 +00:00
|
|
|
|
|
|
|
function zregister_init(&$a) {
|
2012-07-22 06:17:45 +00:00
|
|
|
$a->page['template'] = 'full';
|
2012-07-23 00:25:26 +00:00
|
|
|
|
|
|
|
$cmd = ((argc() > 1) ? argv(1) : '');
|
|
|
|
|
|
|
|
if($cmd === 'email_check.json') {
|
2012-08-16 06:15:29 +00:00
|
|
|
$result = check_account_email($_REQUEST['email']);
|
2012-08-09 01:50:04 +00:00
|
|
|
json_return_and_die($result);
|
2012-07-23 00:25:26 +00:00
|
|
|
}
|
|
|
|
|
2012-07-23 02:37:15 +00:00
|
|
|
$pw1 = t("Password too short");
|
|
|
|
$pw2 = t("Passwords do not match");
|
|
|
|
|
|
|
|
$a->page['htmlhead'] .= <<< EOT
|
|
|
|
<script>
|
|
|
|
function zFormError(elm,x) {
|
|
|
|
if(x) {
|
|
|
|
$(elm).addClass("zform-error");
|
|
|
|
$(elm).removeClass("zform-ok");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$(elm).addClass("zform-ok");
|
|
|
|
$(elm).removeClass("zform-error");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$(document).ready(function() {
|
|
|
|
$("#zregister-email").blur(function() {
|
|
|
|
var zreg_email = $("#zregister-email").val();
|
|
|
|
$.get("zregister/email_check.json?f=&email=" + encodeURIComponent(zreg_email),function(data) {
|
|
|
|
$("#zregister-email-feedback").html(data.message);
|
|
|
|
zFormError("#zregister-email-feedback",data.error);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$("#zregister-password").blur(function() {
|
|
|
|
if(($("#zregister-password").val()).length < 6 ) {
|
|
|
|
$("#zregister-password-feedback").html("$pw1");
|
|
|
|
zFormError("#zregister-password-feedback",true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$("#zregister-password-feedback").html("");
|
|
|
|
zFormError("#zregister-password-feedback",false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$("#zregister-password2").blur(function() {
|
|
|
|
if($("#zregister-password").val() != $("#zregister-password2").val()) {
|
|
|
|
$("#zregister-password2-feedback").html("$pw2");
|
|
|
|
zFormError("#zregister-password2-feedback",true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$("#zregister-password2-feedback").html("");
|
|
|
|
zFormError("#zregister-password2-feedback",false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
EOT;
|
2012-07-23 00:25:26 +00:00
|
|
|
|
2012-07-22 01:03:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function zregister_post(&$a) {
|
2012-07-21 23:43:31 +00:00
|
|
|
|
|
|
|
$max_dailies = intval(get_config('system','max_daily_registrations'));
|
|
|
|
if($max_dailies) {
|
2012-07-23 00:25:26 +00:00
|
|
|
$r = q("select count(*) as total from account where account_created > UTC_TIMESTAMP - INTERVAL 1 day");
|
2012-07-21 23:43:31 +00:00
|
|
|
if($r && $r[0]['total'] >= $max_dailies) {
|
2012-08-16 04:56:04 +00:00
|
|
|
notice( t('Maximum daily site registrations exceeded. Please try again tomorrow.') . EOL);
|
2012-07-21 23:43:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-16 04:56:04 +00:00
|
|
|
if(! x($_POST,'tos')) {
|
|
|
|
notice( t('Please indicate acceptance of the Terms of Service. Registration failed.') . EOL);
|
|
|
|
return;
|
|
|
|
}
|
2012-07-21 23:43:31 +00:00
|
|
|
|
2012-08-16 04:56:04 +00:00
|
|
|
$policy = get_config('system','register_policy');
|
2012-07-21 23:43:31 +00:00
|
|
|
|
2012-08-16 04:56:04 +00:00
|
|
|
switch($policy) {
|
2012-07-21 23:43:31 +00:00
|
|
|
|
2012-08-16 04:56:04 +00:00
|
|
|
case REGISTER_OPEN:
|
|
|
|
$flags = ACCOUNT_UNVERIFIED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case REGISTER_APPROVE:
|
|
|
|
$flags = ACCOUNT_UNVERIFIED | ACCOUNT_BLOCKED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
case REGISTER_CLOSED:
|
|
|
|
// TODO check against service class and fix this line
|
|
|
|
// if((! x($_SESSION,'authenticated') && (! x($_SESSION,'administrator')))) {
|
|
|
|
// notice( t('Permission denied.') . EOL );
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
$flags = ACCOUNT_UNVERIFIED | ACCOUNT_BLOCKED;
|
|
|
|
break;
|
2012-07-21 23:43:31 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 07:46:20 +00:00
|
|
|
require_once('include/account.php');
|
2012-07-21 23:43:31 +00:00
|
|
|
|
|
|
|
$arr = $_POST;
|
2012-08-16 04:56:04 +00:00
|
|
|
$arr['account_flags'] = $flags;
|
2012-07-21 23:43:31 +00:00
|
|
|
|
2012-07-22 07:46:20 +00:00
|
|
|
$result = create_account($arr);
|
2012-07-21 23:43:31 +00:00
|
|
|
|
|
|
|
if(! $result['success']) {
|
|
|
|
notice($result['message']);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$user = $result['user'];
|
|
|
|
|
|
|
|
$using_invites = get_config('system','invitation_only');
|
|
|
|
$num_invites = get_config('system','number_invites');
|
|
|
|
$invite_id = ((x($_POST,'invite_id')) ? notags(trim($_POST['invite_id'])) : '');
|
|
|
|
|
|
|
|
|
2012-08-16 04:56:04 +00:00
|
|
|
if($policy == REGISTER_OPEN ) {
|
2012-07-21 23:43:31 +00:00
|
|
|
|
|
|
|
if($using_invites && $invite_id) {
|
|
|
|
q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
|
|
|
|
set_pconfig($user['uid'],'system','invites_remaining',$num_invites);
|
|
|
|
}
|
|
|
|
|
|
|
|
$email_tpl = get_intltext_template("register_open_eml.tpl");
|
|
|
|
$email_tpl = replace_macros($email_tpl, array(
|
2012-08-16 04:56:04 +00:00
|
|
|
'$sitename' => $a->config['sitename'],
|
|
|
|
'$siteurl' => $a->get_baseurl(),
|
|
|
|
'$email' => $user['email'],
|
|
|
|
'$password' => $result['password'],
|
|
|
|
));
|
2012-07-21 23:43:31 +00:00
|
|
|
|
|
|
|
$res = mail($user['email'], sprintf(t('Registration details for %s'), $a->config['sitename']),
|
|
|
|
$email_tpl,
|
|
|
|
'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n"
|
|
|
|
. 'Content-type: text/plain; charset=UTF-8' . "\n"
|
|
|
|
. 'Content-transfer-encoding: 8bit' );
|
|
|
|
|
|
|
|
if($res) {
|
2012-08-16 04:56:04 +00:00
|
|
|
info( t('Registration successful. Please check your email for validation instructions.') . EOL ) ;
|
2012-07-21 23:43:31 +00:00
|
|
|
goaway(z_root());
|
|
|
|
}
|
|
|
|
}
|
2012-08-16 04:56:04 +00:00
|
|
|
elseif($policy == REGISTER_APPROVE) {
|
2012-07-22 07:46:20 +00:00
|
|
|
|
2012-07-21 23:43:31 +00:00
|
|
|
if(! strlen($a->config['admin_email'])) {
|
|
|
|
notice( t('Your registration can not be processed.') . EOL);
|
|
|
|
goaway(z_root());
|
|
|
|
}
|
|
|
|
|
|
|
|
$hash = random_string();
|
|
|
|
$r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password`, `language` ) VALUES ( '%s', '%s', %d, '%s', '%s' ) ",
|
|
|
|
dbesc($hash),
|
|
|
|
dbesc(datetime_convert()),
|
|
|
|
intval($user['uid']),
|
|
|
|
dbesc($result['password']),
|
2012-07-22 07:46:20 +00:00
|
|
|
dbesc($a->language)
|
2012-07-21 23:43:31 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$r = q("SELECT `language` FROM `user` WHERE `email` = '%s' LIMIT 1",
|
|
|
|
dbesc($a->config['admin_email'])
|
|
|
|
);
|
|
|
|
if(count($r))
|
|
|
|
push_lang($r[0]['language']);
|
|
|
|
else
|
|
|
|
push_lang('en');
|
|
|
|
|
|
|
|
if($using_invites && $invite_id) {
|
|
|
|
q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
|
|
|
|
set_pconfig($user['uid'],'system','invites_remaining',$num_invites);
|
|
|
|
}
|
|
|
|
|
|
|
|
$email_tpl = get_intltext_template("register_verify_eml.tpl");
|
|
|
|
$email_tpl = replace_macros($email_tpl, array(
|
|
|
|
'$sitename' => $a->config['sitename'],
|
|
|
|
'$siteurl' => $a->get_baseurl(),
|
|
|
|
'$username' => $user['username'],
|
|
|
|
'$email' => $user['email'],
|
|
|
|
'$password' => $result['password'],
|
|
|
|
'$uid' => $user['uid'],
|
|
|
|
'$hash' => $hash
|
|
|
|
));
|
|
|
|
|
|
|
|
$res = mail($a->config['admin_email'], sprintf(t('Registration request at %s'), $a->config['sitename']),
|
|
|
|
$email_tpl,
|
|
|
|
'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n"
|
|
|
|
. 'Content-type: text/plain; charset=UTF-8' . "\n"
|
|
|
|
. 'Content-transfer-encoding: 8bit' );
|
|
|
|
|
|
|
|
pop_lang();
|
|
|
|
|
|
|
|
if($res) {
|
|
|
|
info( t('Your registration is pending approval by the site owner.') . EOL ) ;
|
|
|
|
goaway(z_root());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2012-07-22 01:03:22 +00:00
|
|
|
}
|
2012-07-21 23:43:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function zregister_content(&$a) {
|
|
|
|
|
|
|
|
|
2012-08-16 04:56:04 +00:00
|
|
|
if(get_config('system','register_policy') == REGISTER_CLOSED) {
|
2012-07-21 23:43:31 +00:00
|
|
|
notice("Permission denied." . EOL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$max_dailies = intval(get_config('system','max_daily_registrations'));
|
|
|
|
if($max_dailies) {
|
|
|
|
$r = q("select count(*) as total from account where account_created > UTC_TIMESTAMP - INTERVAL 1 day");
|
|
|
|
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-07-23 00:25:26 +00:00
|
|
|
// Configurable terms of service link
|
|
|
|
|
|
|
|
$tosurl = get_config('system','tos_url');
|
|
|
|
if(! $tosurl)
|
|
|
|
$tosurl = $a->get_baseurl() . '/help/TermsOfService';
|
|
|
|
|
|
|
|
$toslink = '<a href="' . $tosurl . '" >' . t('Terms of Service') . '</a>';
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2012-08-16 04:56:04 +00:00
|
|
|
$enable_tos = 1 - intval(get_config('system','no_termsofservice'));
|
2012-07-21 23:43:31 +00:00
|
|
|
|
|
|
|
$email = ((x($_REQUEST,'email')) ? $_REQUEST['email'] : "" );
|
|
|
|
$password = ((x($_REQUEST,'password')) ? $_REQUEST['password'] : "" );
|
|
|
|
$password2 = ((x($_REQUEST,'password2')) ? $_REQUEST['password2'] : "" );
|
|
|
|
$invite_code = ((x($_REQUEST,'invite_code')) ? $_REQUEST['invite_code'] : "" );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$o = replace_macros(get_markup_template('zregister.tpl'), array(
|
|
|
|
|
|
|
|
'$title' => t('Registration'),
|
|
|
|
'$registertext' => get_config('system','register_text'),
|
|
|
|
'$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_id' => $invite_id,
|
|
|
|
|
|
|
|
'$label_email' => t('Your email address'),
|
|
|
|
'$label_pass1' => t('Choose a password'),
|
|
|
|
'$label_pass2' => t('Please re-enter your password'),
|
2012-07-23 00:25:26 +00:00
|
|
|
'$label_tos' => $label_tos,
|
2012-08-16 04:56:04 +00:00
|
|
|
'$enable_tos' => $enable_tos,
|
2012-07-21 23:43:31 +00:00
|
|
|
'$email' => $email,
|
|
|
|
'$pass1' => $password,
|
|
|
|
'$pass2' => $password2,
|
|
|
|
'$submit' => t('Register')
|
|
|
|
));
|
|
|
|
|
|
|
|
return $o;
|
|
|
|
|
|
|
|
}
|
|
|
|
|