/store/catalog/controller/account/login.php

https://github.com/elleeott/WPOC-boilerplate · PHP · 132 lines · 101 code · 28 blank · 3 comment · 24 complexity · cee0c120613d30740915f47fa6ba3a16 MD5 · raw file

  1. <?php
  2. class ControllerAccountLogin extends Controller {
  3. private $error = array();
  4. public function index() {
  5. // Login override for admin users
  6. if (!empty($this->request->get['token'])) {
  7. $this->customer->logout();
  8. $this->load->model('account/customer');
  9. $customer_info = $this->model_account_customer->getCustomerByToken($this->request->get['token']);
  10. if ($customer_info && $this->customer->login($customer_info['email'], '', true)) {
  11. $this->redirect($this->url->link('account/account', '', 'SSL'));
  12. }
  13. }
  14. if ($this->customer->isLogged()) {
  15. $this->redirect($this->url->link('account/account', '', 'SSL'));
  16. }
  17. $this->language->load('account/login');
  18. $this->document->setTitle($this->language->get('heading_title'));
  19. if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
  20. unset($this->session->data['guest']);
  21. // Added strpos check to pass McAfee PCI compliance test (http://forum.opencart.com/viewtopic.php?f=10&t=12043&p=151494#p151295)
  22. if (isset($this->request->post['redirect']) && (strpos($this->request->post['redirect'], HTTP_SERVER) !== false || strpos($this->request->post['redirect'], HTTPS_SERVER) !== false)) {
  23. $this->redirect(str_replace('&amp;', '&', $this->request->post['redirect']));
  24. } else {
  25. $this->redirect($this->url->link('account/account', '', 'SSL'));
  26. }
  27. }
  28. $this->data['breadcrumbs'] = array();
  29. $this->data['breadcrumbs'][] = array(
  30. 'text' => $this->language->get('text_home'),
  31. 'href' => $this->url->link('common/home'),
  32. 'separator' => false
  33. );
  34. $this->data['breadcrumbs'][] = array(
  35. 'text' => $this->language->get('text_account'),
  36. 'href' => $this->url->link('account/account', '', 'SSL'),
  37. 'separator' => $this->language->get('text_separator')
  38. );
  39. $this->data['breadcrumbs'][] = array(
  40. 'text' => $this->language->get('text_login'),
  41. 'href' => $this->url->link('account/login', '', 'SSL'),
  42. 'separator' => $this->language->get('text_separator')
  43. );
  44. $this->data['heading_title'] = $this->language->get('heading_title');
  45. $this->data['text_new_customer'] = $this->language->get('text_new_customer');
  46. $this->data['text_register'] = $this->language->get('text_register');
  47. $this->data['text_register_account'] = $this->language->get('text_register_account');
  48. $this->data['text_returning_customer'] = $this->language->get('text_returning_customer');
  49. $this->data['text_i_am_returning_customer'] = $this->language->get('text_i_am_returning_customer');
  50. $this->data['text_forgotten'] = $this->language->get('text_forgotten');
  51. $this->data['entry_email'] = $this->language->get('entry_email');
  52. $this->data['entry_password'] = $this->language->get('entry_password');
  53. $this->data['button_continue'] = $this->language->get('button_continue');
  54. $this->data['button_login'] = $this->language->get('button_login');
  55. if (isset($this->error['warning'])) {
  56. $this->data['error_warning'] = $this->error['warning'];
  57. } else {
  58. $this->data['error_warning'] = '';
  59. }
  60. $this->data['action'] = $this->url->link('account/login', '', 'SSL');
  61. $this->data['register'] = $this->url->link('account/register', '', 'SSL');
  62. $this->data['forgotten'] = $this->url->link('account/forgotten', '', 'SSL');
  63. // Added strpos check to pass McAfee PCI compliance test (http://forum.opencart.com/viewtopic.php?f=10&t=12043&p=151494#p151295)
  64. if (isset($this->request->post['redirect']) && (strpos($this->request->post['redirect'], HTTP_SERVER) !== false || strpos($this->request->post['redirect'], HTTPS_SERVER) !== false)) {
  65. $this->data['redirect'] = $this->request->post['redirect'];
  66. } elseif (isset($this->session->data['redirect'])) {
  67. $this->data['redirect'] = $this->session->data['redirect'];
  68. unset($this->session->data['redirect']);
  69. } else {
  70. $this->data['redirect'] = '';
  71. }
  72. if (isset($this->session->data['success'])) {
  73. $this->data['success'] = $this->session->data['success'];
  74. unset($this->session->data['success']);
  75. } else {
  76. $this->data['success'] = '';
  77. }
  78. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/login.tpl')) {
  79. $this->template = $this->config->get('config_template') . '/template/account/login.tpl';
  80. } else {
  81. $this->template = 'default/template/account/login.tpl';
  82. }
  83. $this->children = array(
  84. 'common/column_left',
  85. 'common/column_right',
  86. 'common/content_top',
  87. 'common/content_bottom',
  88. 'common/footer',
  89. 'common/header'
  90. );
  91. $this->response->setOutput($this->render());
  92. }
  93. private function validate() {
  94. if (!$this->customer->login($this->request->post['email'], $this->request->post['password'])) {
  95. $this->error['warning'] = $this->language->get('error_login');
  96. }
  97. if (!$this->error) {
  98. return true;
  99. } else {
  100. return false;
  101. }
  102. }
  103. }
  104. ?>