PageRenderTime 121ms CodeModel.GetById 1ms RepoModel.GetById 1ms app.codeStats 0ms

/catalog/controller/affiliate/login.php

https://gitlab.com/shapcy/opencart
PHP | 145 lines | 108 code | 33 blank | 4 comment | 28 complexity | 6d7f09532f2d5c4433cbc8d887945fb5 MD5 | raw file
  1. <?php
  2. class ControllerAffiliateLogin extends Controller {
  3. private $error = array();
  4. public function index() {
  5. if ($this->affiliate->isLogged()) {
  6. $this->response->redirect($this->url->link('affiliate/account', '', true));
  7. }
  8. $this->load->language('affiliate/login');
  9. $this->document->setTitle($this->language->get('heading_title'));
  10. $this->load->model('affiliate/affiliate');
  11. if (($this->request->server['REQUEST_METHOD'] == 'POST') && isset($this->request->post['email']) && isset($this->request->post['password']) && $this->validate()) {
  12. // Add to activity log
  13. $this->load->model('affiliate/activity');
  14. $activity_data = array(
  15. 'affiliate_id' => $this->affiliate->getId(),
  16. 'name' => $this->affiliate->getFirstName() . ' ' . $this->affiliate->getLastName()
  17. );
  18. $this->model_affiliate_activity->addActivity('login', $activity_data);
  19. // Added strpos check to pass McAfee PCI compliance test (http://forum.opencart.com/viewtopic.php?f=10&t=12043&p=151494#p151295)
  20. 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)) {
  21. $this->response->redirect(str_replace('&amp;', '&', $this->request->post['redirect']));
  22. } else {
  23. $this->response->redirect($this->url->link('affiliate/account', '', true));
  24. }
  25. }
  26. $data['breadcrumbs'] = array();
  27. $data['breadcrumbs'][] = array(
  28. 'text' => $this->language->get('text_home'),
  29. 'href' => $this->url->link('common/home')
  30. );
  31. $data['breadcrumbs'][] = array(
  32. 'text' => $this->language->get('text_account'),
  33. 'href' => $this->url->link('affiliate/account', '', true)
  34. );
  35. $data['breadcrumbs'][] = array(
  36. 'text' => $this->language->get('text_login'),
  37. 'href' => $this->url->link('affiliate/login', '', true)
  38. );
  39. $data['heading_title'] = $this->language->get('heading_title');
  40. $data['text_description'] = sprintf($this->language->get('text_description'), $this->config->get('config_name'), $this->config->get('config_name'), $this->config->get('config_affiliate_commission') . '%');
  41. $data['text_new_affiliate'] = $this->language->get('text_new_affiliate');
  42. $data['text_register_account'] = $this->language->get('text_register_account');
  43. $data['text_returning_affiliate'] = $this->language->get('text_returning_affiliate');
  44. $data['text_i_am_returning_affiliate'] = $this->language->get('text_i_am_returning_affiliate');
  45. $data['text_forgotten'] = $this->language->get('text_forgotten');
  46. $data['entry_email'] = $this->language->get('entry_email');
  47. $data['entry_password'] = $this->language->get('entry_password');
  48. $data['button_continue'] = $this->language->get('button_continue');
  49. $data['button_login'] = $this->language->get('button_login');
  50. if (isset($this->error['warning'])) {
  51. $data['error_warning'] = $this->error['warning'];
  52. } else {
  53. $data['error_warning'] = '';
  54. }
  55. $data['action'] = $this->url->link('affiliate/login', '', true);
  56. $data['register'] = $this->url->link('affiliate/register', '', true);
  57. $data['forgotten'] = $this->url->link('affiliate/forgotten', '', true);
  58. if (isset($this->request->post['redirect'])) {
  59. $data['redirect'] = $this->request->post['redirect'];
  60. } elseif (isset($this->session->data['redirect'])) {
  61. $data['redirect'] = $this->session->data['redirect'];
  62. unset($this->session->data['redirect']);
  63. } else {
  64. $data['redirect'] = '';
  65. }
  66. if (isset($this->session->data['success'])) {
  67. $data['success'] = $this->session->data['success'];
  68. unset($this->session->data['success']);
  69. } else {
  70. $data['success'] = '';
  71. }
  72. if (isset($this->request->post['email'])) {
  73. $data['email'] = $this->request->post['email'];
  74. } else {
  75. $data['email'] = '';
  76. }
  77. if (isset($this->request->post['password'])) {
  78. $data['password'] = $this->request->post['password'];
  79. } else {
  80. $data['password'] = '';
  81. }
  82. $data['column_left'] = $this->load->controller('common/column_left');
  83. $data['column_right'] = $this->load->controller('common/column_right');
  84. $data['content_top'] = $this->load->controller('common/content_top');
  85. $data['content_bottom'] = $this->load->controller('common/content_bottom');
  86. $data['footer'] = $this->load->controller('common/footer');
  87. $data['header'] = $this->load->controller('common/header');
  88. $this->response->setOutput($this->load->view('affiliate/login', $data));
  89. }
  90. protected function validate() {
  91. // Check how many login attempts have been made.
  92. $this->load->model('account/customer');
  93. $login_info = $this->model_account_customer->getLoginAttempts($this->request->post['email']);
  94. if ($login_info && ($login_info['total'] >= $this->config->get('config_login_attempts')) && strtotime('-1 hour') < strtotime($login_info['date_modified'])) {
  95. $this->error['warning'] = $this->language->get('error_attempts');
  96. }
  97. // Check if affiliate has been approved.
  98. $affiliate_info = $this->model_affiliate_affiliate->getAffiliateByEmail($this->request->post['email']);
  99. if ($affiliate_info && !$affiliate_info['approved']) {
  100. $this->error['warning'] = $this->language->get('error_approved');
  101. }
  102. if (!$this->error) {
  103. if (!$this->affiliate->login($this->request->post['email'], $this->request->post['password'])) {
  104. $this->error['warning'] = $this->language->get('error_login');
  105. $this->model_account_customer->addLoginAttempt($this->request->post['email']);
  106. } else {
  107. $this->model_account_customer->deleteLoginAttempts($this->request->post['email']);
  108. }
  109. }
  110. return !$this->error;
  111. }
  112. }