public function register()
 {
     try {
         $errors = array();
         $success = false;
         $isPost = $this->request->isPost();
         $user = new User();
         try {
             $fb_active = API_Facebook::isActive();
             if ($fb_active) {
                 $fb_user = $user->getFacebookUser(ROOT_HTTP . 'register');
                 if (!empty($fb_user)) {
                     $this->response->redirect(ROOT_HTTP);
                 }
             }
         } catch (Exception $e) {
             $errors['authent'] = $e->getMessage();
         }
         $confirm_email = $this->request->post('confirm_email', '');
         $confirm_password = $this->request->post('confirm_password', '');
         if ($isPost) {
             foreach ($user->getFields() as $key => $value) {
                 try {
                     $user->{$key} = $this->request->post($key, '');
                 } catch (Exception $e) {
                     $errors[$key] = $e->getMessage();
                 }
             }
             if (empty($confirm_email) || strcmp($user->email, $confirm_email) !== 0) {
                 $errors['confirm_email'] = Lang::_('You must confirm your email');
             }
             if (empty($confirm_password) || strcmp($user->password, $confirm_password) !== 0) {
                 $errors['confirm_password'] = Lang::_('You must confirm your password');
             }
             if (empty($errors)) {
                 $user_already_exists = $user->checkAlreadyExists();
                 if ($user_already_exists === true) {
                     $errors['email'] = Lang::_('Email already in use');
                 } else {
                     $user->password = password_hash($user->password, PASSWORD_BCRYPT);
                     $user_id = $user->register();
                     if (!empty($user_id)) {
                         $success = $user->login();
                     } else {
                         $errors['authent'] = Lang::_('Register failed');
                     }
                 }
             }
         }
         $form = $user->getRegisterForm('insert', ROOT_HTTP . $this->lang->getUserLang() . '/user/register', $this->request, $isPost, $errors);
         $vars = array('title' => Lang::_('Register'), 'isPost' => $isPost, 'form' => $form, 'errors' => $errors, 'success' => $success);
     } catch (Exception $e) {
         $vars['debug'] = $e->getMessage();
     }
     return $this->render('authent', $vars);
 }