Example #1
0
 /**
  *
  */
 public function before()
 {
     $is_guest = \Registry::getCurrentUser()->isGuest();
     // Дополнительные функции
     $this->InitEnvironment();
     if (!Request::current()->is_ajax()) {
         // Add Google Font
         Assets::css('Google_Font', 'https://fonts.googleapis.com/css?family=Open+Sans:400,300,300italic,400italic,600,600italic,700,700italic&subset=latin,cyrillic-ext,cyrillic');
         /*ADD google maps JS*/
         Assets::js('google_maps_api', 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true&libraries=drawing&places&geometry');
         Assets::js('jQuery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js');
         Assets::css('bootstrap', 'http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css', ['media' => 'screen']);
         Assets::js('bootstrap', 'http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js');
         //GMAP Plugin js
         Assets::js('cluster', base_UI . 'js/plugins/gmap/marker.js');
         Assets::js('gmap', base_UI . 'js/plugins/gmap/gmaps.js');
         /*Базовые стили шаблона*/
         //Global Assets
         Assets::js('globalJS', base_UI . 'js/pages/global.js');
         Assets::css('awesome', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css');
         Assets::css('stl', base_UI . 'css/style.css');
         /*BootBox Js file*/
         Assets::js('BootBox', base_UI . 'libs/BootBox/bootbox.js');
         /*Login Js file*/
         Assets::js('LoginJs', base_UI . 'js/Auth/login.js');
         /*Register Js file*/
         Assets::js('RegisterJs', base_UI . 'js/Auth/register.js');
         //Zopim Helper js
         Assets::js('zopim', base_UI . 'js/index/zopim.js');
         //MAP js
         Assets::js('map1', base_UI . 'js/map/map.js');
         Assets::js('map2', base_UI . 'js/pages/map.js');
         Assets::js('map3', base_UI . 'js/map/catalog.js');
         $this->template = \smarty\View::init();
         $this->renderULogin();
         if (!$is_guest) {
             $access = new \Auth\Access(\Registry::getCurrentUser()->access_level);
             $user_id = \Registry::getCurrentUser()->iduser;
             $this->template->assign(['current_user' => \Registry::getCurrentUser(), 'isAdmin' => $access->get(\Auth\Access::User_Is_Admin), 'isModerator' => $access->get(\Auth\Access::User_Is_Moderator)]);
         } else {
             $this->template->assign(['current_user' => \Registry::getCurrentUser()]);
         }
         $this->template->assign(['localis' => $this->localis, 'local' => $this->i18n]);
     } else {
         $this->setJSONHeader();
         // Mobile API
         if (!isset($_POST)) {
             $error = array('status' => 'error', 'message' => 'No Data', 'code' => '2');
             echo json_encode($error);
             return;
         }
         /** @var $dbSession UserSession */
         if ($_POST['token']) {
             $condition = (new \DBCriteria())->addColumnCondition(['token' => $_POST['token']])->addCondition('`expired`>=UNIX_TIMESTAMP(NOW())');
             /** @var $dbSession UserSession */
             $sessionData = UserSession::model()->with('user')->find($condition);
             \Registry::setCurrentUser($sessionData->user);
         }
     }
 }
Example #2
0
 /**
  * @param $userInfo
  * @return bool
  * @throws \Kohana_Exception
  */
 public static function startSession($userInfo)
 {
     /** @var $conf array */
     $conf = \Kohana::$config->load('session')->get('native');
     /** @var $dbSession UserSession */
     $condition = (new \DBCriteria())->addColumnCondition(['ip' => \Request::$client_ip, 'token' => self::getToken()])->addCondition('`expired`>=UNIX_TIMESTAMP(NOW())');
     /** @var $dbSession UserSession */
     $sessionData = UserSession::model()->find($condition);
     if (!$sessionData) {
         $sessionData = new UserSession();
         $sessionData->iduser = $userInfo->iduser;
         $sessionData->ip = \Request::$client_ip;
         $sessionData->expired = time() + $conf['lifetime'];
         $sessionData->token = self::getToken();
     }
     if ($sessionData->save(false)) {
         \Session::instance()->set('user_id', $userInfo->iduser);
         \Session::instance()->set('user_token', $sessionData->token);
         \Registry::setCurrentUser($userInfo);
         return true;
     } else {
         return false;
     }
 }
Example #3
0
define('base_UI', Kohana::$base_url . 'template/default/');
//if(!defined('DS')) define('DS',DIRECTORY_SEPARATOR);
if (!defined('DS')) {
    define('DS', '/');
}
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
/**
 * Attach a file reader to config. Multiple readers are supported.
 */
Kohana::$config->attach(new Config_File());
/**
 * Enable modules. Modules are referenced by a relative or absolute path.
 */
Kohana::modules(['profilertoolbar' => MODPATH . 'profilertoolbar', 'cache' => MODPATH . 'cache', 'pagination' => MODPATH . 'pagination', 'image' => MODPATH . 'image', 'smarty' => MODPATH . 'smarty', 'email' => MODPATH . 'email', 'rawena' => MODPATH . 'rawena', 'dbrecord' => MODPATH . 'dbrecord', 'assets' => MODPATH . 'assets']);
//Add user model in registry
\Registry::setCurrentUser(new \Model\User());
$uri = $_SERVER['QUERY_STRING'];
$findme = 'useradmin';
$pos = strpos($uri, $findme);
if ($pos === false) {
    $panel = 'admin';
} else {
    $panel = 'user';
}
/**
 * Attach the file write to logging. Multiple writers are supported.
 */
//Kohana::$log->attach(new Log_File(APPPATH.'logs'));
//Kohana::$log->attach(new Kohana_Log_Profiler());
//Log::instance()->add(Log::ERROR,'Uyui');
function var_echo($var, $tab = 'default')