Commit 3de8dc03 by pupi1985

Minor code reformatting to confirm page

parent eb036870
...@@ -25,60 +25,59 @@ if (!defined('QA_VERSION')) { // don't allow this page to be requested directly ...@@ -25,60 +25,59 @@ if (!defined('QA_VERSION')) { // don't allow this page to be requested directly
exit; exit;
} }
// Check we're not using single-sign on integration, that we're not already confirmed, and that we're not blocked // Check we're not using single-sign on integration, that we're not already confirmed, and that we're not blocked
if (QA_FINAL_EXTERNAL_USERS) if (QA_FINAL_EXTERNAL_USERS) {
qa_fatal_error('User login is handled by external code'); qa_fatal_error('User login is handled by external code');
}
// Check if we've been asked to send a new link or have a successful email confirmation // Check if we've been asked to send a new link or have a successful email confirmation
$incode = trim(qa_get('c')); // trim to prevent passing in blank values to match uninitiated DB rows $code = trim(qa_get('c')); // trim to prevent passing in blank values to match uninitiated DB rows
$inhandle = qa_get('u'); $handle = trim(qa_get('u'));
$loginuserid = qa_get_logged_in_userid(); $loggedInUserId = qa_get_logged_in_userid();
$useremailed = false; $emailConfirmationSent = false;
$userconfirmed = false; $userConfirmed = false;
if (isset($loginuserid) && qa_clicked('dosendconfirm')) { // button clicked to send a link
require_once QA_INCLUDE_DIR . 'app/users-edit.php';
if (!qa_check_form_security_code('confirm', qa_post_text('code'))) if (isset($loggedInUserId) && qa_clicked('dosendconfirm')) { // A logged in user requested to be sent a confirmation link
if (!qa_check_form_security_code('confirm', qa_post_text('formcode'))) {
$pageerror = qa_lang_html('misc/form_security_again'); $pageerror = qa_lang_html('misc/form_security_again');
} else {
// For qa_send_new_confirm
require_once QA_INCLUDE_DIR . 'app/users-edit.php';
else { qa_send_new_confirm($loggedInUserId);
qa_send_new_confirm($loginuserid); $emailConfirmationSent = true;
$useremailed = true;
} }
} elseif (strlen($code) > 0) { // If there is a code present in the URL
} elseif (strlen($incode)) { // non-empty code detected from the URL // For qa_db_select_with_pending, qa_db_user_account_selectspec
require_once QA_INCLUDE_DIR . 'db/selects.php'; require_once QA_INCLUDE_DIR . 'db/selects.php';
// For qa_complete_confirm
require_once QA_INCLUDE_DIR . 'app/users-edit.php'; require_once QA_INCLUDE_DIR . 'app/users-edit.php';
if (!empty($inhandle)) { // match based on code and handle provided on URL if (strlen($handle) > 0) { // If there is a handle present in the URL
$userinfo = qa_db_select_with_pending(qa_db_user_account_selectspec($inhandle, false)); $userInfo = qa_db_select_with_pending(qa_db_user_account_selectspec($handle, false));
if (strtolower(trim(@$userinfo['emailcode'])) == strtolower($incode)) { if (strtolower(trim($userInfo['emailcode'])) == strtolower($code)) {
qa_complete_confirm($userinfo['userid'], $userinfo['email'], $userinfo['handle']); qa_complete_confirm($userInfo['userid'], $userInfo['email'], $userInfo['handle']);
$userconfirmed = true; $userConfirmed = true;
} }
} }
if ((!$userconfirmed) && isset($loginuserid)) { // as a backup, also match code on URL against logged in user if (!$userConfirmed && isset($loggedInUserId)) { // As a backup, also match code on URL against logged in user
$userinfo = qa_db_select_with_pending(qa_db_user_account_selectspec($loginuserid, true)); $userInfo = qa_db_select_with_pending(qa_db_user_account_selectspec($loggedInUserId, true));
$flags = $userinfo['flags']; $flags = $userInfo['flags'];
if (($flags & QA_USER_FLAGS_EMAIL_CONFIRMED) && !($flags & QA_USER_FLAGS_MUST_CONFIRM))
$userconfirmed = true; // if they confirmed before, just show message as if it happened now
elseif (strtolower(trim($userinfo['emailcode'])) == strtolower($incode)) { if (($flags & QA_USER_FLAGS_EMAIL_CONFIRMED) > 0 && ($flags & QA_USER_FLAGS_MUST_CONFIRM) == 0) {
qa_complete_confirm($userinfo['userid'], $userinfo['email'], $userinfo['handle']); $userConfirmed = true; // if they confirmed before, just show message as if it happened now
$userconfirmed = true; } elseif (strtolower(trim($userInfo['emailcode'])) == strtolower($code)) {
qa_complete_confirm($userInfo['userid'], $userInfo['email'], $userInfo['handle']);
$userConfirmed = true;
} }
} }
} }
// Prepare content for theme // Prepare content for theme
$qa_content = qa_content_prepare(); $qa_content = qa_content_prepare();
...@@ -86,27 +85,26 @@ $qa_content = qa_content_prepare(); ...@@ -86,27 +85,26 @@ $qa_content = qa_content_prepare();
$qa_content['title'] = qa_lang_html('users/confirm_title'); $qa_content['title'] = qa_lang_html('users/confirm_title');
$qa_content['error'] = @$pageerror; $qa_content['error'] = @$pageerror;
if ($useremailed) { if ($emailConfirmationSent) {
$qa_content['success'] = qa_lang_html('users/confirm_emailed'); $qa_content['success'] = qa_lang_html('users/confirm_emailed');
} elseif ($userConfirmed) {
} elseif ($userconfirmed) {
$qa_content['success'] = qa_lang_html('users/confirm_complete'); $qa_content['success'] = qa_lang_html('users/confirm_complete');
if (!isset($loginuserid)) { if (!isset($loggedInUserId)) {
$qa_content['suggest_next'] = strtr( $qa_content['suggest_next'] = strtr(
qa_lang_html('users/log_in_to_access'), qa_lang_html('users/log_in_to_access'),
array( array(
'^1' => '<a href="' . qa_path_html('login', array('e' => $inhandle)) . '">', '^1' => '<a href="' . qa_path_html('login', array('e' => $handle)) . '">',
'^2' => '</a>', '^2' => '</a>',
) )
); );
} }
} elseif (isset($loggedInUserId)) { // if logged in, allow sending a fresh link
} elseif (isset($loginuserid)) { // if logged in, allow sending a fresh link
require_once QA_INCLUDE_DIR . 'util/string.php'; require_once QA_INCLUDE_DIR . 'util/string.php';
if (strlen($incode)) if (strlen($code) > 0) {
$qa_content['error'] = qa_lang_html('users/confirm_wrong_resend'); $qa_content['error'] = qa_lang_html('users/confirm_wrong_resend');
}
$email = qa_get_logged_in_email(); $email = qa_get_logged_in_email();
...@@ -134,7 +132,7 @@ if ($useremailed) { ...@@ -134,7 +132,7 @@ if ($useremailed) {
), ),
'hidden' => array( 'hidden' => array(
'code' => qa_get_form_security_code('confirm'), 'formcode' => qa_get_form_security_code('confirm'),
), ),
); );
...@@ -142,9 +140,8 @@ if ($useremailed) { ...@@ -142,9 +140,8 @@ if ($useremailed) {
$qa_content['error'] = qa_lang_html('users/email_invalid'); $qa_content['error'] = qa_lang_html('users/email_invalid');
unset($qa_content['form']['buttons']['send']); unset($qa_content['form']['buttons']['send']);
} }
} else { // User is not logged in
} else
$qa_content['error'] = qa_insert_login_links(qa_lang_html('users/confirm_wrong_log_in'), 'confirm'); $qa_content['error'] = qa_insert_login_links(qa_lang_html('users/confirm_wrong_log_in'), 'confirm');
}
return $qa_content; return $qa_content;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment