PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/catalog/controller/checkout/login.php

https://gitlab.com/hazelnuts23/unitedfoodstuff
PHP | 111 lines | 81 code | 27 blank | 3 comment | 25 complexity | e5cd33372f3e4427c933e7d2dfa06e63 MD5 | raw file
  1. <?php
  2. class ControllerCheckoutLogin extends Controller {
  3. public function index() {
  4. $this->load->language('checkout/checkout');
  5. $data['text_checkout_account'] = $this->language->get('text_checkout_account');
  6. $data['text_checkout_payment_address'] = $this->language->get('text_checkout_payment_address');
  7. $data['text_new_customer'] = $this->language->get('text_new_customer');
  8. $data['text_returning_customer'] = $this->language->get('text_returning_customer');
  9. $data['text_checkout'] = $this->language->get('text_checkout');
  10. $data['text_register'] = $this->language->get('text_register');
  11. $data['text_guest'] = $this->language->get('text_guest');
  12. $data['text_i_am_returning_customer'] = $this->language->get('text_i_am_returning_customer');
  13. $data['text_register_account'] = $this->language->get('text_register_account');
  14. $data['text_forgotten'] = $this->language->get('text_forgotten');
  15. $data['text_loading'] = $this->language->get('text_loading');
  16. $data['entry_email'] = $this->language->get('entry_email');
  17. $data['entry_password'] = $this->language->get('entry_password');
  18. $data['button_continue'] = $this->language->get('button_continue');
  19. $data['button_login'] = $this->language->get('button_login');
  20. $data['checkout_guest'] = ($this->config->get('config_checkout_guest') && !$this->config->get('config_customer_price') && !$this->cart->hasDownload());
  21. if (isset($this->session->data['account'])) {
  22. $data['account'] = $this->session->data['account'];
  23. } else {
  24. $data['account'] = 'register';
  25. }
  26. $data['forgotten'] = $this->url->link('account/forgotten', '', 'SSL');
  27. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/checkout/login.tpl')) {
  28. $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/checkout/login.tpl', $data));
  29. } else {
  30. $this->response->setOutput($this->load->view('default/template/checkout/login.tpl', $data));
  31. }
  32. }
  33. public function save() {
  34. $this->load->language('checkout/checkout');
  35. $json = array();
  36. if ($this->customer->isLogged()) {
  37. $json['redirect'] = $this->url->link('checkout/checkout', '', 'SSL');
  38. }
  39. if ((!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) {
  40. $json['redirect'] = $this->url->link('checkout/cart');
  41. }
  42. if (!$json) {
  43. $this->load->model('account/customer');
  44. // Check how many login attempts have been made.
  45. $login_info = $this->model_account_customer->getLoginAttempts($this->request->post['email']);
  46. if ($login_info && ($login_info['total'] >= $this->config->get('config_login_attempts')) && strtotime('-1 hour') < strtotime($login_info['date_modified'])) {
  47. $json['error']['warning'] = $this->language->get('error_attempts');
  48. }
  49. // Check if customer has been approved.
  50. $customer_info = $this->model_account_customer->getCustomerByEmail($this->request->post['email']);
  51. if ($customer_info && !$customer_info['approved']) {
  52. $json['error']['warning'] = $this->language->get('error_approved');
  53. }
  54. if (!isset($json['error'])) {
  55. if (!$this->customer->login($this->request->post['email'], $this->request->post['password'])) {
  56. $json['error']['warning'] = $this->language->get('error_login');
  57. $this->model_account_customer->addLoginAttempt($this->request->post['email']);
  58. } else {
  59. $this->model_account_customer->deleteLoginAttempts($this->request->post['email']);
  60. }
  61. }
  62. }
  63. if (!$json) {
  64. unset($this->session->data['guest']);
  65. $this->load->model('account/address');
  66. if ($this->config->get('config_tax_customer') == 'payment') {
  67. $this->session->data['payment_address'] = $this->model_account_address->getAddress($this->customer->getAddressId());
  68. }
  69. if ($this->config->get('config_tax_customer') == 'shipping') {
  70. $this->session->data['shipping_address'] = $this->model_account_address->getAddress($this->customer->getAddressId());
  71. }
  72. $json['redirect'] = $this->url->link('checkout/checkout', '', 'SSL');
  73. // Add to activity log
  74. $this->load->model('account/activity');
  75. $activity_data = array(
  76. 'customer_id' => $this->customer->getId(),
  77. 'name' => $this->customer->getFirstName() . ' ' . $this->customer->getLastName()
  78. );
  79. $this->model_account_activity->addActivity('login', $activity_data);
  80. }
  81. $this->response->addHeader('Content-Type: application/json');
  82. $this->response->setOutput(json_encode($json));
  83. }
  84. }