/** * Pass-thru function for ACL check instance. Check methods * are used to check whether or not an ARO can access an ACO * * @param string $aro ARO The requesting object identifier. * @param string $aco ACO The controlled object identifier. * @param string $action Action (defaults to *) * @return boolean Success * @access public */ function check($aro, $aco, $action = "*") { $path = $this->__cachePath($aro, $aco, $action); if ($this->Session->check($path)) { return $this->Session->read($path); } else { $check = parent::check($aro, $aco, $action); $this->Session->write($path, $check); return $check; } }
/** * * @deprecated */ public function get($criterio = null) { if (!$this->Session->check('Desafio.docs') and is_null($criterio)) { $this->Session->setFlash('Ganaste la posibilidad de descargar documentos, haz una búsqueda para poder acceder a ellos!'); $this->redirect(array('controller' => 'tags')); } else { if (!is_null($criterio)) { $docs = $this->Tag->findDocumentsByTags(array($criterio)); } else { $docs = $this->Session->read('Desafio.docs'); } } $this->Session->delete('Desafio'); $criterio = $this->Criterio->find('first', array('recursive' => -1)); $pack = $criterio['Criterio']['tamano_pack']; $doc_objs = $this->Documento->find('all', array('conditions' => array('Documento.id_documento' => $docs), 'recursive' => -1)); $premio = array(); if (count($doc_objs) > 0) { if (count($doc_objs) < $pack) { $pack = count($doc_objs); } /* shuffle documents */ shuffle($doc_objs); $tmp = array_rand($doc_objs, $pack); $tmp = is_array($tmp) ? $tmp : array($tmp); /* insersect by keys from documents and some random subset of size $pack of $doc_objs */ /* $premio are $pack random documents from search result */ $premio = array_intersect_key($doc_objs, array_flip($tmp)); } $this->set(compact('premio', 'doc_objs')); }
/** * Retrive Twitter auth data in Cookie set by Twitter JSSDK. * * @param CakeRequest $request Request object. * @return mixed Either false or an object of user information of Twitter */ public function getUser(CakeRequest $request) { $api = Configure::read('SocialSignIn.API.Twitter'); // $request_token_url = 'http://api.twitter.com/oauth/request_token'; // $access_token_url = "http://twitter.com/oauth/access_token"; // $authorize_url="http://twitter.com/oauth/authorize"; $session_name = $this->settings['session']; $s = SessionComponent::read($session_name); // if already authenticated, user object is stored in the session if (isset($s['User']) && is_object($s['User'])) { return $s['User']; } if (isset($request->query['oauth_token']) && isset($s['secret'])) { $oauth = new OAuth($this->settings['consumer_key'], $this->settings['consumer_secret'], OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI); $oauth->setToken($request->query['oauth_token'], $s['secret']); $access_token_info = $oauth->getAccessToken($api['access_token_url']); if ($access_token_info['oauth_token']) { $oauth->setToken($access_token_info['oauth_token'], $access_token_info['oauth_token_secret']); $data = $oauth->fetch($api['fetch_url']); $user = json_decode($oauth->getLastResponse()); return $user; } } return false; }
/** * dispatch to user action: * - upload * - download * - index (for earn points) * requires Session var "Points.dispatch" given by PointsController::process() * @see PointsController::process() */ function _dispatch() { $action = $this->_get_action(); $action_name = $this->Session->read('Action.type'); if (!$this->Session->check('Points.dispatch')) { $this->_cancel_everything('This is not meant to happen'); } if ($this->Session->check('Points.proceed') && !$this->Session->read('Points.proceed')) { $this->_cancel_everything($this->Session->read('Points.status')); } if ($this->getConnectedUser() == $this->anonymous) { $this->Session->setFlash("Thank you, now you can {$action_name} document(s)"); } else { $this->Session->setFlash($this->Session->read('Points.status')); } if ($action == $this->earn) { $this->redirect('/'); } if ($action == $this->upload || $action == $this->download) { $this->Session->write('Document.continue', true); $this->_clean_session(); $this->redirect(array('controller' => 'documents', 'action' => $action_name)); } else { $this->_cancel_everything('Action not recognized'); } }
/** * トークンチェック * @param CakeRequest $request * @param SessionComponent $session * @param string $dataAlias * @param string $tokenField * @return boolean */ public static function checkToken(CakeRequest $request, SessionComponent $session, $dataAlias, $tokenField = self::TOKEN_FIELD) { $sessionKey = self::SESSION_KEY_BASE . $dataAlias; $requestToken = $request->data[$dataAlias][$tokenField]; $sessionToken = $session->read($sessionKey); $session->delete($sessionKey); return $requestToken === $sessionToken ? true : false; }
/** * validates challenge and dispatch to PointsController::process() * if unsuccessful, increases user's amount of questions and show failure * requires Session var "Challenge.validate" given by play() * @see PointsController::process() * @see ChallengesController::_dispatch() */ function _validate_challenge($data) { $user = $this->getConnectedUser(); $criterio = $this->Session->read('Challenge.criterio'); $desafio_correcto = $this->CriteriasDocument->validateChallenge($data['Desafio']); $this->CriteriasDocument->saveStatistics($data['Desafio'], $desafio_correcto); $this->CriteriasUser->saveNextC($user['User']['id'], $criterio, $desafio_correcto); $this->_dispatch($desafio_correcto); }
/** * return logged user Information * @author vovich */ function getLoggedUserInfo() { if ($this->Session->check('loggedUser')) { $userSession = $this->Session->read('loggedUser'); } else { $userSession = null; } return $userSession; }
public function hasDailySpecialPostAvailable() { if (date("Y-m-d") === $this->session->read("shoppingcart_dailyspecial")) { return false; } $items = $this->pruneItems($this->session->read("shoppingcart")); foreach ($items as $item) { if (strpos($item['sku'], "US-3001-") === 0) { return false; } } $item = $this->getDailySpecialItem(); return $item['image']['name']; }
/** * セッションをリクエストパラメータに設定 * * @param CakeRequest $request * @param SessionComponent $session * @param type $sessionKey * @throws RuntimeException */ public static function setSessionToRequestData(CakeRequest $request, SessionComponent $session, $sessionKey = null) { $sessionKey = is_null($sessionKey) ? static::TMP_REQUEST_SESSION_KEY : $sessionKey; if (empty($sessionKey)) { throw new RuntimeException(); } $dataSession = $session->check($sessionKey) ? $session->read($sessionKey) : array(); $dataRequest = $request->data; $multipleFields = static::$multipleFields; for ($i = 0, $cnt = count($multipleFields); $i < $cnt; ++$i) { $tmp = $multipleFields[$i]; $arrTmp = explode('.', $tmp); $alias = $arrTmp[0]; $field = $arrTmp[1]; if (isset($dataSession[$alias][$field]) && isset($dataRequest[$alias][$field])) { unset($dataSession[$alias][$field]); } } $request->data = Hash::merge($dataSession, $dataRequest); }
/** * returns current repository data as array * note: if host is localhost, it just reads from the session var * which means to have an expiration time */ function getCurrentRepository() { $repo = null; if (Configure::read('App.subdomains')) { $url = explode('.', $_SERVER['HTTP_HOST'], 3); if (count($url) === 2 or $url[0] === 'www') { $repo = null; } else { $repo = $url[0]; } } elseif ($this->Session->check('Repository.current')) { $repo = $this->Session->read('Repository.current'); } if (!is_null($repo)) { $data = $this->Repository->find('first', array('conditions' => array('Repository.url' => $repo))); if (!is_null($data) && !empty($data)) { return $data; } } return null; }
/** * testSessionDestroy method * * @access public * @return void */ function testSessionDestroy() { $Session = new SessionComponent(); $Session->write('Test', 'some value'); $this->assertEqual($Session->read('Test'), 'some value'); $Session->destroy('Test'); $this->assertNull($Session->read('Test')); }
/** * Template code for including the twitter login button into the theme * * @param boolean $display_if_logged_in * @return html|string */ function twitter_login_button($display_if_logged_in = true) { //initializing variables App::import('Helper', 'Session'); $Session = new SessionComponent(); $auth = $Session->read('Auth'); //reasons to fail if (twitter('profile.id', null, false)) { return false; } if (!$display_if_logged_in && isset($auth['User']['id'])) { return false; } // The same as require('controllers/users_controller.php'); App::import('Helper', 'Html'); $html = new HtmlHelper(); $html->css('/twitterlogin/css/style.css', 'stylesheet', array('inline' => false)); echo "<a href='" . Router::url(array('admin' => false, 'plugin' => null, 'controller' => 'twitterlogin', 'action' => 'authorize'), true) . "'><div class='twitter-login-lighter'></div></a>"; }
/** * isStudent returns true if user is a student in at least once course * * @static * @access public * @return void */ static function isStudentOrTutor() { App::import('Component', 'Session'); $Session = new SessionComponent(); $permission = $Session->read('ipeerSession.IsStudentOrTutor'); if (!isset($permission)) { return false; } return $permission == true; }
/** * Function is responsible for clearning the users tokens * */ function clearUsersTokens() { // loading resources $Twitterlogin = new Twitterlogin(); $Twprofile = new Twprofile(); $Session = new SessionComponent(); $auth = $Session->read('Auth'); if (isset($auth['User']['id'])) { $profile = $Twprofile->find('first', array('conditions' => array('Twprofile.croogo_id' => $auth['User']['id']))); if ($profile) { $profile['Twprofile']['oauth_token'] = ''; $profile['Twprofile']['oauth_token_secret'] = ''; $Twprofile->save($profile); $this->authorized = false; } } // Show notification if something went wrong. $Session->setFlash(__('We had to clear your old tokens, please connect again.', true), 'default', array('class' => 'error')); $loginPage = Router::url(array('plugin' => null, 'controller' => 'users', 'action' => 'login'), true); header("Location: " . $loginPage); break; }
/** * loadRubricEvaluationDetail * Rubric Evaluation functions * * @param mixed $event * @param mixed $studentId * * @access public * @return void */ function loadRubricEvaluationDetail($event, $studentId = null) { $this->EvaluationRubric = new EvaluationRubric(); $this->GroupsMembers = new GroupsMembers(); $this->EvaluationRubricDetail = new EvaluationRubricDetail(); $this->Rubric = new Rubric(); $this->User = ClassRegistry::init('User'); $Session = new SessionComponent(); $user = $Session->read('Auth.User'); //User or Admin or $evaluator = empty($studentId) ? $user['id'] : $studentId; $result = array(); //Get Members for this evaluation $groupMembers = $this->User->getEventGroupMembersNoTutors($event['Group']['id'], $event['Event']['self_eval'], $evaluator); for ($i = 0; $i < count($groupMembers); $i++) { $targetEvaluatee = $groupMembers[$i]['User']['id']; $evaluation = $this->EvaluationRubric->getEvalRubricByGrpEventIdEvaluatorEvaluatee($event['GroupEvent']['id'], $evaluator, $targetEvaluatee); if (!empty($evaluation)) { $groupMembers[$i]['User']['Evaluation'] = $evaluation; $groupMembers[$i]['User']['Evaluation']['EvaluationDetail'] = $this->EvaluationRubricDetail->getAllByEvalRubricId($evaluation['EvaluationRubric']['id']); } } //$this->set('groupMembers', $groupMembers); $result['groupMembers'] = $groupMembers; //Get the target rubric $this->Rubric->id = $event['Event']['template_id']; //$this->set('rubric', $this->Rubric->read()); $result['rubric'] = $this->Rubric->read(); // enough points to distribute amongst number of members - 1 (evaluator does not evaluate him or herself) $numMembers = count($groupMembers); //$this->set('evaluateeCount', $numMembers); $result['evaluateeCount'] = $numMembers; return $result; }
/** * トークンチェック * @param CakeRequest $request * @param SessionComponent $session * @param string $dataAlias * @param string $tokenField * @return boolean */ public static function checkToken($requestToken, SessionComponent $session, $dataAlias = self::DEFAULT_KEY) { $sessionKey = self::SESSION_KEY_BASE . $dataAlias; $sessionToken = $session->read($sessionKey); return $requestToken === $sessionToken ? true : false; }
public function testConnection() { $this->cookies = SessionComponent::read('Capsule.cookies'); if (empty($this->idul)) { $this->idul = SessionComponent::read('User.idul'); } $request = $this->_fetchPage('/pls/etprod8/twbkwbis.P_GenMenu?name=bmenu.P_AdminMnu'); // Retry user login if request fails if (!$request || !isset($request['headers']) || !is_array($request['headers'])) { $this->login($this->idul, $this->password); } // Check if session ID cookie from header response is empty $isEmpty = false; for (reset($request['headers']), $header = 0; $header < count($request['headers']); next($request['headers']), $header++) { $header_name = key($request['headers']); if ($header_name == 'set-cookie') { if (is_array($request['headers'][$header_name])) { foreach ($request['headers'][$header_name] as $cookie) { if (preg_match("#SESSID\\=;#", $cookie)) { $isEmpty = true; break; } } } elseif (preg_match("#SESSID\\=;#", $request['headers'][$header_name])) { $isEmpty = true; } } } if ($isEmpty) { // Retry user login $this->login($this->idul, $this->password); } // Connection is OK return true; }
/** * _getAuthedUserId * Gets the id of the currently Authed user. * * @param mixed $model * * @access private * @return void */ private function _getAuthedUserId($model) { App::import('Component', 'Session'); $session = new SessionComponent(); return $session->read('Auth.' . $this->settings[$model->alias]['user_model'] . '.id'); }
public function getSession() { return $this->session->read(); }
/** * testSessionDestroy method * * @return void */ public function testSessionDestroy() { $Session = new SessionComponent($this->ComponentCollection); $Session->write('Test', 'some value'); $this->assertEquals('some value', $Session->read('Test')); $Session->destroy('Test'); $this->assertNull($Session->read('Test')); }
* Configure::write('Dispatcher.filters', array( * 'MyCacheFilter', // will use MyCacheFilter class from the Routing/Filter package in your app. * 'MyCacheFilter' => array('prefix' => 'my_cache_'), // will use MyCacheFilter class from the Routing/Filter package in your app with settings array. * 'MyPlugin.MyFilter', // will use MyFilter class from the Routing/Filter package in MyPlugin plugin. * array('callable' => $aFunction, 'on' => 'before', 'priority' => 9), // A valid PHP callback type to be called on beforeDispatch * array('callable' => $anotherMethod, 'on' => 'after'), // A valid PHP callback type to be called on afterDispatch * * )); */ Configure::write('Dispatcher.filters', array('AssetDispatcher', 'CacheDispatcher')); /** * Configures default file logging options */ App::uses('CakeLog', 'Log'); CakeLog::config('debug', array('engine' => 'File', 'types' => array('notice', 'info', 'debug'), 'file' => 'debug')); CakeLog::config('error', array('engine' => 'File', 'types' => array('warning', 'error', 'critical', 'alert', 'emergency'), 'file' => 'error')); //Default Routes // include the Session Component to our application App::uses('SessionComponent', 'Controller/Component'); // now create new SessionComponent instance $Session = new SessionComponent(new ComponentCollection()); // check if the user logged in if ($Session->read('Auth.User')) { if (isset($_SESSION['Auth']['User']["password"])) { Configure::write('Route.default', array('controller' => 'usuarios', 'action' => 'EditarSenha')); } else { Configure::write('Route.default', array('controller' => 'pages', 'action' => 'display')); } } else { Configure::write('Route.default', array('controller' => 'usuarios', 'action' => 'login')); }