function watch($id = null) { if (is_null($id)) { $this->Session->setFlash('Repository not found'); $this->redirect('/'); } if (!$this->isLoggedIn()) { $this->redirect(array('controller' => 'login', 'action' => 'index')); } $user = $this->getConnectedUser(); $repo = $this->RepositoriesUser->find('first', array('conditions' => array('user_id' => $user['User']['id'], 'repository_id' => $id), 'recursive' => -1)); if (empty($repo)) { $this->Session->setFlash('Repository not found'); $this->redirect('/'); } $watching = $repo['RepositoriesUser']['watching']; $this->RepositoriesUser->read(null, $repo['RepositoriesUser']['id']); $this->RepositoriesUser->set('watching', !$watching); $this->RepositoriesUser->save(); if ($watching) { $msg = "Repository removed from watchlist"; } else { $msg = "Repository added to watchlist"; } $this->Session->setFlash($msg); $this->redirect(array('action' => 'set_repository_by_id', $id)); }
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'])); } } } }
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'); } }
function requireRepository() { $repo = $this->getCurrentRepository(); if (is_null($repo)) { $this->Session->setFlash("You must be in a repository", 'flash_errors'); $this->redirect('/'); } return $repo; }
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')); }
/** * exceptional case when there aren't enough * criterias or documents to play a challenge * * had to rewrite dispatch logic here :( * */ function _skip_challenge() { $this->Session->delete('Challenge.play'); $this->Session->write('Document.continue', true); $action = $this->Session->read('Action.type'); $earn = strcmp($action, 'earn') == 0; $download = strcmp($action, 'download') == 0; $upload = strcmp($action, 'upload') == 0; if ($earn) { $this->Session->setFlash('Sorry, there aren\'t enough documents or criterias to play a challenge'); $this->redirect('/'); } elseif ($download || $upload) { $this->redirect(array('controller' => 'documents', 'action' => $this->Session->read('Action.type'))); } else { $this->redirect('/'); } }
/** * セッションメッセージを出力する */ 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>'); }
/** * testSessionFlash method * * @return void */ public function testSessionFlash() { $Session = new SessionComponent($this->ComponentCollection); $this->assertNull($Session->read('Message.flash')); $Session->setFlash('This is a test message'); $this->assertEquals(array('message' => 'This is a test message', 'element' => 'default', 'params' => array()), $Session->read('Message.flash')); $Session->setFlash('This is a test message', 'test', array('name' => 'Joel Moss')); $this->assertEquals(array('message' => 'This is a test message', 'element' => 'test', 'params' => array('name' => 'Joel Moss')), $Session->read('Message.flash')); $Session->setFlash('This is a test message', 'default', array(), 'myFlash'); $this->assertEquals(array('message' => 'This is a test message', 'element' => 'default', 'params' => array()), $Session->read('Message.myFlash')); $Session->setFlash('This is a test message', 'non_existing_layout'); $this->assertEquals(array('message' => 'This is a test message', 'element' => 'default', 'params' => array()), $Session->read('Message.myFlash')); $Session->delete('Message'); }
/** * 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; }
/** * 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; }
/** * セッションメッセージを出力する * * @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(); }
/** * * in case something goes wrong */ function _cancel_everything($reason) { $this->Session->setFlash("Sorry, an unexpected error has occurred [Message: {$reason}]", 'flash_errors'); $this->_clean_session(); $this->redirect('/'); }