/**
  * The Register action allows a user to register a new account.
  *
  * @return array Data given
  */
 protected function register()
 {
     $regions = $this->model->getregion();
     $data = Request::getAssoc(array('nickname', 'password', 'password_confirm', 'email', 'firstname', 'lastname', 'cgu', 'g-recaptcha-response'));
     if (!in_array(null, $data, true)) {
         $data += Request::getAssoc(array('adress', 'zip_code', 'city', 'region', 'phone', 'newsletter'));
         $errors = array();
         // Check Captcha
         require LIBS_DIR . 'ReCaptcha' . DS . 'autoload.php';
         $recaptcha = new \ReCaptcha\ReCaptcha('6LdmkBMTAAAAAKRjvJVIrAsNbiTUJpFk3IdC7LXt');
         $resp = $recaptcha->verify($data['g-recaptcha-response'], Session::getIP());
         if (!$resp->isSuccess()) {
             $errors[] = 'Captcha incorrect !';
         }
         // Check nickname availability
         if (($e = $this->model->checkNickname($data['nickname'])) !== true) {
             $errors[] = $e;
         }
         // Matching passwords
         if (!empty($data['password'])) {
             if ($data['password'] === $data['password_confirm']) {
                 $data['password'] = sha1($data['password']);
             } else {
                 $errors[] = 'Les mots de passe saisis ne concordent pas.';
             }
         } else {
             $errors[] = 'Aucun mot de passe n\'a été saisi.';
         }
         // Email availability
         if (($e = $this->model->checkEmail($data['email'])) !== true) {
             $errors[] = $e;
         }
         if (empty($errors)) {
             // Set a confirm code
             $data['confirm'] = uniqid();
             // Configure user
             $user_id = $this->model->createUser($data);
             if ($user_id !== false) {
                 // Send a validation email
                 $headers = "From: " . strip_tags(Config::get('config.email')) . "\r\n";
                 $headers .= "Reply-To: " . strip_tags(Config::get('config.email')) . "\r\n";
                 $headers .= "MIME-Version: 1.0\r\n";
                 $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
                 $message = 'Bonjour <strong>' . $data['nickname'] . '</strong>,<br><br>' . "\r\n";
                 $message .= 'Votre inscription sur Event-You-All a bien été prise en compte !<br>Cependant, vous devez toujours confirmer votre email avant de pouvoir vous connecter !<br><br>' . "\r\n";
                 $message .= 'Pour pouvoir valider votre email, veuillez cliquer sur <a href="' . Config::get('config.base') . '/user/activate/' . $data['confirm'] . '">ce lien</a><br><br>' . "\r\n";
                 $message .= 'Merci et à bientôt sur Event-You-All !';
                 mail($data['email'], 'Event-You-All : Validez votre inscription', $message, $headers);
                 return array('data' => $data, 'success' => true);
             } else {
                 return array('data' => $data, 'errors' => array('Une erreur inconnue est survenue durant l\'inscription'));
             }
         } else {
             return array('data' => $data, 'errors' => $errors);
         }
     } else {
         if (Request::getMethod() == 'POST') {
             return array('data' => $data, 'errors' => array('Tous les champs requis n\'ont pas été renseignés'), 'regions' => $regions);
         }
     }
     return array('data' => $data, 'errors' => array(), 'regions' => $regions);
 }