示例#1
0
文件: admin.php 项目: Maxlander/shixi
 /**
  * authorizing administrator
  *
  * Function checks if there's active administrator.
  * If it is, then it return true. If it's not it outputs
  * form for logging into system untill administrator logins system
  *
  * @return bool 'true' administrator has authorized or 'false' otherwise
  */
 public static function admin_auth()
 {
     $error = array();
     $tp = SJB_System::getTemplateProcessor();
     $params = SJB_HelperFunctions::form(array('action' => 'login') + SJB_HelperFunctions::get_request_data_params());
     if (SJB_Request::getVar('action') == 'login') {
         if (!SJB_Admin::isAdminExist(SJB_Request::getVar('username', ''), SJB_Request::getVar('password')) && !SJB_SubAdmin::isSubAdminExist()) {
             if (is_null(SJB_Session::getValue('adminLoginCounter'))) {
                 SJB_Session::setValue('adminLoginCounter', 1);
             } else {
                 SJB_Session::setValue('adminLoginCounter', SJB_Session::getValue('adminLoginCounter') + 1);
             }
             $error['LOGIN_PASS_NOT_CORRECT'] = true;
         }
         if (SJB_Captcha::getInstance($tp, $_REQUEST)->isValid($error) && empty($error)) {
             return SJB_SubAdmin::isSubAdminExist() ? SJB_SubAdmin::admin_auth() : SJB_Admin::admin_login(SJB_Request::getVar('username', ''));
         }
     }
     header('Content-type: text/html;charset=utf-8', true);
     $tp->assign('form_hidden_params', $params);
     $tp->assign('ERROR', $error);
     $tp->display('auth.tpl');
     return false;
 }