register.php (11914B)
1 <?php 2 class ControllerAccountRegister 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/register'); 11 12 $this->document->setTitle($this->language->get('heading_title')); 13 14 $this->document->addScript('catalog/view/javascript/jquery/datetimepicker/moment/moment.min.js'); 15 $this->document->addScript('catalog/view/javascript/jquery/datetimepicker/moment/moment-with-locales.min.js'); 16 $this->document->addScript('catalog/view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.js'); 17 $this->document->addStyle('catalog/view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.css'); 18 19 $this->load->model('account/customer'); 20 21 if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { 22 $customer_id = $this->model_account_customer->addCustomer($this->request->post); 23 24 // Clear any previous login attempts for unregistered accounts. 25 $this->model_account_customer->deleteLoginAttempts($this->request->post['email']); 26 27 $this->customer->login($this->request->post['email'], $this->request->post['password']); 28 29 unset($this->session->data['guest']); 30 31 $this->response->redirect($this->url->link('account/success')); 32 } 33 34 $data['breadcrumbs'] = array(); 35 36 $data['breadcrumbs'][] = array( 37 'text' => $this->language->get('text_home'), 38 'href' => $this->url->link('common/home') 39 ); 40 41 $data['breadcrumbs'][] = array( 42 'text' => $this->language->get('text_account'), 43 'href' => $this->url->link('account/account', '', true) 44 ); 45 46 $data['breadcrumbs'][] = array( 47 'text' => $this->language->get('text_register'), 48 'href' => $this->url->link('account/register', '', true) 49 ); 50 $data['text_account_already'] = sprintf($this->language->get('text_account_already'), $this->url->link('account/login', '', true)); 51 52 if (isset($this->error['warning'])) { 53 $data['error_warning'] = $this->error['warning']; 54 } else { 55 $data['error_warning'] = ''; 56 } 57 58 if (isset($this->error['firstname'])) { 59 $data['error_firstname'] = $this->error['firstname']; 60 } else { 61 $data['error_firstname'] = ''; 62 } 63 64 if (isset($this->error['lastname'])) { 65 $data['error_lastname'] = $this->error['lastname']; 66 } else { 67 $data['error_lastname'] = ''; 68 } 69 70 if (isset($this->error['email'])) { 71 $data['error_email'] = $this->error['email']; 72 } else { 73 $data['error_email'] = ''; 74 } 75 76 if (isset($this->error['telephone'])) { 77 $data['error_telephone'] = $this->error['telephone']; 78 } else { 79 $data['error_telephone'] = ''; 80 } 81 82 if (isset($this->error['custom_field'])) { 83 $data['error_custom_field'] = $this->error['custom_field']; 84 } else { 85 $data['error_custom_field'] = array(); 86 } 87 88 if (isset($this->error['password'])) { 89 $data['error_password'] = $this->error['password']; 90 } else { 91 $data['error_password'] = ''; 92 } 93 94 if (isset($this->error['confirm'])) { 95 $data['error_confirm'] = $this->error['confirm']; 96 } else { 97 $data['error_confirm'] = ''; 98 } 99 100 $data['action'] = $this->url->link('account/register', '', true); 101 102 $data['customer_groups'] = array(); 103 104 if (is_array($this->config->get('config_customer_group_display'))) { 105 $this->load->model('account/customer_group'); 106 107 $customer_groups = $this->model_account_customer_group->getCustomerGroups(); 108 109 foreach ($customer_groups as $customer_group) { 110 if (in_array($customer_group['customer_group_id'], $this->config->get('config_customer_group_display'))) { 111 $data['customer_groups'][] = $customer_group; 112 } 113 } 114 } 115 116 if (isset($this->request->post['customer_group_id'])) { 117 $data['customer_group_id'] = $this->request->post['customer_group_id']; 118 } else { 119 $data['customer_group_id'] = $this->config->get('config_customer_group_id'); 120 } 121 122 if (isset($this->request->post['firstname'])) { 123 $data['firstname'] = $this->request->post['firstname']; 124 } else { 125 $data['firstname'] = ''; 126 } 127 128 if (isset($this->request->post['lastname'])) { 129 $data['lastname'] = $this->request->post['lastname']; 130 } else { 131 $data['lastname'] = ''; 132 } 133 134 if (isset($this->request->post['email'])) { 135 $data['email'] = $this->request->post['email']; 136 } else { 137 $data['email'] = ''; 138 } 139 140 if (isset($this->request->post['telephone'])) { 141 $data['telephone'] = $this->request->post['telephone']; 142 } else { 143 $data['telephone'] = ''; 144 } 145 146 // Custom Fields 147 $data['custom_fields'] = array(); 148 149 $this->load->model('account/custom_field'); 150 151 $custom_fields = $this->model_account_custom_field->getCustomFields(); 152 153 foreach ($custom_fields as $custom_field) { 154 if ($custom_field['location'] == 'account') { 155 $data['custom_fields'][] = $custom_field; 156 } 157 } 158 159 if (isset($this->request->post['custom_field']['account'])) { 160 $data['register_custom_field'] = $this->request->post['custom_field']['account']; 161 } else { 162 $data['register_custom_field'] = array(); 163 } 164 165 if (isset($this->request->post['password'])) { 166 $data['password'] = $this->request->post['password']; 167 } else { 168 $data['password'] = ''; 169 } 170 171 if (isset($this->request->post['confirm'])) { 172 $data['confirm'] = $this->request->post['confirm']; 173 } else { 174 $data['confirm'] = ''; 175 } 176 177 if (isset($this->request->post['newsletter'])) { 178 $data['newsletter'] = $this->request->post['newsletter']; 179 } else { 180 $data['newsletter'] = ''; 181 } 182 183 // Captcha 184 if ($this->config->get('captcha_' . $this->config->get('config_captcha') . '_status') && in_array('register', (array)$this->config->get('config_captcha_page'))) { 185 $data['captcha'] = $this->load->controller('extension/captcha/' . $this->config->get('config_captcha'), $this->error); 186 } else { 187 $data['captcha'] = ''; 188 } 189 190 if ($this->config->get('config_account_id')) { 191 $this->load->model('catalog/information'); 192 193 $information_info = $this->model_catalog_information->getInformation($this->config->get('config_account_id')); 194 195 if ($information_info) { 196 $data['text_agree'] = sprintf($this->language->get('text_agree'), $this->url->link('information/information/agree', 'information_id=' . $this->config->get('config_account_id'), true), $information_info['title'], $information_info['title']); 197 } else { 198 $data['text_agree'] = ''; 199 } 200 } else { 201 $data['text_agree'] = ''; 202 } 203 204 if (isset($this->request->post['agree'])) { 205 $data['agree'] = $this->request->post['agree']; 206 } else { 207 $data['agree'] = false; 208 } 209 210 $data['column_left'] = $this->load->controller('common/column_left'); 211 $data['column_right'] = $this->load->controller('common/column_right'); 212 $data['content_top'] = $this->load->controller('common/content_top'); 213 $data['content_bottom'] = $this->load->controller('common/content_bottom'); 214 $data['footer'] = $this->load->controller('common/footer'); 215 $data['header'] = $this->load->controller('common/header'); 216 217 $this->response->setOutput($this->load->view('account/register', $data)); 218 } 219 220 private function validate() { 221 if ((utf8_strlen(trim($this->request->post['firstname'])) < 1) || (utf8_strlen(trim($this->request->post['firstname'])) > 32)) { 222 $this->error['firstname'] = $this->language->get('error_firstname'); 223 } 224 225 if ((utf8_strlen(trim($this->request->post['lastname'])) < 1) || (utf8_strlen(trim($this->request->post['lastname'])) > 32)) { 226 $this->error['lastname'] = $this->language->get('error_lastname'); 227 } 228 229 if ((utf8_strlen($this->request->post['email']) > 96) || !filter_var($this->request->post['email'], FILTER_VALIDATE_EMAIL)) { 230 $this->error['email'] = $this->language->get('error_email'); 231 } 232 233 if ($this->model_account_customer->getTotalCustomersByEmail($this->request->post['email'])) { 234 $this->error['warning'] = $this->language->get('error_exists'); 235 } 236 237 if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 32)) { 238 $this->error['telephone'] = $this->language->get('error_telephone'); 239 } 240 241 // Customer Group 242 if (isset($this->request->post['customer_group_id']) && is_array($this->config->get('config_customer_group_display')) && in_array($this->request->post['customer_group_id'], $this->config->get('config_customer_group_display'))) { 243 $customer_group_id = $this->request->post['customer_group_id']; 244 } else { 245 $customer_group_id = $this->config->get('config_customer_group_id'); 246 } 247 248 // Custom field validation 249 $this->load->model('account/custom_field'); 250 251 $custom_fields = $this->model_account_custom_field->getCustomFields($customer_group_id); 252 253 foreach ($custom_fields as $custom_field) { 254 if ($custom_field['location'] == 'account') { 255 if ($custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']])) { 256 $this->error['custom_field'][$custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']); 257 } elseif (($custom_field['type'] == 'text') && !empty($custom_field['validation']) && !filter_var($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => $custom_field['validation'])))) { 258 $this->error['custom_field'][$custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']); 259 } 260 } 261 } 262 263 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)) { 264 $this->error['password'] = $this->language->get('error_password'); 265 } 266 267 if ($this->request->post['confirm'] != $this->request->post['password']) { 268 $this->error['confirm'] = $this->language->get('error_confirm'); 269 } 270 271 // Captcha 272 if ($this->config->get('captcha_' . $this->config->get('config_captcha') . '_status') && in_array('register', (array)$this->config->get('config_captcha_page'))) { 273 $captcha = $this->load->controller('extension/captcha/' . $this->config->get('config_captcha') . '/validate'); 274 275 if ($captcha) { 276 $this->error['captcha'] = $captcha; 277 } 278 } 279 280 // Agree to terms 281 if ($this->config->get('config_account_id')) { 282 $this->load->model('catalog/information'); 283 284 $information_info = $this->model_catalog_information->getInformation($this->config->get('config_account_id')); 285 286 if ($information_info && !isset($this->request->post['agree'])) { 287 $this->error['warning'] = sprintf($this->language->get('error_agree'), $information_info['title']); 288 } 289 } 290 291 return !$this->error; 292 } 293 294 public function customfield() { 295 $json = array(); 296 297 $this->load->model('account/custom_field'); 298 299 // Customer Group 300 if (isset($this->request->get['customer_group_id']) && is_array($this->config->get('config_customer_group_display')) && in_array($this->request->get['customer_group_id'], $this->config->get('config_customer_group_display'))) { 301 $customer_group_id = $this->request->get['customer_group_id']; 302 } else { 303 $customer_group_id = $this->config->get('config_customer_group_id'); 304 } 305 306 $custom_fields = $this->model_account_custom_field->getCustomFields($customer_group_id); 307 308 foreach ($custom_fields as $custom_field) { 309 $json[] = array( 310 'custom_field_id' => $custom_field['custom_field_id'], 311 'required' => $custom_field['required'] 312 ); 313 } 314 315 $this->response->addHeader('Content-Type: application/json'); 316 $this->response->setOutput(json_encode($json)); 317 } 318 }