예제 #1
0
 public function register($do)
 {
     if (isset($_SESSION[UID . 'USER']['id'])) {
         header('Location: ' . \CODOF\User\User::getProfileUrl());
         exit;
     }
     $this->view = 'user/register';
     $set_fields = array('username', 'password', 'mail');
     $req_fields = array('username', 'password', 'mail');
     $this->js_files = array(array(DATA_PATH . 'assets/js/user/register.js', array('type' => 'defer')));
     if (\CODOF\Util::is_set($_REQUEST, $set_fields) && !\CODOF\Util::is_empty($_REQUEST, $req_fields) && $do) {
         $register = new \CODOF\User\Register($this->db);
         $register->username = str_replace('"', '"', $_REQUEST['username']);
         $register->name = null;
         //$_REQUEST['name'];
         $register->password = $_REQUEST["password"];
         $register->mail = $_REQUEST['mail'];
         $register->rid = ROLE_UNVERIFIED;
         $errors = $register->get_errors();
         if (empty($errors)) {
             $errors = $register->register_user();
             $register->login();
             header('Location: ' . \CODOF\User\User::getProfileUrl());
             exit;
         }
         $this->smarty->assign('errors', $errors);
     } else {
         $register = new \stdClass();
         $register->username = null;
         $register->name = null;
         //$_REQUEST['name'];
         $register->password = null;
         $register->mail = null;
     }
     if (\CODOF\Util::get_opt('captcha') == "enabled") {
         $publickey = \CODOF\Util::get_opt('captcha_public_key');
         // you got this from the signup page
         $this->smarty->assign('recaptcha', '<div class="g-recaptcha col-md-6" data-sitekey="' . $publickey . '"></div>');
         $this->js_files[] = array('https://www.google.com/recaptcha/api.js', array('type' => 'remote'));
     }
     $this->smarty->assign('min_pass_len', \CODOF\Util::get_opt('register_pass_min'));
     $this->smarty->assign('min_username_len', \CODOF\Util::get_opt('register_username_min'));
     $this->smarty->assign('register', $register);
     \CODOF\Store::set('sub_title', 'Register');
 }