forgotten.php (2325B)
1 <?php 2 class ControllerCommonForgotten extends Controller { 3 private $error = array(); 4 5 public function index() { 6 if ($this->user->isLogged() && isset($this->request->get['user_token']) && ($this->request->get['user_token'] == $this->session->data['user_token'])) { 7 $this->response->redirect($this->url->link('common/dashboard', '', true)); 8 } 9 10 if (!$this->config->get('config_password')) { 11 $this->response->redirect($this->url->link('common/login', '', true)); 12 } 13 14 $this->load->language('common/forgotten'); 15 16 $this->document->setTitle($this->language->get('heading_title')); 17 18 $this->load->model('user/user'); 19 20 if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { 21 $this->model_user_user->editCode($this->request->post['email'], token(40)); 22 23 $this->session->data['success'] = $this->language->get('text_success'); 24 25 $this->response->redirect($this->url->link('common/login', '', true)); 26 } 27 28 if (isset($this->error['warning'])) { 29 $data['error_warning'] = $this->error['warning']; 30 } else { 31 $data['error_warning'] = ''; 32 } 33 34 $data['breadcrumbs'] = array(); 35 36 $data['breadcrumbs'][] = array( 37 'text' => $this->language->get('text_home'), 38 'href' => $this->url->link('common/dashboard', '', true) 39 ); 40 41 $data['breadcrumbs'][] = array( 42 'text' => $this->language->get('heading_title'), 43 'href' => $this->url->link('common/forgotten', 'user_token=' . '', true) 44 ); 45 46 $data['action'] = $this->url->link('common/forgotten', '', true); 47 48 $data['cancel'] = $this->url->link('common/login', '', true); 49 50 if (isset($this->request->post['email'])) { 51 $data['email'] = $this->request->post['email']; 52 } else { 53 $data['email'] = ''; 54 } 55 56 $data['header'] = $this->load->controller('common/header'); 57 $data['footer'] = $this->load->controller('common/footer'); 58 59 $this->response->setOutput($this->load->view('common/forgotten', $data)); 60 } 61 62 protected function validate() { 63 if (!isset($this->request->post['email'])) { 64 $this->error['warning'] = $this->language->get('error_email'); 65 } elseif (!$this->model_user_user->getTotalUsersByEmail($this->request->post['email'])) { 66 $this->error['warning'] = $this->language->get('error_email'); 67 } 68 69 return !$this->error; 70 } 71 }