/upload/catalog/controller/account/login.php

https://bitbucket.org/elena_dyavolova/omf · PHP · 218 lines · 172 code · 41 blank · 5 comment · 42 complexity · daa424eb5e5a7196e6bf96e0f0b074da MD5 · raw file

  1. <?php
  2. class ControllerAccountLogin extends Controller {
  3. private $error = array();
  4. public function index() {
  5. $this->load->model('account/customer');
  6. // Login override for admin users
  7. if (!empty($this->request->get['token'])) {
  8. $this->customer->logout();
  9. $this->cart->clear();
  10. unset($this->session->data['wishlist']);
  11. unset($this->session->data['shipping_address_id']);
  12. unset($this->session->data['shipping_country_id']);
  13. unset($this->session->data['shipping_zone_id']);
  14. unset($this->session->data['shipping_postcode']);
  15. unset($this->session->data['shipping_method']);
  16. unset($this->session->data['shipping_methods']);
  17. unset($this->session->data['payment_address_id']);
  18. unset($this->session->data['payment_country_id']);
  19. unset($this->session->data['payment_zone_id']);
  20. unset($this->session->data['payment_method']);
  21. unset($this->session->data['payment_methods']);
  22. unset($this->session->data['comment']);
  23. unset($this->session->data['order_id']);
  24. unset($this->session->data['coupon']);
  25. unset($this->session->data['reward']);
  26. unset($this->session->data['voucher']);
  27. unset($this->session->data['vouchers']);
  28. $customer_info = $this->model_account_customer->getCustomerByToken($this->request->get['token']);
  29. if ($customer_info && $this->customer->login($customer_info['email'], '', true)) {
  30. // Default Addresses
  31. $this->load->model('account/address');
  32. $address_info = $this->model_account_address->getAddress($this->customer->getAddressId());
  33. if ($address_info) {
  34. if ($this->config->get('config_tax_customer') == 'shipping') {
  35. $this->session->data['shipping_country_id'] = $address_info['country_id'];
  36. $this->session->data['shipping_zone_id'] = $address_info['zone_id'];
  37. $this->session->data['shipping_postcode'] = $address_info['postcode'];
  38. }
  39. if ($this->config->get('config_tax_customer') == 'payment') {
  40. $this->session->data['payment_country_id'] = $address_info['country_id'];
  41. $this->session->data['payment_zone_id'] = $address_info['zone_id'];
  42. }
  43. } else {
  44. unset($this->session->data['shipping_country_id']);
  45. unset($this->session->data['shipping_zone_id']);
  46. unset($this->session->data['shipping_postcode']);
  47. unset($this->session->data['payment_country_id']);
  48. unset($this->session->data['payment_zone_id']);
  49. }
  50. $this->redirect($this->url->link('account/account', '', 'SSL'));
  51. }
  52. }
  53. if ($this->customer->isLogged()) {
  54. $this->redirect($this->url->link('account/account', '', 'SSL'));
  55. }
  56. $this->language->load('account/login');
  57. $this->document->setTitle($this->language->get('heading_title'));
  58. if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
  59. unset($this->session->data['guest']);
  60. // Default Shipping Address
  61. $this->load->model('account/address');
  62. $address_info = $this->model_account_address->getAddress($this->customer->getAddressId());
  63. if ($address_info) {
  64. if ($this->config->get('config_tax_customer') == 'shipping') {
  65. $this->session->data['shipping_country_id'] = $address_info['country_id'];
  66. $this->session->data['shipping_zone_id'] = $address_info['zone_id'];
  67. $this->session->data['shipping_postcode'] = $address_info['postcode'];
  68. }
  69. if ($this->config->get('config_tax_customer') == 'payment') {
  70. $this->session->data['payment_country_id'] = $address_info['country_id'];
  71. $this->session->data['payment_zone_id'] = $address_info['zone_id'];
  72. }
  73. } else {
  74. unset($this->session->data['shipping_country_id']);
  75. unset($this->session->data['shipping_zone_id']);
  76. unset($this->session->data['shipping_postcode']);
  77. unset($this->session->data['payment_country_id']);
  78. unset($this->session->data['payment_zone_id']);
  79. }
  80. // Added strpos check to pass McAfee PCI compliance test (http://forum.opencart.com/viewtopic.php?f=10&t=12043&p=151494#p151295)
  81. if (isset($this->request->post['redirect']) && (strpos($this->request->post['redirect'], $this->config->get('config_url')) !== false || strpos($this->request->post['redirect'], $this->config->get('config_ssl')) !== false)) {
  82. $this->redirect(str_replace('&amp;', '&', $this->request->post['redirect']));
  83. } else {
  84. $this->redirect($this->url->link('account/account', '', 'SSL'));
  85. }
  86. }
  87. $this->data['breadcrumbs'] = array();
  88. $this->data['breadcrumbs'][] = array(
  89. 'text' => $this->language->get('text_home'),
  90. 'href' => $this->url->link('common/home'),
  91. 'separator' => false
  92. );
  93. $this->data['breadcrumbs'][] = array(
  94. 'text' => $this->language->get('text_account'),
  95. 'href' => $this->url->link('account/account', '', 'SSL'),
  96. 'separator' => $this->language->get('text_separator')
  97. );
  98. $this->data['breadcrumbs'][] = array(
  99. 'text' => $this->language->get('text_login'),
  100. 'href' => $this->url->link('account/login', '', 'SSL'),
  101. 'separator' => $this->language->get('text_separator')
  102. );
  103. $this->data['heading_title'] = $this->language->get('heading_title');
  104. $this->data['text_new_customer'] = $this->language->get('text_new_customer');
  105. $this->data['text_register'] = $this->language->get('text_register');
  106. $this->data['text_register_account'] = $this->language->get('text_register_account');
  107. $this->data['text_returning_customer'] = $this->language->get('text_returning_customer');
  108. $this->data['text_i_am_returning_customer'] = $this->language->get('text_i_am_returning_customer');
  109. $this->data['text_forgotten'] = $this->language->get('text_forgotten');
  110. $this->data['entry_email'] = $this->language->get('entry_email');
  111. $this->data['entry_password'] = $this->language->get('entry_password');
  112. $this->data['button_continue'] = $this->language->get('button_continue');
  113. $this->data['button_login'] = $this->language->get('button_login');
  114. if (isset($this->error['warning'])) {
  115. $this->data['error_warning'] = $this->error['warning'];
  116. } else {
  117. $this->data['error_warning'] = '';
  118. }
  119. $this->data['action'] = $this->url->link('account/login', '', 'SSL');
  120. $this->data['register'] = $this->url->link('account/register', '', 'SSL');
  121. $this->data['forgotten'] = $this->url->link('account/forgotten', '', 'SSL');
  122. // Added strpos check to pass McAfee PCI compliance test (http://forum.opencart.com/viewtopic.php?f=10&t=12043&p=151494#p151295)
  123. if (isset($this->request->post['redirect']) && (strpos($this->request->post['redirect'], $this->config->get('config_url')) !== false || strpos($this->request->post['redirect'], $this->config->get('config_ssl')) !== false)) {
  124. $this->data['redirect'] = $this->request->post['redirect'];
  125. } elseif (isset($this->session->data['redirect'])) {
  126. $this->data['redirect'] = $this->session->data['redirect'];
  127. unset($this->session->data['redirect']);
  128. } else {
  129. $this->data['redirect'] = '';
  130. }
  131. if (isset($this->session->data['success'])) {
  132. $this->data['success'] = $this->session->data['success'];
  133. unset($this->session->data['success']);
  134. } else {
  135. $this->data['success'] = '';
  136. }
  137. if (isset($this->request->post['email'])) {
  138. $this->data['email'] = $this->request->post['email'];
  139. } else {
  140. $this->data['email'] = '';
  141. }
  142. if (isset($this->request->post['password'])) {
  143. $this->data['password'] = $this->request->post['password'];
  144. } else {
  145. $this->data['password'] = '';
  146. }
  147. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/login.tpl')) {
  148. $this->template = $this->config->get('config_template') . '/template/account/login.tpl';
  149. } else {
  150. $this->template = 'default/template/account/login.tpl';
  151. }
  152. $this->children = array(
  153. 'common/column_left',
  154. 'common/column_right',
  155. 'common/content_top',
  156. 'common/content_bottom',
  157. 'common/footer',
  158. 'common/header'
  159. );
  160. $this->response->setOutput($this->render());
  161. }
  162. protected function validate() {
  163. if (!$this->customer->login($this->request->post['email'], $this->request->post['password'])) {
  164. $this->error['warning'] = $this->language->get('error_login');
  165. }
  166. $customer_info = $this->model_account_customer->getCustomerByEmail($this->request->post['email']);
  167. if ($customer_info && !$customer_info['approved']) {
  168. $this->error['warning'] = $this->language->get('error_approved');
  169. }
  170. if (!$this->error) {
  171. return true;
  172. } else {
  173. return false;
  174. }
  175. }
  176. }
  177. ?>