Пример #1
0
 /**
  * Login form
  *
  * @return  void
  */
 public function _default()
 {
     if (X4Utils_helper::is_ajax()) {
         $view = new X4View_core('empty');
         $view->location = BASE_URL . 'login';
     } else {
         // initialize failure counter
         if (!isset($_SESSION['failed'])) {
             $_SESSION['failed'] = 0;
         }
         // load dictionary
         $this->dict->get_wordarray(array('login'));
         // get page
         $page = $this->get_page('login');
         // contents
         $view = new X4View_core(X4Utils_helper::set_tpl($page->tpl));
         $view->page = $page;
         $view->menus = array();
         $view->content = new X4View_core('login');
         // check if user have used remember me
         if (isset($_COOKIE[COOKIE . '_login'])) {
             list($usr, $hidden_pwd) = explode('-', $_COOKIE[COOKIE . '_login']);
             $pwd = '12345678';
             $chk = true;
         } else {
             $usr = $pwd = '';
             $chk = false;
         }
         // build the form
         $fields = array();
         // antispam control
         $fields[] = array('label' => null, 'type' => 'hidden', 'value' => time(), 'name' => 'antispam');
         $fields[] = array('label' => _USERNAME, 'type' => 'text', 'value' => $usr, 'name' => 'username', 'rule' => 'required', 'sanitize' => 'string', 'extra' => 'class="large"');
         $fields[] = array('label' => _PASSWORD, 'type' => 'password', 'value' => $pwd, 'name' => 'password', 'rule' => 'required|minlength§5', 'sanitize' => 'string', 'extra' => 'class="large"');
         if ($chk) {
             $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $hidden_pwd, 'name' => 'hpwd');
         }
         $fields[] = array('label' => _REMEMBER_ME, 'type' => 'checkbox', 'value' => '1', 'name' => 'remember_me', 'checked' => $chk);
         // if site is on line and user is unknown or fails his login add captcha
         if ($this->site->site->xon && !$chk && isset($_SESSION['failed'])) {
             $fields[] = array('label' => _CAPTCHA, 'type' => 'text', 'value' => '', 'name' => 'captcha', 'rule' => 'required|captcha', 'suggestion' => _CAPTCHA_MSG, 'extra' => 'class="large" autocomplete="off"');
             $fields[] = array('label' => null, 'type' => 'html', 'value' => '<div id="cha" class="acenter"><img id="captcha_img" src="' . BASE_URL . 'captcha/51/51/51" alt="captcha" /></div>');
             $fields[] = array('label' => null, 'type' => 'html', 'value' => '<p class="small"><a href="' . BASE_URL . 'captcha/51/51/51" title="reload" id="reload_captcha">' . _RELOAD_CAPTCHA . '</a></p>');
         }
         // if submitted, check control field
         if (X4Route_core::$post && array_key_exists(strrev('formlogin'), $_POST)) {
             $e = X4Validation_helper::form($fields, 'formlogin');
             if ($e && !isset($_POST['antispam'])) {
                 $this->do_login($_POST);
                 die;
             } else {
                 X4Utils_helper::set_error($fields);
             }
         }
         // msg
         if (isset($_SESSION['msg']) && !empty($_SESSION['msg'])) {
             $view->content->msg = $_SESSION['msg'];
             unset($_SESSION['msg']);
         }
         // failure message
         if ($_SESSION['failed']) {
             $view->content->msg = $_SESSION['failed'] < 5 ? str_replace('XXX', $_SESSION['failed'], _FAILED_X_TIMES) : _FAILED_TOO_TIMES;
         }
         // form builder
         $view->content->form = X4Form_helper::doform('formlogin', $_SERVER['REQUEST_URI'], $fields, array(null, _LOGIN, 'buttons'));
     }
     $view->render(TRUE);
 }