/**
  *
  */
 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);
         }
     }
 }
Exemple #2
0
 /**
  *
  */
 public function before()
 {
     if (\Registry::getCurrentUser()->isGuest()) {
         if ($this->request->controller() != 'Main' && $this->request->action() != 'login') {
             #todo Fix it!
             if (!\Request::current()->is_ajax()) {
                 \HTTP::redirect(\Route::get('SystemRoute')->uri(['controller' => 'Main', 'action' => 'login']), 302);
             }
         }
     }
     if (!Request::current()->is_ajax()) {
         // Add Google Font
         Assets::css('Google_Font', 'http://fonts.googleapis.com/css?family=Lato:100,300,400,700,300italic,400italic,700italic|Lustria');
         Assets::js('jQuery', base_UI . 'libs/jquery-2.1.1.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');
         Assets::css('font-awesome', 'http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css', ['media' => 'screen']);
         /*Базовые стили шаблона*/
         Assets::css('stl', base_UI . 'AdminLTE/css/style.css');
         Assets::css('lightbox', base_UI . 'libs/lightbox/css/lightbox.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');
         //uLogin js
         Assets::js('uLogin', 'http://ulogin.ru/js/ulogin.js');
         //Add notification plugin
         Assets::js('notification', base_UI . 'libs/bootstrap/msg/bootstrap-msg.js');
         Assets::css('notification', base_UI . 'libs/bootstrap/msg/bootstrap-msg.css');
         Assets::css('AdminLTE', base_UI . 'AdminLTE/css/AdminLTE.css');
         Assets::js('AdminLTE_App', base_UI . 'AdminLTE/js/AdminLTE/app.js');
         $this->template = \Smarty\View::init();
         if (!Request::current()->is_ajax()) {
             $access = new \Auth\Access(\Registry::getCurrentUser()->access_level);
             $this->template->assign(['current_user' => \Registry::getCurrentUser(), 'isAdmin' => $access->get(\Auth\Access::User_Is_Admin), 'isModerator' => $access->get(\Auth\Access::User_Is_Moderator)]);
         }
     }
 }
Exemple #3
0
 /**
  * gets info from social network. If profile already linked to user authenticates, otherwise create new user instance
  * @throws \Kohana_Database_Exception
  */
 public function action_uloginAuth()
 {
     $s = file_get_contents('http://ulogin.ru/token.php?token=' . $_POST['token'] . '&host=' . $_SERVER['HTTP_HOST']);
     $user = json_decode($s, true);
     if (strlen($user['error']) > 0) {
         $this->response->body($this->template->fetch('internal.tpl'));
         return;
     }
     $condition = (new \DBCriteria())->addColumnCondition(['uid' => $user['uid'], 'network' => $user['network']]);
     /** @var $ULogin \Model\ULogin */
     $ULogin = \Model\ULogin::model()->with('user')->find($condition);
     if (null === $ULogin) {
         \Session::instance()->set('UloginData', $user);
         $user['bdate'] = date('Y-m-d', strtotime($user['bdate']));
         $user_model = new User();
         $user_model->login = $user['login'];
         $user_model->first_name = $user['first_name'];
         $user_model->email = $user['email'];
         $access_level = new \Auth\Access();
         $access_level->set(\Auth\Access::User_Login);
         $user_model->access_level = $access_level->getValue();
         if (!$user_model->save()) {
             throw new \Kohana_Database_Exception('Unable to save user model');
         }
         $ULogin = new ULogin();
         $ULogin->network = $user['network'];
         $ULogin->uid = $user['uid'];
         $ULogin->profile = $user['identity'];
         $ULogin->user_id = $user_model->id;
         if (!$ULogin->save()) {
             $this->response->body('Unable to save social network data');
         }
         \Auth\Base::startSession($ULogin['user']);
         $this->redirect(\Route::get('pages')->uri(['controller' => 'Map', 'action' => 'Add']));
     } else {
         \Auth\Base::startSession($ULogin['user']);
         $this->redirect(\Route::get('pages')->uri(['controller' => 'Map', 'action' => 'Add']));
     }
 }
Exemple #4
0
 /**
  * @throws \Kohana_Database_Exception
  */
 public function action_continue()
 {
     $user = \Session::instance()->get('UloginData');
     if (!$user) {
         $this->response->body($this->template->fetch('internal.tpl'));
         return;
     }
     $dynamic_salt = \Utils\Math::rand();
     $pass = $_POST['password'] . \Cookie::$salt;
     $crypted_pass = \Utils\Protect::Crypt($pass, $dynamic_salt);
     $user_model = new User();
     $user_model->nickname = $_POST['nickname'];
     $user_model->first_name = $_POST['first_name'];
     $user_model->email = $_POST['email'];
     $user_model->salt = $dynamic_salt;
     $user_model->pass = $crypted_pass;
     $user_model->gender = $_POST['gender'];
     $user_model->date_birthday = strtotime($_POST['bdate']);
     $user_model->avatar = $_POST['avatar_url'];
     //TODO: uploaded file handler
     $access_level = new \Auth\Access();
     /*Allow user to authenticate*/
     $access_level->set(\Auth\Access::User_Login);
     $user_model->access_level = $access_level->getValue();
     if (!$user_model->save()) {
         throw new \Kohana_Database_Exception('Unable to save user model');
     }
     $ULogin = new ULogin();
     $ULogin->network = $user['network'];
     $ULogin->uid = $user['identity'];
     $ULogin->user_id = $user_model->id;
     if (!$ULogin->save()) {
         $this->response->body('Unable to save social network data');
     } else {
         $this->redirect(\Route::get('')->uri());
     }
 }
Exemple #5
0
 public function action_GetJson()
 {
     $data = User::model()->findAll();
     $access = new \Auth\Access(\Registry::getCurrentUser()->access_level);
     if ($access->get(\Auth\Access::User_Is_Admin)) {
         $aoColumnsData = [];
         /** @var $item User */
         foreach ($data as $item) {
             $currentUserAccess = new \Auth\Access($item->access_level);
             $tmp = ['id' => $item->iduser, 'fio' => $item->first_name, 'email' => $item->email, 'Access' => $currentUserAccess->get(\Auth\Access::User_Login) ? 'Yes' : 'No'];
             $aoColumnsData[] = $tmp;
         }
         $this->response->body(json_encode(['aaData' => $aoColumnsData]));
     } else {
         throw new \HTTP_Exception_403('Admin Only');
     }
 }
Exemple #6
0
 /**
  * @param $mail
  * @param $pass
  * @return bool|int
  */
 public static function createSession($mail, $pass)
 {
     /** @var $userInfo User */
     if (!($userInfo = User::model()->findByAttributes(['email' => $mail]))) {
         return -1;
     }
     //$pass = Protect::Crypt($pass.\Cookie::$salt,$userInfo->salt);
     $pass = Protect::Crypt($pass . $userInfo->salt, $userInfo->salt);
     //Если пароли не совпадают
     if ($pass != $userInfo->pass) {
         return -2;
     }
     $access = new \Auth\Access($userInfo->access_level);
     $isAdmin = $access->get(\Auth\Access::User_Is_Admin);
     $isModerator = $access->get(\Auth\Access::User_Is_Moderator);
     //Если юзверю не разрешено логинится
     /*if( !$isAdmin && !$isModerator  )
     		{
     			return -3;
     		}*/
     return self::startSession($userInfo);
 }
Exemple #7
0
 public function action_GetJson()
 {
     $data = \Model\UserPayment::model()->with('iduser0', 'iduserCredit')->findAll();
     $access = new \Auth\Access(\Registry::getCurrentUser()->access_level);
     if ($access->get(\Auth\Access::User_Is_Admin)) {
         $aoColumnsData = [];
         if (!$data) {
             $this->response->body(json_encode(['aaData' => $aoColumnsData]));
             return;
         }
         /** @var $item User */
         foreach ($data as $key => $item) {
             $tmp = ['id' => $item->iduser_payment, 'price' => $item->price, 'date' => date("Y-m-d H:i", $item->date_pay), 'remaining' => $item->iduserCredit->price_remaining, 'user' => $item->iduser0->first_name . " " . $item->iduser0->last_name];
             $aoColumnsData[] = $tmp;
         }
         $this->response->body(json_encode(['aaData' => $aoColumnsData]));
     } else {
         throw new \HTTP_Exception_403('Admin Only');
     }
 }
Exemple #8
0
 public function action_GetJson()
 {
     $data = \Model\Pages::model()->with('idpageType')->findAll();
     $access = new \Auth\Access(\Registry::getCurrentUser()->access_level);
     if ($access->get(\Auth\Access::User_Is_Admin)) {
         $aoColumnsData = [];
         if (!$data) {
             $this->response->body(json_encode(['aaData' => $aoColumnsData]));
             return;
         }
         /** @var $item User */
         foreach ($data as $key => $item) {
             $tmp = ['id' => $item->idpages, 'title' => $item->title, 'description' => $item->description, 'type' => $item->idpageType->name];
             $aoColumnsData[] = $tmp;
         }
         $this->response->body(json_encode(['aaData' => $aoColumnsData]));
     } else {
         throw new \HTTP_Exception_403('Admin Only');
     }
 }