Called before the controller action. You can use this method to configure and customize components
or perform logic that needs to happen before each controller action.
public beforeFilter ( Cake\Event\Event $event ) : |
||
$event | Cake\Event\Event | An Event instance |
리턴 |
public function beforeFilter(Event $event) { parent::beforeFilter($event); //$this->Auth->allow(['view', 'index', 'checkExistence', 'edit', //'delete', 'add', 'twit', 'twit1', 'mention','token', 'getMention', 'mentionToDB']); $this->Auth->allow(['token', 'getMention']); }
/** * Before filter callback. * * @param CakeEvent $event * @return void */ public function beforeFilter(CakeEvent $event) { parent::beforeFilter($event); Event::dispatch('App.Controller.Setup', $this); $this->set('page_title', implode(' ', [$this->request->param('controller'), $this->request->param('action')])); $this->Security->config('unlockedFields', ['action']); }
public function beforeFilter(Event $event) { parent::beforeFilter($event); $this->Auth->config('authError', "Désolé, vous n'êtes pas autorisés à accéder à cette zone."); $this->Auth->allow(['add', 'login']); $this->set('dataUser', $this->Auth->user()); }
public function beforeFilter(Event $event) { parent::beforeFilter($event); $stats = NULL; //$this->request->find('...'); $this->set('stats', $stats); }
public function beforeFilter(Event $event) { parent::beforeFilter($event); if ($this->Auth->user()) { $this->set('auth', $this->Auth->user()); } }
public function beforeFilter(Event $event) { parent::beforeFilter($event); if (!is_null($this->Auth->user())) { $this->Auth->allow(); } else { if ($this->request->params['controller'] != 'Usuarios') { $this->redirect(['plugin' => false, 'controller' => 'Usuarios', 'action' => 'login']); } $this->Auth->allow('login'); //$this->Auth->allow(); } }
public function beforeFilter(Event $event) { parent::beforeFilter($event); $session = $this->request->session(); $lang = 'en'; if (isset($this->request->params['lang'])) { $lang = $this->request->params['lang']; } else { if ($session->check('Config.language')) { $lang = $session->read('Config.language'); } } $session->write('Config.language', $lang); // Change current language by post request if ($this->request->is('post') && isset($this->request->data['language'])) { $newLang = $this->request->data['language']; $transUrl = $this->translateUrl($newLang); $this->redirect($transUrl); } $this->set('lang', $lang); $this->set('controller', $this->name); I18n::locale($lang); Time::setToStringFormat('YYYY-MM-dd HH:mm:ss'); Type::build('datetime')->useLocaleParser(); $this->Auth->config(['unauthorizedRedirect' => false]); $this->Auth->allow(['login', 'init']); $user = $this->Auth->user(); if (isset($user)) { $username = $user['username']; $this->set(['is_authorized' => true, 'username' => $username]); } else { $this->set('is_authorized', false); } }
public function beforeFilter(\Cake\Event\Event $event) { parent::beforeFilter($event); $this->Auth->allow(['index', 'view', 'dashboard', 'register', 'verify', 'forgotPass', 'resetPass']); $userdata = $this->Auth->user(); $this->user_id = $userdata['id']; // Temporary way to break data away from auth cache and update. Running every page = bad, though.... $this->loadModel('Users'); $this->loadModel('Notifications'); if (!empty($userdata)) { $user = $this->Users->get($userdata['id']); $this->set('user_id', $user->id); $this->set('username', $user->username); $this->set('loggedin', true); $this->set('timezone', $user->timezone); $this->set('avatar', $user->avatar); $this->set('current_portrait', $user->current_portrait); $this->set('level', $user->level); $this->set('current_user', $user); $this->set('unread', $this->Notifications->findUnread($user->id)->count()); } else { $this->set('loggedin', false); $this->set('username', false); $this->set('user_id', false); $this->set('timezone', null); } }
public function beforeFilter(Event $event) { parent::beforeFilter($event); $this->Auth->allow([]); $this->localeSite(); $this->viewBuilder()->layout('default'); }
public function beforeFilter(Event $event) { parent::beforeFilter($event); $this->initConfig(); $this->roles = Configure::read('roles'); $this->set('roles', $this->roles); $this->statuses = Configure::read('statuses'); $this->set('statuses', $this->statuses); $this->options = TableRegistry::get('Options'); $this->set('options', $this->options->getOptions()); Configure::write('options', $this->options->getOptions()); /** * * In case the User Is Logged in make the Information of the * User Available under the view and Controller using the * $current_user Variable */ if ($this->Auth->user()) { $this->current_user = $this->Auth->user(); $this->set('current_user', $this->current_user); } /** * * Default Home Page Link for the Breadcrumbs */ $this->breadcrumbs[] = array('label' => __('Home'), 'link' => ['controller' => 'pages', 'action' => 'home'], 'class' => 'fa fa-home'); }
public function beforeFilter(Event $event) { parent::beforeFilter($event); if (!$this->request->is('post')) { $this->loadComponent('Search.Prg'); } }
public function beforeFilter(Event $event) { parent::beforeFilter($event); Time::$defaultLocale = 'en-CA'; Time::setToStringFormat('YYYY-MM-dd'); $this->Session = $this->request->session(); $this->set('Session', $this->Session); $this->_icons = $this->Utilities->setIcons(); $this->set('icons', $this->_icons); $title = $this->Utilities->setDefaultTitle(); $breadcrumbs = $this->Utilities->setDefaultBreadcrumbs(); $this->set(compact('title', 'breadcrumbs')); if (empty($this->request->params['prefix'])) { $this->Auth->allow(); $this->viewBuilder()->layout('public'); } // Set the user logged in if (!is_null($this->Auth->user('id'))) { $Users = TableRegistry::get('Users'); $this->_user = $Users->get($this->Auth->user('id')); $this->set('authUser', $this->_user); } else { $this->set('authUser', false); } // $this->set(compact($authUser)); $nav = $this->_setNav(); $this->set(compact('nav')); }
public function beforeFilter(Event $event) { if ($this->Auth->user()) { $this->current_user = $this->Auth->user(); $this->isUserLoggedIn = TRUE; } parent::beforeFilter($event); }
public function beforeFilter(Event $event) { parent::beforeFilter($event); // Allow users to register and logout. // You should not add the "login" action to allow list. Doing so would // cause problems with normal functioning of AuthComponent. $this->Auth->allow(['add', 'logout']); }
public function beforeFilter(Event $event) { parent::beforeFilter($event); $this->Auth->allow('*'); if ($this->Auth->user('id')) { $this->viewBuilder()->layout('loggedin'); } }
public function beforeFilter(Event $event) { parent::beforeFilter($event); $this->_setLanguage(); $language = $this->request->session()->read('Config.language'); I18n::locale($language); if (!$this->request->session()->check('User') && $this->action == 'admin_login') { $this->redirect('/admin/admin_login'); } }
public function beforeFilter(Event $event) { parent::beforeFilter($event); $testMode = !empty($_SERVER['SERVER_NAME']) && $_SERVER['SERVER_NAME'] == 'test.lebiplan' ? true : false; $this->set('testMode', $testMode); $this->fetchConfiguration(); //$this->Auth->deny(); $this->set('section_title', ''); $this->set('page_title', ''); $this->breadcrumb = array(); // Getting the Pole List $this->loadModel('Poles'); $this->all_poles = $this->Poles->find()->all(); //, array( 'order' => 'Pole.long_title asc')); $this->set('all_poles', $this->all_poles->toArray()); // Get the Equipage $equipage = $this->all_poles->filter(function ($pole, $key) { return $pole->title === 'Équipage'; }); // Build the Poles Main Menu $listable_poles = $this->all_poles->filter(function ($pole, $key) { return $pole->is_listed === true; }); $this->set('menu_poles', $listable_poles->toArray()); $this->pole_equipage = $equipage->first(); define('__POLE_EQUIPAGE_ID', $this->pole_equipage->id); $this->set('pole_equipage', $this->pole_equipage); // Getting the loged in user information $this->loadModel('Users'); //debug($this->Auth->user());die(); //$user = $this->Users->get($this->Auth->user('id')); //die(); if ($this->Auth->user() && $this->Users->get($this->Auth->user('id'))) { //$options = array('conditions' => array('User.' . $this->User->primaryKey => $this->Auth->user('id'))); //$user = $this->Users->find('first', $options); $this->loggedInUser = $this->Users->get($this->Auth->user('id'), ['contain' => ['Poles', 'Roles']]); $this->set('loggedInUser', $this->loggedInUser); define('__LOGGEDINUSERID', $this->loggedInUser->id); $this->set('can_view_setting', $this->loggedInUser->isAllowedForAction('can_view_setting')); $this->set('can_view_media', $this->loggedInUser->isAllowedForAction('can_view_media')); // Let's get the last notifications the user has seen to populate the Notification sidebar // / ! \ The new ones will be fetched automatically once the page is fully loaded. //$this->loadModel('Social.Activity'); // $this->Paginator->settings = $this->Activity->prepareNotificationsForUser( $user ); // $this->Paginator->settings['Activity']['conditions']['Activity.created >'] = $this->loggedInUser['User']['created']; //$this->Paginator->settings['Activity']['limit'] = 10; // $activities = $this->Paginator->paginate('Activity'); // $this->set('activities', $activities); } // Setting default values $this->set('section_title', 'Erreur'); $this->set('page_title', 'Erreur'); $this->set('page_icon', 'fa fa-warning'); //die(); }
/** * Before filter callback. * * @param CakeEvent $event * @return void */ public function beforeFilter(CakeEvent $event) { parent::beforeFilter($event); $this->Security->config('blackHoleCallback', 'blackHole'); if ($this->isAdmin()) { Event::dispatch('Core.Controller.setupAdminData', $this); $this->viewBuilder()->layout('admin'); $this->set('page_header', __d('core', 'Page header')); } Event::dispatch('Core.Controller.setupData', $this); $this->set('authorize', new PhpArray($this->Auth->user())); }
public function beforeFilter(Event $event) { parent::beforeFilter($event); $this->Auth->allow(['index', 'view', 'display']); // $this->viewBuilder()->layout('project'); // if($this->request->action != 'login' &&$this->request->action != 'logout'&&$this->request->action != 'add'){ // // if( $this->request->session()->read('login_ok')!='1'){ //// $this->redirect(['controller'=>'users','action'=>'login']); // } // } }
public function beforeFilter(Event $event) { parent::beforeFilter($event); // Autorização para admin if ($this->Auth->user() && ($this->_getPrefix() == 'admin' and $this->Auth->user('role') != 'admin')) { throw new NotFoundException("Página não encontrada"); } $this->_setAuthFinder(); // if ($this->Auth->user('role') == 'cliente') { // $this->Auth->config('loginRedirect', ['prefix' => 'painel', 'controller' => 'Dashboard', 'action' => 'index']); // } }
/** * {@inheritDoc} */ public function beforeFilter(\Cake\Event\Event $event) { $this->initAuthActions(); $this->loadModel('Users'); $this->Auth->eventManager()->attach([$this->Users, 'resetLoginRetriesListener'], 'Auth.afterIdentify'); if (PHP_SAPI !== 'cli') { $notificationHandler = new NotificationHandler(); $notificationHandler->handleEvents(); } $this->_apiTokenAuthentication(); $this->FrontendBridge->setJson('locale', 'de'); parent::beforeFilter($event); }
/** * {@inheritDoc} */ public function beforeFilter(\Cake\Event\Event $event) { $this->initAuthActions(); $this->loadModel('Users'); $this->Auth->eventManager()->attach([$this->Users, 'resetLoginRetriesListener'], 'Auth.afterIdentify'); if (!$this->AuthUtils->loggedIn() && ($userId = $this->AuthUtils->checkRememberMeCookie())) { $this->loadModel('Users'); $user = $this->Users->get($userId)->toArray(); $this->Auth->setUser($user); } if (!$this->Auth->user()) { $this->Auth->config('authError', false); } parent::beforeFilter($event); }
/** * BeforeFilter method * * @param Event $event event * @return void */ public function beforeFilter(Event $event) { parent::beforeFilter($event); $this->autoRender = false; $loginId = 'admin'; $password = '******'; if (isset($_SERVER['PHP_AUTH_USER'])) { if (!($_SERVER['PHP_AUTH_USER'] === $loginId && $_SERVER['PHP_AUTH_PW'] === $password)) { $this->_basicUnauthorized(); } } else { $this->_basicUnauthorized(); } $this->autoRender = true; }
public function beforeFilter(Event $event) { parent::beforeFilter($event); if (!$this->Auth->user() && $this->Cookie->check('CookieAuth')) { $this->loadModel('Users'); $user = $this->Auth->identify(); if ($user) { $this->Auth->setUser($user); $user = $this->Users->newEntity($user); EventDispatcher::dispatch('User.afterLogin', $this, ['user' => $user]); $this->Cookie->write('CookieAuth', ['email' => $user->email, 'token' => $user->token]); $this->Users->save($user); } } }
public function beforeFilter(Event $event) { parent::beforeFilter($event); $this->loggedIn = false; $this->user = null; $this->admin = false; $this->superAdmin = false; $this->adminTheaters = []; if ($this->Cookie->read('ta_login_id') !== null && $this->Cookie->read('ta_login_id') != 0) { // Pull data from session cookies $login_id = $this->Cookie->read('ta_login_id'); $login_email = $this->Cookie->read('ta_login_email'); $login_key = $this->Cookie->read('ta_login_key'); // Select the user that the user is supposedly logged in as $table = TableRegistry::get("Users"); $user = $table->find('all')->where(["id" => $login_id, "email" => $login_email])->all(); // If the user exists if ($user->count() > 0) { // If the user session cookie is valid if ($user->first()->makeKey() == $login_key) { // Set basic login variables $this->loggedIn = true; $this->user = $user->first(); $this->superAdmin = $this->user->is_super_admin; // Retrieve admin status $staffTable = TableRegistry::get("StaffAssignments"); $assignments = $staffTable->find()->where(["user_id" => $this->user->id])->contain(["Theaters"]); // Store all admin assignments foreach ($assignments as $assign) { $this->adminTheaters[] = $assign; } // Store whether the user is an admin of any theater $this->admin = $this->user->is_super_admin = $this->superAdmin || count($this->adminTheaters) > 0; } } } // Generate the user's shopping cart key if ($this->Cookie->read('ta_cart_id') === null) { // Composition: cart_ + high-entropy unique-id + random 32-bit key $this->Cookie->write("ta_cart_id", uniqid("cart_", true) . "." . dechex(mt_rand(0, pow(2, 32)))); } $this->set("loggedIn", $this->loggedIn); $this->set("user", $this->user); $this->set("me", $this->user); $this->set("admin", $this->admin); $this->set("superAdmin", $this->superAdmin); $this->set("adminTheaters", $this->adminTheaters); }
/** * Before filter callback * * @param \Cake\Event\Event $event The beforeFilter event. * * @return void */ public function beforeFilter(Event $event) { parent::beforeFilter($event); $this->Auth->allow(); // SFW $this->set('seeNSFW', $this->request->session()->read('seeNSFW')); // Languages $lang = $this->request->session()->read('language'); $this->set('availableLanguages', $this->request->session()->read('languages')); $this->set('siteLanguage', $lang); I18n::locale($this->_getFolderNameFromLangCode($lang)); // User menu $authUser = null; if (!is_null($this->Auth->user('id'))) { $authUser = $this->Auth->user(); } $this->set('authUser', $authUser); }
/** * Before render callback. * * @param \Cake\Event\Event $event The beforeRender event. * @return void */ public function beforeFilter(Event $event) { parent::beforeFilter($event); $json = file_get_contents('php://input'); $obj = json_decode($json); $data = (array) $obj; foreach ($data as $key => $value) { $this->request->data[$key] = $value; } if (!$this->Auth->user() && $this->request->action != 'login') { $this->auth_by_token(); } if ($this->Auth->user()) { $this->current_user = $this->Users->get($this->Auth->user('id')); } ob_clean(); header('Access-Control-Allow-Origin', '*'); }
/** * AppController::beforeFilter() * * @return void */ public function beforeFilter(Event $event) { parent::beforeFilter($event); // Automatic login using cookie. if (!$this->Auth->user() && $this->Cookie->read('CookieAuth')) { $user = $this->Auth->identify(); if ($user) { $this->Auth->setUser($user); } else { $this->Cookie->delete('CookieAuth'); } } $controllerName = $this->request->params['controller']; // Allow public actions with no authentication. if (array_key_exists($controllerName, $this->_publicActions)) { $this->Auth->allow($this->_publicActions[$controllerName]); } }
public function beforeFilter(Event $event) { parent::beforeFilter($event); $authUser = $this->Auth->user(); $this->set(compact('authUser')); $this->Auth->allow(['index', 'login', 'logout', 'register']); }
public function beforeFilter(Event $event) { parent::beforeFilter($event); if ($this->Crud) { $this->Crud->on('setFlash', function (Event $event) { $event->subject()->params['class'] = str_replace('message ', 'alert alert-dismissible fade in alert-', $event->subject()->params['class']); }); } }