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