本文整理汇总了PHP中Controller::beforeFilter方法的典型用法代码示例。如果您正苦于以下问题:PHP Controller::beforeFilter方法的具体用法?PHP Controller::beforeFilter怎么用?PHP Controller::beforeFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Controller
的用法示例。
在下文中一共展示了Controller::beforeFilter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeFilter
public function beforeFilter()
{
$this->loadModel('User');
parent::beforeFilter();
// Disable content cache for Chrome
$this->response->disableCache();
// Delete the default auth message. Just show them the login page
// people will get the idea pretty quickly.
$this->Session->delete('Message.auth');
/*if ($this->RequestHandler->isMobile()) {
$this->layout = 'mobile';
$this->isMobile = true;
} else {
$this->layout = 'mobile';
$this->isMobile = true;
}*/
if ($this->request->is('ajax')) {
$this->layout = 'ajax';
}
$this->Auth->allow('index', 'view', 'display');
// Let everyone know about the user
$this->set('loggedIn', $this->Auth->loggedIn());
$user = $this->Auth->user();
$this->isAdmin = $this->User->isAdmin($user);
$this->isEditor = $this->User->isEditor($user);
$this->set('loggedInuserId', $this->Auth->user('id'));
$this->set('isAdmin', $this->isAdmin);
$this->set('isEditor', $this->isEditor);
$this->set('allowAccountCreation', Configure::read('App.allowPublicAccountCreation'));
}
示例2: beforeFilter
public function beforeFilter()
{
parent::beforeFilter();
$this->player = null;
$this->isPlayer = false;
$this->isGameMaster = false;
$this->helpers['Format'] = array('timezone' => $this->Auth->user('timezone'));
if ($this->Auth->user()) {
$playerId = $this->Auth->user('id');
$this->AccessLog->save(array('plugin' => $this->request->plugin, 'controller' => $this->request->controller, 'action' => $this->request->action, 'params' => json_encode($this->request->params['pass']), 'post' => json_encode($_POST), 'get' => json_encode($_GET), 'player_id' => $playerId));
$this->player = $this->Player->findById($playerId);
unset($this->player['Player']['password']);
if (!$this->request->is('ajax') && $this->request->is('get')) {
$notifications = $this->Notification->unread($playerId, 5);
$this->set('notificationsUnread', $notifications);
}
$this->isPlayer = $this->player['Player']['player_type_id'] == PLAYER_TYPE_PLAYER;
$this->isGameMaster = $this->player['Player']['player_type_id'] == PLAYER_TYPE_GAME_MASTER;
$this->set('myPendingActivitiesCount', $this->Log->countPendingFromPlayer($playerId));
$this->set('activitiesNotReviewedCount', $this->Log->countNotReviewed());
$this->set('teamPendingActivities', $this->Log->countPendingFromTeamNotFromPlayer($playerId));
$this->set('allDomains', $this->Domain->allFromOwner($this->gameMasterId()));
}
$this->set('isPlayer', $this->isPlayer);
$this->set('isGameMaster', $this->isGameMaster);
$this->set('loggedPlayer', $this->player);
$this->set('collapseSidebar', false);
}
示例3: beforeFilter
/**
* [beforeFilter description]
* @return [type] [description]
*/
public function beforeFilter()
{
parent::beforeFilter();
$endpoint = 'http://earthquake.usgs.gov/fdsnws/event/1/query.geojson?starttime=%DATEMIN%%2000:00:00&minmagnitude=2&endtime=%DATEMAX%%2023:59:59&orderby=time';
$endpointTokens = ['%DATEMIN%', '%DATEMAX%'];
$this->scrapper = new Scrapper($endpoint, $endpointTokens);
}
示例4: beforeFilter
function beforeFilter()
{
parent::beforeFilter();
if (!$this->authenticate_token()) {
exit;
}
}
示例5: beforeFilter
public function beforeFilter()
{
$this->Auth->authorize = array('Actions' => array('actionPath' => 'controllers/'));
$this->Auth->authenticate = array('Blowfish');
$this->Auth->authError = __d('cake', 'You are not authorized to access the request action');
parent::beforeFilter();
}
示例6: beforeFilter
public function beforeFilter()
{
parent::beforeFilter();
//Basic認証
$this->autoRender = false;
$loginId = 'yamaoka';
$loginPassword = 'yamaoka';
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="Please enter your ID and password"');
header('HTTP/1.0 401 Unauthorized');
die("id / password Required");
} else {
if ($_SERVER['PHP_AUTH_USER'] != $loginId || $_SERVER['PHP_AUTH_PW'] != $loginPassword) {
header('WWW-Authenticate: Basic realm="Please enter your ID and password"');
header('HTTP/1.0 401 Unauthorized');
die("Invalid id / password combination. Please try again");
}
}
$typeArr = array("芝", "ダート");
$this->set("typeArr", $typeArr);
$turnArr = array("右", "左");
$this->set("turnArr", $turnArr);
$viewArr = array("非公開", "公開");
$this->set("viewArr", $viewArr);
$acceptArr = array("停止", "受付中");
$this->set("acceptArr", $acceptArr);
$kojiharuArr = array("-", "対象レース");
$this->set("kojiharuArr", $kojiharuArr);
$this->user = $this->Auth->user();
$this->set("user", $this->user);
//アクセス許可
$this->Auth->allow('admin_login', 'admin_logout');
$this->autoRender = true;
}
示例7: beforeFilter
public function beforeFilter()
{
$this->Cookie->httpOnly = true;
$currency = $this->currency();
if (!$this->Auth->loggedIn() && $this->Cookie->read('rememberMe')) {
$cookie = $this->Cookie->read('rememberMe');
$this->loadModel('User');
// If the User model is not loaded already
$user = $this->User->find('first', array('conditions' => array('User.email' => $cookie['email'], 'User.password' => $cookie['password'])));
if ($user && !$this->Auth->login($user['User'])) {
$this->redirect('/users/logout');
// destroy session & cookie
}
}
$this->createArrayValue();
$param = $this->request->params;
$action = $param['action'];
if ($this->params['prefix'] == '') {
$this->Auth->allow();
} elseif ($this->params['prefix'] == 'mpadmin') {
if ($this->Session->read('Auth.User')) {
if ($this->Auth->user('role_id') == 1) {
$this->Auth->allow();
} else {
$this->Session->destroy();
$this->Session->setFlash(__('Your are not authorized here '));
$this->redirect(array('prefix' => false, 'controller' => 'users', 'action' => 'login'));
}
} else {
$this->Auth->allow('mpadmin_login');
}
}
parent::beforeFilter();
$this->set(compact('currency'));
}
示例8: beforeFilter
function beforeFilter()
{
parent::beforeFilter();
$pageRedirect = $this->Session->read('permission_error_redirect');
$this->Session->delete('permission_error_redirect');
$this->company_id = $this->Session->read('Company.id');
if (empty($pageRedirect)) {
$actionUrl = $this->params['url']['url'];
if (isset($this->params['slug'])) {
$website = $this->Website->find('Website.subdomain = "' . $this->params['slug'] . '"');
} else {
$website = null;
}
if (!$website) {
$user = $this->Authsome->get();
if (!$user) {
//anonymous?
if (!$this->UserGroup->isGuestAccess($actionUrl)) {
$this->Session->write('permission_error_redirect', '/users/login');
$this->Session->setFlash('Sorry, You don\'t have permission to view this page.');
$this->redirect('/users/login');
}
} else {
if (!$this->UserGroup->isUserGroupAccess($user['User']['user_group_id'], $actionUrl)) {
$this->Session->write('permission_error_redirect', '/users/login');
$this->Session->setFlash('Sorry, You don\'t have permission to view this page. ' . $user['User']['user_group_id'] . ':(' . $actionUrl . ')');
$this->redirect('/users/dashboard');
}
}
}
}
}
示例9: beforeFilter
function beforeFilter()
{
parent::beforeFilter();
$this->loadModel('Event');
$sidebar_events = $this->Event->get_upcoming_events(4);
$this->set('sidebar_events', $sidebar_events);
}
示例10: beforeFilter
public function beforeFilter()
{
$this->_setSettings();
parent::beforeFilter();
$ext = explode(".", $this->request->here);
$ext = strtolower($ext[count($ext) - 1]);
if (!in_array($ext, array("gif", "png", "php", "jpg", "pdf")) && !strstr($this->request->here, "/admin")) {
$this->loadModel('Seo.SeoUri');
$uri = $this->SeoUri->find('first', array('conditions' => array('SeoUri.uri' => $this->request->here)));
if (empty($uri)) {
$this->SeoUri->create();
$this->SeoUri->save(array('SeoUri' => array('uri' => $this->request->here, 'is_approved' => 1, 'created' => date("Y-m-d H:i:s", time()), 'modified' => date("Y-m-d H:i:s", time()))));
}
}
$this->Auth->authenticate = array('all' => array('userModel' => 'User'), 'Form');
$this->Auth->allow('admin_add', 'getglobals');
if ($this->request->param("prefix")) {
$this->layout = "admin";
}
$this->loadModel('User');
$this->set('authUser', $this->User->find('first', array('conditions' => array('User.id' => $this->Auth->User('id')))));
$this->loadModel('Size');
$this->set("sizes_cart", $this->Size->find('all'));
$this->set("patterns", $this->_patterns);
$this->set("_bycolorswt", $this->_bycolorswatchs());
$this->_getglobals();
}
示例11: beforeFilter
public function beforeFilter()
{
parent::beforeFilter();
//$this->set('title_for_layout','Seção de Administração para o Aplicativo');
$this->set('current_user', $this->Auth->user());
$controller = $this->params['controller'];
$action = $this->params['action'];
$user = $this->Auth->user();
$groupid = $user['group_id'];
$this->Auth->allow('index');
//'add'
if ($action != 'index') {
// || $action != 'add'
if ($this->AccessControl->access($controller, $action) == 'admins' && $groupid == 1) {
//
} elseif ($this->AccessControl->access($controller, $action) == 'managers' && $groupid == 2) {
//
} else {
if ($this->AccessControl->access($controller, $action) == false) {
//$this->Session->setFlash(__('Privilégio não cadastrado/Acesso Negado!'));
} else {
$this->redirect(array('plugin' => 'admin', 'controller' => 'users', 'action' => 'login'));
}
}
}
}
示例12: beforeFilter
/**
* beforeFilter
*
* @return void
* @throws MissingComponentException
*/
public function beforeFilter()
{
parent::beforeFilter();
$aclFilterComponent = Configure::read('Site.acl_plugin') . 'Filter';
if (empty($this->{$aclFilterComponent})) {
throw new MissingComponentException(array('class' => $aclFilterComponent));
}
$this->{$aclFilterComponent}->auth();
$this->RequestHandler->setContent('json', 'text/x-json');
$this->Security->blackHoleCallback = 'securityError';
$this->Security->requirePost('admin_delete');
if (isset($this->request->params['admin'])) {
$this->layout = 'admin';
}
if ($this->RequestHandler->isAjax()) {
$this->layout = 'ajax';
}
if (Configure::read('Site.theme') && !isset($this->request->params['admin'])) {
$this->theme = Configure::read('Site.theme');
} elseif (Configure::read('Site.admin_theme') && isset($this->request->params['admin'])) {
$this->theme = Configure::read('Site.admin_theme');
}
if (!isset($this->request->params['admin']) && Configure::read('Site.status') == 0) {
$this->layout = 'maintenance';
$this->response->statusCode(503);
$this->set('title_for_layout', __('Site down for maintenance'));
$this->render('../Elements/blank');
}
if (isset($this->request->params['locale'])) {
Configure::write('Config.language', $this->request->params['locale']);
}
}
示例13: beforeFilter
public function beforeFilter()
{
parent::beforeFilter();
Configure::config('configini', new IniReader());
Configure::load('config.ini', 'configini');
/*
* "Auth" logic
* Generate and test the security key
*/
$api = json_decode($this->Setting->getOption('api'));
if (empty($api) || empty($api->enabled) || !$api->enabled) {
return $this->api401(__('API is disabled'));
}
// No key, refuse connexion
if (empty($this->request->params['named']) || empty($this->request->params['named']['key'])) {
return $this->api401(__('Security key is missing'));
}
// Get the key and remote it from the params
$theirSecurityKey = $this->request->params['named']['key'];
unset($this->request->params['named']['key']);
// generate the security key
$paramsUrl = '/' . $this->request->params['controller'] . '/' . $this->request->params['action'];
$paramsUrl .= $this->Tools->paramsToUrl($this->request->params['named']);
$securityKey = hash_hmac('sha1', $paramsUrl, $api->privateKey);
if ($theirSecurityKey != $securityKey) {
return $this->api401(__('Wrong security key'));
}
}
示例14: beforeFilter
public function beforeFilter()
{
parent::beforeFilter();
$this->Auth->userScope = array('User.status' => 1);
$this->Auth->allow('login');
$this->Auth->fields = array('username' => 'username', 'password' => 'password');
/*
if($this->Auth->user()){
$userid = $this->Session->read('Auth.User.id');
$this->loadModel('Inbox');
$notifquery="SELECT
(SELECT SUM(sender_read) FROM mfc353_2.inboxes WHERE sender_id=$userid)
+
(SELECT SUM(receiver_read) FROM mfc353_2.inboxes WHERE receiver_id=$userid)
as SumCount";
$notif=$this->Inbox->query($notifquery);
$notifications=$notif[0][0]['SumCount'];
if($notifications!=0){
if($notifications=1)
$notification="You have $notifications unread message in your inbox!";
else
$notification="You have $notifications unread messages in your inbox!";
$this->Session->setFlash(__($notification), 'good');
}
}
*/
}
示例15: beforeFilter
public function beforeFilter()
{
parent::beforeFilter();
//$this->_setupSecurity();
$this->loadModel('Description');
$desc = $this->Description->find('all', array('conditions' => array('Description.pagetype' => 'history', 'Description.visible' => true)));
$history_menu = array();
foreach ($desc as $d) {
$history_menu[$d['Description']['name']] = array('controller' => 'firearms', 'action' => 'learn', 'history', $d['Description']['slug']);
}
$desc = $this->Description->find('all', array('conditions' => array('Description.pagetype' => 'firearm', 'Description.visible' => true)));
$firearm_menu = array();
foreach ($desc as $d) {
$firearm_menu[$d['Description']['name']] = array('controller' => 'firearms', 'action' => 'learn', 'firearm', $d['Description']['slug']);
}
/*
$desc=$this->Description->find('all',array('conditions'=>array('Description.pagetype'=>'Gun','Description.visible'=>true)));
$gun_menu=array();
foreach ($desc as $d){
$gun_menu[$d['Description']['name']]=array('controller'=>'firearms','action'=>'gunview',$d['Description']['id']);
}
$desc=$this->Description->find('all',array('conditions'=>array('Description.pagetype'=>'Feature','Description.visible'=>true)));
$f_menu=array();
foreach ($desc as $d){
$f_menu[$d['Description']['name']]=array('controller'=>'firearms','action'=>'featureview',$d['Description']['id']);
}
*/
$menu_array = array('Firearms History' => array('dropdown' => $history_menu), 'Our Firearms' => array('dropdown' => $firearm_menu), 'Packages' => array('controller' => 'firearms', 'action' => 'packages'));
$this->set(compact('menu_array'));
}