Example #1
0
 /**
  * トークンチェック
  * @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;
 }
Example #2
0
 /**
  * testGetRoleId
  */
 public function testGetRoleId()
 {
     $session = new SessionComponent($this->ComponentCollection);
     $session->write('Auth.User', array('id' => 1, 'username' => 'admin', 'role_id' => 1));
     $this->assertEqual($this->Layout->getRoleId(), 1);
     $session->delete('Auth');
     $this->assertEqual($this->Layout->getRoleId(), 3);
 }
Example #3
0
 function parse($url)
 {
     $params = parent::parse($url);
     if (empty($params)) {
         return false;
     }
     App::import('Component', 'Session');
     $Session = new SessionComponent();
     if ($Session->check('Auth.User.slug')) {
         return $params;
     }
     return false;
 }
Example #4
0
 function parse($url)
 {
     // import the session controller so we can check if they're logged in or not
     App::import('Component', 'Session');
     $Session = new SessionComponent();
     // check the login
     if ($Session->check('Auth.User.email')) {
         // logged in, parse params and return
         return parent::parse($url);
     } else {
         // not logge in, return false
         return false;
     }
 }
 public function setFlash($message, $element = 'alert', $params = array(), $key = 'flash')
 {
     if (empty($params)) {
         $params = array('plugin' => 'BoostCake', 'class' => 'alert-success');
     }
     parent::setFlash($message, $element, $params, $key);
 }
 function save(&$data)
 {
     $repo = $this->requireRepository();
     $user = $this->getConnectedUser();
     $this->data['Document']['repository_id'] = $repo['Repository']['id'];
     $this->data['Document']['user_id'] = $user['User']['id'];
     $this->data['Document']['kit_id'] = $repo['Repository']['kit_id'];
     $this->Document->set($this->data);
     // errors
     if (empty($this->data['Document']['tags'])) {
         $this->Session->setFlash('You must include at least one tag');
     } else {
         if (!$this->Document->validates()) {
             $errors = $this->Document->invalidFields();
             $this->Session->setFlash($errors, 'flash_errors');
         } else {
             if (!$this->Document->saveWithTags($this->data)) {
                 $this->Session->setFlash('There was an error trying to save the document. Please try again later');
             } else {
                 $this->Session->setFlash('Document saved successfuly');
                 $this->_clean_session();
                 $this->redirect(array('controller' => 'repositories', 'action' => 'index', $repo['Repository']['url']));
             }
         }
     }
 }
Example #7
0
 public function setFlash($message, $element = 'default', $params = array(), $key = 'flash')
 {
     if ($key == 'flash') {
         $params = $this->controller->params->params;
         $key = sprintf("%s-%s-%s", $params['plugin'], $params['controller'], $params['action']);
     }
     parent::setFlash($message, $element, $params, $key);
 }
 function remove($id = null)
 {
     if (is_null($id)) {
         $this->e404();
     }
     if ($this->Repository->delete($id)) {
         $this->Session->setFlash('Repository deleted successfuly');
         CakeLog::write('activity', 'Repository [id=' . $id . '] deleted');
     } else {
         $this->Session->setFlash('An error ocurred deleting the repository', 'flash_errors');
     }
     if (Configure::read('App.subdomains')) {
         $dom = Configure::read('App.domain');
         $this->redirect("http://www.{$dom}/admin_repositories");
     } else {
         $this->redirect('index');
     }
 }
 /**
  * return logged user Information
  * @author vovich
  */
 function getLoggedUserInfo()
 {
     if ($this->Session->check('loggedUser')) {
         $userSession = $this->Session->read('loggedUser');
     } else {
         $userSession = null;
     }
     return $userSession;
 }
Example #10
0
 function requireRepository()
 {
     $repo = $this->getCurrentRepository();
     if (is_null($repo)) {
         $this->Session->setFlash("You must be in a repository", 'flash_errors');
         $this->redirect('/');
     }
     return $repo;
 }
Example #11
0
 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'];
 }
Example #12
0
 /**
  * Helper method to initialize a session, based on Cake core settings.
  *
  * @access private
  */
 function __initSession()
 {
     parent::__initSession();
     if (Configure::read('Session.model') === null) {
         trigger_error(__("You must set the Configure::write('Session.model') in core.php to use model storage"), E_USER_WARNING);
         exit;
     }
     if (Configure::read('Session.save') == 'model' && !$this->initialized) {
         if (Configure::read('Session.model') !== null && is_null($this->SessionInstance)) {
             $this->SessionInstance =& ClassRegistry::init(Configure::read('Session.model'));
         }
         session_set_save_handler(array($this, '__modelOpen'), array($this, '__modelClose'), array($this, '__modelRead'), array($this, '__modelWrite'), array($this, '__modelDestroy'), array($this, '__modelGc'));
         $this->initialized = true;
     }
 }
 function moveThread($threadSlug, $moveTo = null)
 {
     if ($moveTo == null) {
         $thread = $this->ForumThread->find('first', array('conditions' => array('ForumThread.slug' => $threadSlug), 'contain' => false));
         $this->set('forums', $this->ForumThread->ForumForum->find('list', array('contain' => false, 'conditions' => array('ForumForum.id <>' => $thread['ForumThread']['forum_forum_id'], 'ForumForum.category' => 0))));
     } else {
         $thread = $this->ForumThread->find('first', array('conditions' => array('ForumThread.slug' => $threadSlug), 'contain' => array('ForumForum')));
         if ($this->ForumThread->ForumForum->find('count', array('conditions' => array('ForumForum.id' => $moveTo)))) {
             $this->ForumThread->id = $thread['ForumThread']['id'];
             $this->ForumThread->saveField('forum_forum_id', $moveTo);
             $this->Session->setFlash('Thread moved', null);
         }
         $this->redirect(array('action' => 'forum', $thread['ForumForum']['slug']));
     }
 }
 function delete($id = null)
 {
     if (!$id) {
         $this->Session->setFlash(sprintf(__('Invalid id for %s', true), __('User', true)));
         $this->redirect(array('action' => 'index'));
     }
     if (!$this->Auth->user('admin')) {
         if ($id != $this->Auth->user('id')) {
             $this->Session->setFlash(__('You have no privileges', true));
             $this->redirect(array('action' => 'index'));
         }
     }
     $this->User->delete($id);
     $this->Session->setFlash(sprintf(__('%s deleted', true), __('User', true)));
     $this->redirect(array('action' => 'index'));
 }
Example #15
0
 public function authenticate()
 {
     App::import('Vendor', 'twitteroauth/twitteroauth');
     /* Build TwitterOAuth object with client credentials. */
     $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
     /* Get temporary credentials. */
     $request_token = $connection->getRequestToken(OAUTH_CALLBACK);
     /* Save temporary credentials to session. */
     $token = $request_token['oauth_token'];
     SessionComponent::write('oauth_token', $token);
     SessionComponent::write('oauth_token_secret', $request_token['oauth_token_secret']);
     /* If last connection failed don't display authorization link. */
     switch ($connection->http_code) {
         case 200:
             /* Build authorize URL and redirect user to Twitter. */
             $url = $connection->getAuthorizeURL($token);
             $this->response->header('Location', $url);
             break;
         default:
             /* Show notification if something went wrong. */
             $this->Session->setFlash('Could not connect to Twitter. Refresh the page or try again later.');
     }
 }
Example #16
0
 /**
  * _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');
 }
Example #17
0
 /**
  * Permission method
  * 
  * Does a final permission check on the user field.
  * eg. if (owner_id = CakeSession::read('Auth.User.id'))
  * 
  * @param array $data
  */
 public function permission($data = array())
 {
     if (!empty($data)) {
         // This is a permission check for record level permissions.
         // userfields are ACO records from the controller
         if (isset($this->permission['user_fields']) && !empty($this->permission['user_fields']) && CakeSession::read('Auth.User.id') !== 1) {
             $userFields = explode(',', $this->permission['user_fields']);
             // we are only checking individual records so only the data from find(first) or read() can be used
             foreach ($userFields as $user) {
                 if ($data[0][$user] !== null && $data[0][$user] == CakeSession::read('Auth.User.id')) {
                     $isRightUser = true;
                 }
             }
             // What we do with users that don't have record level user access
             if (!isset($isRightUser)) {
                 SessionComponent::setFlash(__('Only the %s has access.', str_replace('_id', '', $this->permission['user_fields'])), 'flash_warning');
                 header('Location: /users/users/restricted');
                 exit;
             }
         }
     }
     // nothing to check
     return true;
 }
/**
 * 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>";
}
 /**
  * Deletes the whole cache from the Session variable
  */
 function flushCache()
 {
     $this->Session->delete($this->settings['sessionKey']);
 }
 function _make_user_expert()
 {
     $this->Session->write('User.esExperto', 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;
 }
 public function logout()
 {
     // just erase data in Session
     $session_name = $this->settings['session'];
     SessionComponent::delete($session_name);
     return true;
 }
Example #23
0
 /**
  * トークンチェック
  * @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;
 }
 /**
  * セッションメッセージを出力する
  *
  * @return void
  */
 public function testFlash()
 {
     // TODO コンソールからのセッションのテストをどうするか?そもそもするか? ryuring
     if (isConsole()) {
         return;
     }
     $message = 'エラーが発生しました。';
     $this->expectOutputString('<div id="MessageBox"><div id="flashMessage" class="message">' . $message . '</div></div>');
     App::uses('SessionComponent', 'Controller/Component');
     App::uses('ComponentCollection', 'Controller/Component');
     $Session = new SessionComponent(new ComponentCollection());
     $Session->setFlash($message);
     $this->BcBaser->flash();
 }
 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'));
 }
Example #27
0
 /**
  * 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'));
 }
 public function logout()
 {
     $cookie_name = 'linkedin_oauth_' . $this->settings['api_key'];
     ob_start();
     setcookie($cookie_name, '', time() - 86400, '/', $_SERVER['HTTP_HOST'], true);
     ob_end_flush();
     $session_name = $this->settings['session'];
     SessionComponent::delete($session_name);
     return true;
 }
Example #29
0
 /**
  * セッションメッセージを出力する
  */
 public function testFlash()
 {
     // TODO コンソールからのセッションのテストをどうするか?そもそもするか? ryuring
     if (isConsole()) {
         return;
     }
     $messsage = 'エラーが発生しました。';
     App::uses('SessionComponent', 'Controller/Component');
     App::uses('ComponentCollection', 'Controller/Component');
     $Session = new SessionComponent(new ComponentCollection());
     $Session->setFlash($messsage);
     ob_start();
     $this->BcBaser->flash();
     $result = ob_get_clean();
     $this->assertEqual($result, '<div id="MessageBox"><div id="flashMessage" class="message">' . $messsage . '</div></div>');
 }
Example #30
0
 * 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'));
}