reset.php (3218B)
1 <?php 2 class ControllerCommonReset 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 if (isset($this->request->get['code'])) { 15 $code = $this->request->get['code']; 16 } else { 17 $code = ''; 18 } 19 20 $this->load->model('user/user'); 21 22 $user_info = $this->model_user_user->getUserByCode($code); 23 24 if ($user_info) { 25 $this->load->language('common/reset'); 26 27 $this->document->setTitle($this->language->get('heading_title')); 28 29 if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { 30 $this->model_user_user->editPassword($user_info['user_id'], $this->request->post['password']); 31 32 $this->session->data['success'] = $this->language->get('text_success'); 33 34 $this->response->redirect($this->url->link('common/login', '', true)); 35 } 36 37 $data['breadcrumbs'] = array(); 38 39 $data['breadcrumbs'][] = array( 40 'text' => $this->language->get('text_home'), 41 'href' => $this->url->link('common/dashboard', '', true) 42 ); 43 44 $data['breadcrumbs'][] = array( 45 'text' => $this->language->get('heading_title'), 46 'href' => $this->url->link('common/reset', '', true) 47 ); 48 49 if (isset($this->error['password'])) { 50 $data['error_password'] = $this->error['password']; 51 } else { 52 $data['error_password'] = ''; 53 } 54 55 if (isset($this->error['confirm'])) { 56 $data['error_confirm'] = $this->error['confirm']; 57 } else { 58 $data['error_confirm'] = ''; 59 } 60 61 $data['action'] = $this->url->link('common/reset', 'code=' . $code, true); 62 63 $data['cancel'] = $this->url->link('common/login', '', true); 64 65 if (isset($this->request->post['password'])) { 66 $data['password'] = $this->request->post['password']; 67 } else { 68 $data['password'] = ''; 69 } 70 71 if (isset($this->request->post['confirm'])) { 72 $data['confirm'] = $this->request->post['confirm']; 73 } else { 74 $data['confirm'] = ''; 75 } 76 77 $data['header'] = $this->load->controller('common/header'); 78 $data['footer'] = $this->load->controller('common/footer'); 79 80 $this->response->setOutput($this->load->view('common/reset', $data)); 81 } else { 82 $this->load->model('setting/setting'); 83 84 $this->model_setting_setting->editSettingValue('config', 'config_password', '0'); 85 86 return new Action('common/login'); 87 } 88 } 89 90 protected function validate() { 91 if ((utf8_strlen(html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8')) < 4) || (utf8_strlen(html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8')) > 40)) { 92 $this->error['password'] = $this->language->get('error_password'); 93 } 94 95 if ($this->request->post['confirm'] != $this->request->post['password']) { 96 $this->error['confirm'] = $this->language->get('error_confirm'); 97 } 98 99 return !$this->error; 100 } 101 }