Here's my first-blush look at the code and approach:
Here is the file in zen cart that makes the magic happen:
...\includes\modules\pages\header_php.php
The specific code snippet is:
Code:
if (isset($_GET['action']) && ($_GET['action'] == 'process')) {
$email_address = zen_db_prepare_input($_POST['email_address']);
$password = zen_db_prepare_input($_POST['password']);
/* Privacy-policy-read does not need to be checked during "login"
if (DISPLAY_PRIVACY_CONDITIONS == 'true') {
if (!isset($_POST['privacy_conditions']) || ($_POST['privacy_conditions'] != '1')) {
$error = true;
$messageStack->add('create_account', ERROR_PRIVACY_STATEMENT_NOT_ACCEPTED, 'error');
}
}
*/
// Check if email exists
$check_customer_query = "SELECT customers_id, customers_firstname, customers_password,
customers_email_address, customers_default_address_id,
customers_authorization, customers_referral
FROM " . TABLE_CUSTOMERS . "
WHERE customers_email_address = :email";
$check_customer_query =$db->bindVars($check_customer_query, ':email', $email_address, 'string');
$check_customer = $db->Execute($check_customer_query);
if (!$check_customer->RecordCount()) {
$error = true;
} else {
// Check that password is good
if (!zen_validate_password($password, $check_customer->fields['customers_password'])) {
$error = true;
} else {
if (SESSION_RECREATE == 'True') {
zen_session_recreate();
}
$check_country_query = "SELECT entry_country_id, entry_zone_id
FROM " . TABLE_ADDRESS_BOOK . "
WHERE customers_id = :customersID
AND address_book_id = :adressBookID";
$check_country_query = $db->bindVars($check_country_query, ':customersID', $check_customer->fields['customers_id'], 'integer');
$check_country_query = $db->bindVars($check_country_query, ':adressBookID', $check_customer->fields['customers_default_address_id'], 'integer');
$check_country = $db->Execute($check_country_query);
$_SESSION['customer_id'] = $check_customer->fields['customers_id'];
$_SESSION['customer_default_address_id'] = $check_customer->fields['customers_default_address_id'];
$_SESSION['customers_authorization'] = $check_customer->fields['customers_authorization'];
$_SESSION['customer_first_name'] = $check_customer->fields['customers_firstname'];
$_SESSION['customer_country_id'] = $check_country->fields['entry_country_id'];
$_SESSION['customer_zone_id'] = $check_country->fields['entry_zone_id'];
$sql = "UPDATE " . TABLE_CUSTOMERS_INFO . "
SET customers_info_date_of_last_logon = now(),
customers_info_number_of_logons = customers_info_number_of_logons+1
WHERE customers_info_id = :customersID";
$sql = $db->bindVars($sql, ':customersID', $_SESSION['customer_id'], 'integer');
$db->Execute($sql);
$zco_notifier->notify('NOTIFY_LOGIN_SUCCESS');
// restore cart contents
$_SESSION['cart']->restore_contents();
/*
if ($_SESSION['cart']->count_contents() > 0) {
zen_redirect(zen_href_link(FILENAME_CHECKOUT_SHIPPING));
}
*/
if (sizeof($_SESSION['navigation']->snapshot) > 0) {
// $back = sizeof($_SESSION['navigation']->path)-2;
//if (isset($_SESSION['navigation']->path[$back]['page'])) {
// if (sizeof($_SESSION['navigation']->path)-2 > 0) {
$origin_href = zen_href_link($_SESSION['navigation']->snapshot['page'], zen_array_to_string($_SESSION['navigation']->snapshot['get'], array(zen_session_name())), $_SESSION['navigation']->snapshot['mode']);
// $origin_href = zen_back_link_only(true);
$_SESSION['navigation']->clear_snapshot();
zen_redirect($origin_href);
} else {
zen_redirect(zen_href_link(FILENAME_DEFAULT));
}
}
}
}
previously I made the following tweak to osCommerce in the login.php file:
Code:
// Check if email exists
$check_customer_query = tep_db_query("select user_id, user_password from phpbb_users where username = '" . $phpbb_username . "'");
if (!tep_db_num_rows($check_customer_query)) {
$error = true;
} else {
$phpbb_check_customer = tep_db_fetch_array($check_customer_query);
// Check that password is good
if (! md5($password) == $phpbb_check_customer['user_password']) {
$error = true;
} else {
## Check to see if customer has logged in to osCommerce before
$Qcheck = tep_db_query("select customers_info_number_of_logons from " . TABLE_CUSTOMERS_INFO . " where customers_info_id = '" . $phpbb_check_customer['user_id'] . "'");
if (tep_db_num_rows($Qcheck) > 0) {
tep_db_query("update " . TABLE_CUSTOMERS_INFO . " set customers_info_date_of_last_logon = now(), customers_info_number_of_logons = customers_info_number_of_logons+1 where customers_info_id = '" . (int)$phpbb_check_customer['user_id'] . "'");
## update query needs to be written to freshen the osc_customer table each time a user logs in.
$Qphpbb_users = tep_db_query("select user_firstname, user_lastname, user_email, user_address1, user_address2, user_city, user_state, user_zip, user_homephone, user_chronicleemail from phpbb_users where user_id = '" . $phpbb_check_customer['user_id'] . "'");
$phpbb_users_array = tep_db_fetch_array($Qphpbb_users);
$Qdefault_address = tep_db_query("select customers_default_address_id from " . TABLE_CUSTOMERS . " where customers_id = '" . $phpbb_check_customer['user_id'] . "'");
$default_address = tep_db_fetch_array($Qdefault_address);
$sql_data_array = array('customers_firstname' => $phpbb_users_array['user_firstname'],
'customers_lastname' => $phpbb_users_array['user_lastname'],
'customers_email_address' => $phpbb_users_array['user_email'],
'customers_telephone' => $phpbb_users_array['user_homephone'],
'customers_newsletter' => $phpbb_users_array['user_chronicleemail'],
);
tep_db_perform(TABLE_CUSTOMERS, $sql_data_array, 'update', "customers_id ='" . $phpbb_check_customer['user_id'] . "'");
$sql_data_array = array('entry_firstname' => $phpbb_users_array['user_firstname'],
'entry_lastname' => $phpbb_users_array['user_lastname'],
'entry_street_address' => $phpbb_users_array['user_address1'] . " " . $phpbb_users_array['user_address2'],
'entry_postcode' => $phpbb_users_array['user_zip'],
'entry_city' => $phpbb_users_array['user_city'],
'entry_state' => $phpbb_users_array['user_state'],
);
tep_db_perform(TABLE_ADDRESS_BOOK, $sql_data_array, 'update', "address_book_id = '" . $default_address['customers_default_address_id'] . "' and customers_id ='" . $phpbb_check_customer['user_id'] . "'");
} else {
tep_db_query("insert into " . TABLE_CUSTOMERS_INFO . " (customers_info_id, customers_info_date_of_last_logon, customers_info_number_of_logons, customers_info_date_account_created) values (" . $phpbb_check_customer['user_id'] . " , now(), 1, now())");
## Query phpBB database to get info and populate osc_customers table.
$Qphpbb_users = tep_db_query("select user_firstname, user_lastname, user_email, user_address1, user_address2, user_city, user_state, user_zip, user_homephone, user_chronicleemail from phpbb_users where user_id = '" . $phpbb_check_customer['user_id'] . "'");
$phpbb_users_array = tep_db_fetch_array($Qphpbb_users);
$sql_data_array = array('customers_id' => $phpbb_check_customer['user_id'],
'customers_firstname' => $phpbb_users_array['user_firstname'],
'customers_lastname' => $phpbb_users_array['user_lastname'],
'customers_email_address' => $phpbb_users_array['user_email'],
'customers_telephone' => $phpbb_users_array['user_homephone'],
'customers_newsletter' => $phpbb_users_array['user_chronicleemail'],
);
tep_db_perform(TABLE_CUSTOMERS, $sql_data_array);
$sql_data_array = array('customers_id' => $phpbb_check_customer['user_id'],
'entry_firstname' => $phpbb_users_array['user_firstname'],
'entry_lastname' => $phpbb_users_array['user_lastname'],
'entry_street_address' => $phpbb_users_array['user_address1'] . " " . $phpbb_users_array['user_address2'],
'entry_postcode' => $phpbb_users_array['user_zip'],
'entry_city' => $phpbb_users_array['user_city'],
'entry_state' => $phpbb_users_array['user_state'],
'entry_country_id' => STORE_COUNTRY,
);
tep_db_perform(TABLE_ADDRESS_BOOK, $sql_data_array);
$address_id = tep_db_insert_id();
tep_db_query("update " . TABLE_CUSTOMERS . " set customers_default_address_id = '" . (int)$address_id . "' where customers_id = '" . $phpbb_check_customer['user_id'] . "'");
if (SESSION_RECREATE == 'True') {
tep_session_recreate();
}
}
## Now begin normal login and session stuff
$check_customer_query = tep_db_query("select customers_firstname, customers_email_address, customers_default_address_id from " . TABLE_CUSTOMERS . " where customers_id = '" . $phpbb_check_customer['user_id'] . "'");
if (!tep_db_num_rows($check_customer_query)) {
$error = true;
} else {
$check_customer = tep_db_fetch_array($check_customer_query);
}
$check_country_query = tep_db_query("select entry_country_id, entry_zone_id from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . $phpbb_check_customer['user_id'] . "' and address_book_id = '" . (int)$check_customer['customers_default_address_id'] . "'");
$check_country = tep_db_fetch_array($check_country_query);
$customer_id = $phpbb_check_customer['user_id'];
$customer_default_address_id = $check_customer['customers_default_address_id'];
$customer_first_name = $check_customer['customers_firstname'];
$customer_country_id = $check_country['entry_country_id'];
$customer_zone_id = $check_country['entry_zone_id'];
tep_session_register('customer_id');
tep_session_register('customer_default_address_id');
tep_session_register('customer_first_name');
tep_session_register('customer_country_id');
tep_session_register('customer_zone_id');
Notice some of the similarities, it seems as though the zen team has embedded the login process into a separate file and further embedded it into an if->then->else statement. Tweaking the database queries to read the phpbb_user table shouldn't be too difficult... Perhaps it should be moved to a separate "Bridge" file that could contain bridges to other software packages as well...