shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

forgotten.php (2810B)


      1 <?php
      2 class ControllerAccountForgotten 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('account/forgotten');
     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') && $this->validate()) {
     17 			$this->model_account_customer->editCode($this->request->post['email'], token(40));
     18 
     19 			$this->session->data['success'] = $this->language->get('text_success');
     20 
     21 			$this->response->redirect($this->url->link('account/login', '', true));
     22 		}
     23 
     24 		$data['breadcrumbs'] = array();
     25 
     26 		$data['breadcrumbs'][] = array(
     27 			'text' => $this->language->get('text_home'),
     28 			'href' => $this->url->link('common/home')
     29 		);
     30 
     31 		$data['breadcrumbs'][] = array(
     32 			'text' => $this->language->get('text_account'),
     33 			'href' => $this->url->link('account/account', '', true)
     34 		);
     35 
     36 		$data['breadcrumbs'][] = array(
     37 			'text' => $this->language->get('text_forgotten'),
     38 			'href' => $this->url->link('account/forgotten', '', true)
     39 		);
     40 
     41 		if (isset($this->error['warning'])) {
     42 			$data['error_warning'] = $this->error['warning'];
     43 		} else {
     44 			$data['error_warning'] = '';
     45 		}
     46 
     47 		$data['action'] = $this->url->link('account/forgotten', '', true);
     48 
     49 		$data['back'] = $this->url->link('account/login', '', true);
     50 
     51 		if (isset($this->request->post['email'])) {
     52 			$data['email'] = $this->request->post['email'];
     53 		} else {
     54 			$data['email'] = '';
     55 		}
     56 
     57 		$data['column_left'] = $this->load->controller('common/column_left');
     58 		$data['column_right'] = $this->load->controller('common/column_right');
     59 		$data['content_top'] = $this->load->controller('common/content_top');
     60 		$data['content_bottom'] = $this->load->controller('common/content_bottom');
     61 		$data['footer'] = $this->load->controller('common/footer');
     62 		$data['header'] = $this->load->controller('common/header');
     63 
     64 		$this->response->setOutput($this->load->view('account/forgotten', $data));
     65 	}
     66 
     67 	protected function validate() {
     68 		if (!isset($this->request->post['email'])) {
     69 			$this->error['warning'] = $this->language->get('error_email');
     70 		} elseif (!$this->model_account_customer->getTotalCustomersByEmail($this->request->post['email'])) {
     71 			$this->error['warning'] = $this->language->get('error_email');
     72 		}
     73 		
     74 		// Check if customer has been approved.
     75 		$customer_info = $this->model_account_customer->getCustomerByEmail($this->request->post['email']);
     76 
     77 		if ($customer_info && !$customer_info['status']) {
     78 			$this->error['warning'] = $this->language->get('error_approved');
     79 		}
     80 
     81 		return !$this->error;
     82 	}
     83 }