-
Notifications
You must be signed in to change notification settings - Fork 5
/
login.php
executable file
·186 lines (160 loc) · 9.79 KB
/
login.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
/* -----------------------------------------------------------------------------------------
$Id: login.php 4228 2013-01-11 10:43:51Z gtb-modified $
XT-Commerce - community made shopping
http://www.xt-commerce.com
Copyright (c) 2003 XT-Commerce
-----------------------------------------------------------------------------------------
based on:
(c) 2000-2001 The Exchange Project (earlier name of osCommerce)
(c) 2002-2003 osCommerce(login.php,v 1.79 2003/05/19); www.oscommerce.com
(c) 2003 nextcommerce (login.php,v 1.13 2003/08/17); www.nextcommerce.org
Released under the GNU General Public License
-----------------------------------------------------------------------------------------
Third Party contribution:
guest account idea by Ingo T. <xIngox@web.de>
---------------------------------------------------------------------------------------*/
include ('includes/application_top.php');
if (isset ($_SESSION['customer_id'])) {
xtc_redirect(xtc_href_link(FILENAME_ACCOUNT, '', 'SSL'));
}
// create smarty elements
$smarty = new Smarty;
// include boxes
require (DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/source/boxes.php');
// include needed functions
require_once(DIR_FS_INC.'verify_recaptcha.inc.php');
require_once (DIR_FS_INC.'xtc_validate_password.inc.php');
require_once (DIR_FS_INC.'xtc_array_to_string.inc.php');
require_once (DIR_FS_INC.'xtc_write_user_info.inc.php');
// redirect the customer to a friendly cookie-must-be-enabled page if cookies are disabled (or the session has not started)
if ($session_started == false) {
xtc_redirect(xtc_href_link(FILENAME_COOKIE_USAGE));
}
$info_message = false; //DokuMan - 2010-02-28 - set undefined variable
if (!isset($_SESSION['customers_login_tries'])) {
$_SESSION['customers_login_tries'] = 1;
}
if (isset ($_GET['action']) && ($_GET['action'] == 'process')) {
$email_address = xtc_db_prepare_input($_POST['email_address']);
$password = xtc_db_prepare_input($_POST['password']);
// brute force
$check_login_query = xtc_db_query("SELECT customers_login_tries
FROM ".TABLE_CUSTOMERS_LOGIN."
WHERE (customers_email_address = '".xtc_db_input($email_address)."'
OR customers_ip = '".xtc_db_input($_SESSION['tracking']['ip'])."')");
if (xtc_db_num_rows($check_login_query) > 0) {
while ($check_login = xtc_db_fetch_array($check_login_query)) {
if ($check_login['customers_login_tries'] > $_SESSION['customers_login_tries']) {
$_SESSION['customers_login_tries'] = $check_login['customers_login_tries'];
}
}
// update login tries
xtc_db_query("UPDATE ".TABLE_CUSTOMERS_LOGIN."
SET customers_login_tries = '".($_SESSION['customers_login_tries'] + 1)."'
WHERE (customers_email_address = '".xtc_db_input($email_address)."'
OR customers_ip = '".xtc_db_input($_SESSION['tracking']['ip'])."')");
} else {
$sql_data_array = array(
'customers_ip' => $_SESSION['tracking']['ip'],
'customers_email_address' => $email_address,
'customers_login_tries' => ($_SESSION['customers_login_tries'] + 1),
);
xtc_db_perform(TABLE_CUSTOMERS_LOGIN, $sql_data_array);
}
$captcha_error = false;
if (trim(INSERT_RECAPTCHA_KEY) != '' && trim(RECAPTCHA_SECRET_KEY) != '') {
if ($_SESSION['customers_login_tries'] > FAILED_LOGINS_LIMIT) {
$captcha_error = true;
if (isset($_POST['g-recaptcha-response']) && !empty( $_POST['g-recaptcha-response']) && verify_recaptcha($_POST['g-recaptcha-response'], RECAPTCHA_SECRET_KEY) === false) {
$captcha_error = false;
} else {
$info_message .= TEXT_LOGIN_ERROR_NO_CAPTCHA."<br />";
}
}
}
// Check if email exists
$check_customer_query = xtc_db_query("select customers_id, customers_vat_id, customers_firstname,customers_lastname, customers_gender, customers_password, customers_email_address, customers_default_address_id from ".TABLE_CUSTOMERS." where customers_email_address = '".xtc_db_input($email_address)."' and account_type = '0'");
if (!xtc_db_num_rows($check_customer_query)) {
$_GET['login'] = 'fail';
$info_message .= TEXT_NO_EMAIL_ADDRESS_FOUND;
} else {
$check_customer = xtc_db_fetch_array($check_customer_query);
// Check that password is good
if (!xtc_validate_password($password, $check_customer['customers_password'],$check_customer['customers_id'])) {
$_GET['login'] = 'fail';
$info_message .= TEXT_LOGIN_ERROR;
} else if($captcha_error === false){
if (SESSION_RECREATE == 'True') {
xtc_session_recreate();
}
// reset Login tries
unset($_SESSION['customers_login_tries']);
xtc_db_query("DELETE FROM ".TABLE_CUSTOMERS_LOGIN."
WHERE (customers_email_address = '".xtc_db_input($email_address)."'
OR customers_ip = '".xtc_db_input($_SESSION['tracking']['ip'])."')");
$check_country_query = xtc_db_query("select entry_country_id, entry_zone_id from ".TABLE_ADDRESS_BOOK." where customers_id = '".(int) $check_customer['customers_id']."' and address_book_id = '".$check_customer['customers_default_address_id']."'");
$check_country = xtc_db_fetch_array($check_country_query);
$_SESSION['customer_gender'] = $check_customer['customers_gender'];
$_SESSION['customer_first_name'] = $check_customer['customers_firstname'];
$_SESSION['customer_last_name'] = $check_customer['customers_lastname'];
$_SESSION['customer_id'] = $check_customer['customers_id'];
$_SESSION['customer_vat_id'] = $check_customer['customers_vat_id'];
$_SESSION['customer_default_address_id'] = $check_customer['customers_default_address_id'];
$_SESSION['customer_country_id'] = $check_country['entry_country_id'];
$_SESSION['customer_zone_id'] = $check_country['entry_zone_id'];
$date_now = date('Ymd');
xtc_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) $_SESSION['customer_id']."'");
xtc_write_user_info((int) $_SESSION['customer_id']);
// restore cart contents
$_SESSION['cart']->restore_contents();
if (is_object($econda)) $econda->_loginUser();
if (isset($_SESSION['REFERER']) && !empty($_SESSION['REFERER'])) {
xtc_redirect(xtc_href_link($_SESSION['REFERER'], xtc_get_all_get_params(array('review_prod_id')).(isset($_GET['review_prod_id'])?'products_id='.$_GET['review_prod_id']:'')));
} elseif ($_SESSION['cart']->count_contents() > 0 && !isset($_GET['review_prod_id']) && !isset($_GET['order_id'])) {
xtc_redirect(xtc_href_link(FILENAME_SHOPPING_CART),'NONSSL');
} else {
xtc_redirect(xtc_href_link(FILENAME_DEFAULT),'NONSSL');
}
}
}
}
$breadcrumb->add(NAVBAR_TITLE_LOGIN, xtc_href_link(FILENAME_LOGIN, '', 'SSL'));
require (DIR_WS_INCLUDES.'header.php');
if (isset($_GET['info_message'])) $info_message = $_GET['info_message'];
$smarty->assign('info_message', $info_message);
$smarty->assign('account_option', ACCOUNT_OPTIONS);
$smarty->assign('BUTTON_NEW_ACCOUNT', '<a href="'.xtc_href_link(FILENAME_CREATE_ACCOUNT, '', 'SSL').'">'.xtc_image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE).'</a>');
$smarty->assign('BUTTON_LOGIN', xtc_image_submit('button_login.gif', IMAGE_BUTTON_LOGIN));
$smarty->assign('BUTTON_GUEST', '<a href="'.xtc_href_link(FILENAME_CREATE_GUEST_ACCOUNT, '', 'SSL').'">'.xtc_image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE).'</a>');
// BOC added review_prod_id to be able to redirect to product_reviews_write when coming from reviews button, and order_id to redirect to account_history_info when coming from Link in change_order_mail, noRiddle
//$smarty->assign('FORM_ACTION', xtc_draw_form('login', xtc_href_link(FILENAME_LOGIN, 'action=process', 'SSL')));
if(isset($_GET['review_prod_id'])) {
$smarty->assign('FORM_ACTION', xtc_draw_form('login', xtc_href_link(FILENAME_LOGIN, 'action=process&review_prod_id='.(int)$_GET['review_prod_id'], 'SSL')));
} elseif (isset($_GET['order_id'])) {
$smarty->assign('FORM_ACTION', xtc_draw_form('login', xtc_href_link(FILENAME_LOGIN, 'action=process&order_id='.(int)$_GET['order_id'], 'SSL')));
} else {
$smarty->assign('FORM_ACTION', xtc_draw_form('login', xtc_href_link(FILENAME_LOGIN, 'action=process', 'SSL')));
}
// EOC added review_prod_id and order_id, noRiddle
$smarty->assign('INPUT_MAIL', xtc_draw_input_field('email_address'));
$smarty->assign('INPUT_PASSWORD', xtc_draw_password_field('password'));
$smarty->assign('LINK_LOST_PASSWORD', xtc_href_link(FILENAME_PASSWORD_DOUBLE_OPT, '', 'SSL'));
$smarty->assign('FORM_END', '</form>');
// captcha
if (trim(INSERT_RECAPTCHA_KEY) != '' && trim(RECAPTCHA_SECRET_KEY) != '') {
if ($_SESSION['customers_login_tries'] >= FAILED_LOGINS_LIMIT) {
$smarty->assign('RECAPTCHA','<div class="g-recaptcha" data-sitekey="'. trim(INSERT_RECAPTCHA_KEY).'"></div>');
}
}
$smarty->assign('language', $_SESSION['language']);
$smarty->caching = 0;
$main_content = $smarty->fetch(CURRENT_TEMPLATE.'/module/login.html');
$smarty->assign('main_content', $main_content);
$smarty->assign('language', $_SESSION['language']);
$smarty->caching = 0;
// if (!defined('RM'))
// /*$smarty->load_filter('output', 'note');*/
$smarty->display(CURRENT_TEMPLATE.'/index.html');
include ('includes/application_bottom.php');
?>