diff options
-rw-r--r-- | include/account.php | 27 | ||||
-rw-r--r-- | mod/zregister.php | 92 | ||||
-rw-r--r-- | view/tpl/zregister.tpl | 15 |
3 files changed, 75 insertions, 59 deletions
diff --git a/include/account.php b/include/account.php index 10ef6c525..4191d8d0b 100644 --- a/include/account.php +++ b/include/account.php @@ -11,21 +11,17 @@ function create_account($arr) { // Required: { email, password } - $a = get_app(); - $result = array('success' => false, 'user' => null, 'password' => '', 'message' => ''); + $result = array('success' => false, 'email' => '', 'password' => '', 'message' => ''); $using_invites = get_config('system','invitation_only'); $num_invites = get_config('system','number_invites'); - $invite_id = ((x($arr,'invite_id')) ? notags(trim($arr['invite_id'])) : ''); $email = ((x($arr,'email')) ? notags(trim($arr['email'])) : ''); $password = ((x($arr,'password')) ? trim($arr['password']) : ''); $password2 = ((x($arr,'password2')) ? trim($arr['password2']) : ''); $parent = ((x($arr,'parent')) ? intval($arr['parent']) : 0 ); - - $blocked = ((x($arr,'blocked')) ? intval($arr['blocked']) : 0); - $verified = ((x($arr,'verified')) ? intval($arr['verified']) : 0); + $flags = ((x($arr,'account_flags')) ? intval($arr['account_flags']) : ACCOUNT_OK); if($using_invites) { if(! $invite_id) { @@ -50,16 +46,19 @@ function create_account($arr) { if((! valid_email($email)) || (! validate_email($email))) $result['message'] .= t('Not a valid email address.') . EOL; + $r = q("select account_email, account_password from account where email = '%s' limit 1", + + + + if(strlen($result['message'])) { return $result; } - $password_encoded = hash('whirlpool',$password); - - $result['password'] = $new_password; + $password_encoded = hash('whirlpool',$password); $r = q("INSERT INTO account ( account_parent, account_password, account_email, account_language, @@ -69,7 +68,7 @@ function create_account($arr) { intval($parent), dbesc($password_encoded), dbesc($email), - dbesc($a->language), + dbesc(get_best_language()), dbesc(datetime_convert()), dbesc($flags), dbesc(0), @@ -77,8 +76,16 @@ function create_account($arr) { dbesc($default_service_class) ); + if(! $r) { + logger('create_account: DB INSERT failed.'); + $result['message'] = t('Failed to store account information.'); + return($result); + } $result['success'] = true; + + $result['email'] = $email; + $result['password'] = $password; return $result; } diff --git a/mod/zregister.php b/mod/zregister.php index 87a5cff0c..fbdc4e260 100644 --- a/mod/zregister.php +++ b/mod/zregister.php @@ -6,18 +6,28 @@ function zregister_init(&$a) { $cmd = ((argc() > 1) ? argv(1) : ''); - if($cmd === 'email_check.json') { $result = array('error' => false, 'message' => ''); $email = $_REQUEST['email']; + if(! strlen($email)) + json_return_and_die($result); - if(! allowed_email($email)) - $result['message'] = t('Your email domain is not among those allowed on this site'); if((! valid_email($email)) || (! validate_email($email))) $result['message'] .= t('Not a valid email address') . EOL; + elseif(! allowed_email($email)) + $result['message'] = t('Your email domain is not among those allowed on this site'); + else { + $r = q("select account_email from account where account_email = '%s' limit 1", + dbesc($email) + ); + if(count($r)) { + $result['message'] .= t('Your email address is already registered at this site.'); + } + } if($result['message']) $result['error'] = true; + json_return_and_die($result); } @@ -75,50 +85,47 @@ EOT; function zregister_post(&$a) { - $verified = 0; - $blocked = 1; - - $arr = array('post' => $_POST); - call_hooks('zregister_post', $arr); - $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) { + notice( t('Maximum daily site registrations exceeded. Please try again tomorrow.') . EOL); return; } } - switch(get_config('system','register_policy')) { + if(! x($_POST,'tos')) { + notice( t('Please indicate acceptance of the Terms of Service. Registration failed.') . EOL); + return; + } - case REGISTER_OPEN: - $blocked = 0; - $verified = 0; - break; + $policy = get_config('system','register_policy'); - case REGISTER_APPROVE: - $blocked = 0; - $verified = 0; - break; + switch($policy) { - 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; - } - $blocked = 1; - $verified = 0; - break; + 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; } require_once('include/account.php'); $arr = $_POST; - - $arr['blocked'] = $blocked; - $arr['verified'] = $verified; + $arr['account_flags'] = $flags; $result = create_account($arr); @@ -134,7 +141,7 @@ function zregister_post(&$a) { $invite_id = ((x($_POST,'invite_id')) ? notags(trim($_POST['invite_id'])) : ''); - if( $a->config['register_policy'] == REGISTER_OPEN ) { + if($policy == REGISTER_OPEN ) { if($using_invites && $invite_id) { q("delete * from register where hash = '%s' limit 1", dbesc($invite_id)); @@ -143,12 +150,11 @@ function zregister_post(&$a) { $email_tpl = get_intltext_template("register_open_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'] )); + '$sitename' => $a->config['sitename'], + '$siteurl' => $a->get_baseurl(), + '$email' => $user['email'], + '$password' => $result['password'], + )); $res = mail($user['email'], sprintf(t('Registration details for %s'), $a->config['sitename']), $email_tpl, @@ -156,13 +162,12 @@ function zregister_post(&$a) { . 'Content-type: text/plain; charset=UTF-8' . "\n" . 'Content-transfer-encoding: 8bit' ); - if($res) { - info( t('Registration successful. Please check your email for further instructions.') . EOL ) ; + info( t('Registration successful. Please check your email for validation instructions.') . EOL ) ; goaway(z_root()); } } - elseif($a->config['register_policy'] == REGISTER_APPROVE) { + elseif($policy == REGISTER_APPROVE) { if(! strlen($a->config['admin_email'])) { notice( t('Your registration can not be processed.') . EOL); @@ -229,7 +234,7 @@ function zregister_post(&$a) { function zregister_content(&$a) { - if((! local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) { + if(get_config('system','register_policy') == REGISTER_CLOSED) { notice("Permission denied." . EOL); return; } @@ -260,6 +265,7 @@ function zregister_content(&$a) { else $label_tos = sprintf( t('I am over 13 years of age and accept the %s for this website'), $toslink); + $enable_tos = 1 - intval(get_config('system','no_termsofservice')); $email = ((x($_REQUEST,'email')) ? $_REQUEST['email'] : "" ); $password = ((x($_REQUEST,'password')) ? $_REQUEST['password'] : "" ); @@ -281,7 +287,7 @@ function zregister_content(&$a) { '$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, diff --git a/view/tpl/zregister.tpl b/view/tpl/zregister.tpl index 356b1b61d..d888052b0 100644 --- a/view/tpl/zregister.tpl +++ b/view/tpl/zregister.tpl @@ -10,7 +10,7 @@ <p id="register-invite-desc">$invite_desc</p> <label for="zregister-invite" id="label-zregister-invite" class="zregister-label">$label_invite</label> - <input type="text" maxlength="72" size="32" name="invite_id" id="zregister-invite" class="zregister-input" value="$invite_id" > + <input type="text" maxlength="72" size="32" name="invite_id" id="zregister-invite" class="zregister-input" value="$invite_id" /> </div> <div id="zregister-invite-feedback" class="zregister-feedback"></div> <div id="zregister-invite-end" class="zregister-field-end"></div> @@ -19,25 +19,28 @@ <label for="zregister-email" id="label-zregister-email" class="zregister-label" >$label_email</label> - <input type="text" maxlength="72" size="32" name="email" id="zregister-email" class="zregister-input" value="$email" > + <input type="text" maxlength="72" size="32" name="email" id="zregister-email" class="zregister-input" value="$email" /> <div id="zregister-email-feedback" class="zregister-feedback"></div> <div id="zregister-email-end" class="zregister-field-end"></div> <label for="zregister-password" id="label-zregister-password" class="zregister-label" >$label_pass1</label> - <input type="password" maxlength="72" size="32" name="password" id="zregister-password" class="zregister-input" value="$pass1" > + <input type="password" maxlength="72" size="32" name="password" id="zregister-password" class="zregister-input" value="$pass1" /> <div id="zregister-password-feedback" class="zregister-feedback"></div> <div id="zregister-password-end" class="zregister-field-end"></div> <label for="zregister-password2" id="label-zregister-password2" class="zregister-label" >$label_pass2</label> - <input type="password" maxlength="72" size="32" name="password2" id="zregister-password2" class="zregister-input" value="$pass2" > + <input type="password" maxlength="72" size="32" name="password2" id="zregister-password2" class="zregister-input" value="$pass2" /> <div id="zregister-password2-feedback" class="zregister-feedback"></div> <div id="zregister-password2-end" class="zregister-field-end"></div> - - <input type="checkbox" name="tos" id="zregister-tos" value="1" > + {{ if $enable_tos }} + <input type="checkbox" name="tos" id="zregister-tos" value="1" /> <label for="zregister-tos" id="label-zregister-tos">$label_tos</label> <div id="zregister-tos-feedback" class="zregister-feedback"></div> <div id="zregister-tos-end" class="zregister-field-end"></div> + {{ else }} + <input type="hidden" name="tos" value="1" /> + {{ endif }} <input type="submit" name="submit" id="zregister-submit-button" value="$submit" /> <div id="zregister-submit-end" class="zregister-field-end"></div> |