/** * @param $url_id * @return Url | null */ public function loadUrl($url_id) { $user_id = $this->userSession->getUserId(); $dataObject = $this->urlQuery->getUrlByIdAndUserId($url_id, $user_id); if ($dataObject == null) { return null; } return $this->urlDataObjectMapper->mapFromDataObject($dataObject); }
/** * */ 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); } } }
private function sessionHandle() { if (empty($this->session)) { $requestArgs = array_merge($_GET, $_POST, $_COOKIE); $sessionId = empty($requestArgs['session_id']) ? '' : $requestArgs['session_id']; $this->session = \model\UserSession::get($sessionId); } //$this->session = array(); }
public function testExecute() { $action = new Action\TaskAssignCurrentUser($this->container, 1, Task::EVENT_MOVE_COLUMN); $action->setParam('column_id', 2); $_SESSION = array('user' => array('id' => 5)); // We create a task in the first column $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); $us = new UserSession($this->container); $this->assertEquals(5, $us->getId()); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); // We create an event to move the task to the 2nd column $event = array('project_id' => 1, 'task_id' => 1, 'column_id' => 2); // Our event should be executed $this->assertTrue($action->execute(new GenericEvent($event))); // Our task should be assigned to the user 5 (from the session) $task = $tf->getById(1); $this->assertNotEmpty($task); $this->assertEquals(1, $task['id']); $this->assertEquals(5, $task['owner_id']); }
public function __construct() { if (isset($_SESSION['user'])) { self::$storage = json_decode($_SESSION['user']); } else { if (isset($_COOKIE['sesskey'])) { $sess = \Model\UserSession::find_by_sesskey($_COOKIE['sesskey']); if ($sess) { $user = \Model\User::find_by_id($sess->userid); self::set($user->to_json()); } } } }
public function testLastSeenProject() { $us = new UserSession($this->container); $this->assertEquals(0, $us->getLastSeenProjectId()); $us->storeLastSeenProjectId(33); $this->assertEquals(33, $us->getLastSeenProjectId()); $us->storeLastSeenProjectId(66); $this->assertEquals(66, $us->getLastSeenProjectId()); }
/** * @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; } }
public function testIsAdmin() { $s = new Session(); $us = new UserSession($this->container); $this->assertFalse($us->isAdmin()); $s['user'] = array(); $this->assertFalse($us->isAdmin()); $s['user'] = array('is_admin' => '1'); $this->assertFalse($us->isAdmin()); $s['user'] = array('is_admin' => false); $this->assertFalse($us->isAdmin()); $s['user'] = array('is_admin' => '2'); $this->assertFalse($us->isAdmin()); $s['user'] = array('is_admin' => true); $this->assertTrue($us->isAdmin()); }
public function testPrepareCreation() { $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $tp = new TaskPermission($this->container); $p = new Project($this->container); $u = new User($this->container); $us = new UserSession($this->container); $this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456'))); $this->assertNotFalse($u->create(array('username' => 'toto2', 'password' => '123456'))); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'creator_id' => 1))); $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'creator_id' => 2))); $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'creator_id' => 3))); $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1))); // User #1 can remove everything $user = $u->getbyId(1); $this->assertNotEmpty($user); $us->refresh($user); $task = $tf->getbyId(1); $this->assertNotEmpty($task); $this->assertTrue($tp->canRemoveTask($task)); // User #2 can't remove the task #1 $user = $u->getbyId(2); $this->assertNotEmpty($user); $us->refresh($user); $task = $tf->getbyId(1); $this->assertNotEmpty($task); $this->assertFalse($tp->canRemoveTask($task)); // User #1 can remove everything $user = $u->getbyId(1); $this->assertNotEmpty($user); $us->refresh($user); $task = $tf->getbyId(2); $this->assertNotEmpty($task); $this->assertTrue($tp->canRemoveTask($task)); // User #2 can remove his own task $user = $u->getbyId(2); $this->assertNotEmpty($user); $us->refresh($user); $task = $tf->getbyId(2); $this->assertNotEmpty($task); $this->assertTrue($tp->canRemoveTask($task)); // User #1 can remove everything $user = $u->getbyId(1); $this->assertNotEmpty($user); $us->refresh($user); $task = $tf->getbyId(3); $this->assertNotEmpty($task); $this->assertTrue($tp->canRemoveTask($task)); // User #2 can't remove the task #3 $user = $u->getbyId(2); $this->assertNotEmpty($user); $us->refresh($user); $task = $tf->getbyId(3); $this->assertNotEmpty($task); $this->assertFalse($tp->canRemoveTask($task)); // User #1 can remove everything $user = $u->getbyId(1); $this->assertNotEmpty($user); $us->refresh($user); $task = $tf->getbyId(4); $this->assertNotEmpty($task); $this->assertTrue($tp->canRemoveTask($task)); // User #2 can't remove the task #4 $user = $u->getbyId(2); $this->assertNotEmpty($user); $us->refresh($user); $task = $tf->getbyId(4); $this->assertNotEmpty($task); $this->assertFalse($tp->canRemoveTask($task)); }