本文整理汇总了PHP中UserGroup::isUserGroupAccess方法的典型用法代码示例。如果您正苦于以下问题:PHP UserGroup::isUserGroupAccess方法的具体用法?PHP UserGroup::isUserGroupAccess怎么用?PHP UserGroup::isUserGroupAccess使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserGroup
的用法示例。
在下文中一共展示了UserGroup::isUserGroupAccess方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeFilter
/**
* 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.
*
* @param object $c current controller object
* @return void
*/
function beforeFilter(&$c)
{
$user = $this->__getActiveUser();
UsermgmtInIt($this);
$pageRedirect = $c->Session->read('permission_error_redirect');
$c->Session->delete('permission_error_redirect');
$controller = $c->params['controller'];
$action = $c->params['action'];
$actionUrl = $controller . '/' . $action;
$requested = isset($controller->params['requested']) && $controller->params['requested'] == 1 ? true : false;
$permissionFree = array('users/login', 'users/logout', 'users/register', 'users/userVerification', 'users/forgotPassword', 'users/activatePassword', 'pages/display', 'users/accessDenied', 'users/customer_register', 'users/customer_login');
if ((empty($pageRedirect) || $actionUrl != 'users/login') && !$requested && !in_array($actionUrl, $permissionFree)) {
App::import("Model", "Usermgmt.UserGroup");
$userGroupModel = new UserGroup();
if (!$this->isLogged()) {
if (!$userGroupModel->isGuestAccess($controller, $action)) {
$c->log('permission: actionUrl-' . $actionUrl, LOG_DEBUG);
$c->Session->write('permission_error_redirect', '/users/login');
$c->Session->setFlash('You need to be signed in to view this page.');
$c->Session->write('Usermgmt.OriginAfterLogin', '/' . $c->params->url);
$c->redirect('/login');
}
} else {
if (!$userGroupModel->isUserGroupAccess($controller, $action, $this->getGroupId())) {
$c->log('permission: actionUrl-' . $actionUrl, LOG_DEBUG);
$c->Session->write('permission_error_redirect', '/users/login');
$c->redirect('/accessDenied');
}
}
}
}
示例2: authorize
/**
* 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.
*
* @param object $c current controller object
* @return void
*/
function authorize(&$controller)
{
$user = $this->getUser();
$pageRedirect = $controller->Session->read('permission_error_redirect');
$controller->Session->delete('permission_error_redirect');
$action = $controller->params['action'];
$actionUrl = $controller->params['controller'] . '/' . $action;
$this->updateActivity($controller, $actionUrl);
$requested = isset($controller->params['requested']) && $controller->params['requested'] == 1 ? true : false;
if (!in_array($actionUrl, unserialize(PERMISSION_FREE)) && empty($pageRedirect) && !$requested && !in_array($controller->params['controller'], array('css', 'img'))) {
App::import("Model", "Users.UserGroup");
$userGroupModel = new UserGroup();
if (!$this->User->isLogged()) {
if (!$userGroupModel->isGuestAccess($controller->params['controller'], $action)) {
$controller->Session->write('permission_error_redirect', array('plugin' => 'users', 'controller' => 'users', 'action' => 'login'));
$controller->Session->setFlash(__('You need to be signed in to view this page!'), 'warning');
$cUrl = '/' . $controller->params->url;
if (!empty($_SERVER['QUERY_STRING'])) {
$rUrl = $_SERVER['REQUEST_URI'];
$pos = strpos($rUrl, $cUrl);
$cUrl = substr($rUrl, $pos, strlen($rUrl));
}
if ($controller->request->is('ajax')) {
$controller->Session->write('Authorization.Redirect', $_SERVER['HTTP_REFERER']);
$controller->redirect(array('plugin' => 'users', 'controller' => 'users', 'action' => 'login'));
}
$controller->Session->write('Authorization.Redirect', $cUrl);
$controller->redirect(array('plugin' => 'users', 'controller' => 'users', 'action' => 'login'));
}
} else {
if (!$userGroupModel->isUserGroupAccess($controller->params['controller'], $action, $this->User->Group->id())) {
$controller->redirect(array('plugin' => 'users', 'controller' => 'users', 'action' => 'accessDenied'));
}
}
} elseif (!empty($pageRedirect)) {
$controller->redirect($pageRedirect);
}
$this->setLanguage($this->getLanguage());
}
示例3: beforeFilter
/**
* 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.
*
* @param object $c current controller object
* @return void
*/
function beforeFilter(&$c)
{
UsermgmtInIt($this);
$user = $this->__getActiveUser();
$pageRedirect = $c->Session->read('permission_error_redirect');
$c->Session->delete('permission_error_redirect');
$controller = $c->params['controller'];
$action = $c->params['action'];
$actionUrl = $controller . '/' . $action;
$requested = isset($c->params['requested']) && $c->params['requested'] == 1 ? true : false;
$permissionFree = array('users/login', 'users/logout', 'users/register', 'users/userVerification', 'users/forgotPassword', 'users/activatePassword', 'pages/display', 'users/accessDenied', 'users/emailVerification');
$access = str_replace(' ', '', ucwords(str_replace('_', ' ', $controller))) . '/' . $action;
$allControllers = $this->ControllerList->getControllerWithMethods();
$errorPage = false;
if (!in_array($access, $allControllers)) {
$errorPage = true;
}
if ((empty($pageRedirect) || $actionUrl != 'users/login') && !$requested && !in_array($actionUrl, $permissionFree) && !$errorPage) {
App::import("Model", "Usermgmt.UserGroup");
$userGroupModel = new UserGroup();
if (!$this->isLogged()) {
if (!$userGroupModel->isGuestAccess($controller, $action)) {
$c->log('permission: actionUrl-' . $actionUrl, LOG_DEBUG);
$c->Session->write('permission_error_redirect', '/users/login');
$c->Session->setFlash('You need to be signed in to view this page.');
$cUrl = '/' . $c->params->url;
if (!empty($_SERVER['QUERY_STRING'])) {
$rUrl = $_SERVER['REQUEST_URI'];
$pos = strpos($rUrl, $cUrl);
$cUrl = substr($rUrl, $pos, strlen($rUrl));
}
$c->Session->write('Usermgmt.OriginAfterLogin', $cUrl);
$c->redirect('/login');
}
} else {
if (!$userGroupModel->isUserGroupAccess($controller, $action, $this->getGroupId())) {
$c->log('permission: actionUrl-' . $actionUrl, LOG_DEBUG);
$c->Session->write('permission_error_redirect', '/users/login');
$c->redirect('/accessDenied');
}
}
}
}
示例4: beforeFilter
//.........这里部分代码省略.........
$acToken = $ret->access_token;
$rToken = $ret->refresh_token;
$acExpr = $ret->expires_in;
$this->Session->write('wechatUserInfo', $user);
$wechatUserInfo = $user;
$openId = $ret->openid;
}
/*user account about wechat's system is done*/
//bind our system id;
//wechat user data stored in db
// wechatUser: in our DB ; wechatUserInfo: in cookie and wechat's system
// they are different
$username = $wechatUserInfo->nickname;
$wechatUser = $this->WeChatDataModel->getWechatUserByOpenId($openId);
if (!$wechatUser) {
///yes
//create sys user
if ($username == '') {
$wechatUserInfo = $this->Session->read('wechatUserInfo');
$username = $wechatUserInfo->nickname;
}
//create and bind it
$count = 0;
while ($this->User->findByFirstName($username)) {
if ($count == 0) {
$username = '来自微信的_' . $username;
} else {
$username = $userInfo['name'] . "{$count}";
$count += 1;
}
}
$sysUser = $this->newEmptyUserByWechat($openId, $username);
//$this->UserAuth->debug($openId, $username);
//var_dump($sysUser);
//bind
$userId = $sysUser['User']['id'];
$data = array();
$data['WechatUser']['iz_user_id'] = $userId;
$data['WechatUser']['wechat_name'] = $username;
// when we update these? todo
$data['WechatUser']['open_id'] = $openId;
$data['WechatUser']['access_token'] = $acToken;
$expTime = $acExpr + time();
$exptimeStamp = date("Y-m-d H:i:s", $expTime);
$data['WechatUser']['access_token_expire'] = $exptimeStamp;
$data['WechatUser']['refresh_token'] = $rToken;
$this->WechatUser->save($data);
$wechatUser = $this->WeChatDataModel->getWechatUserByOpenId($openId);
}
$c->wechatUser = $wechatUser;
// got the info of our system' user account
$userId = $wechatUser['WechatUser']['iz_user_id'];
// login our sys
$sysUser = $this->User->findById($userId);
$this->login($sysUser);
$this->setUser($c);
}
$user = $this->__getActiveUser();
$pageRedirect = $c->Session->read('permission_error_redirect');
$c->Session->delete('permission_error_redirect');
$controller = $c->params['controller'];
$action = $c->params['action'];
$actionUrl = $controller . '/' . $action;
$requested = isset($c->params['requested']) && $c->params['requested'] == 1 ? true : false;
$permissionFree = array('users/login', 'users/logout', 'users/register', 'users/userVerification', 'users/forgotPassword', 'users/activatePassword', 'pages/display', 'users/accessDenied', 'users/emailVerification');
$access = str_replace(' ', '', ucwords(str_replace('_', ' ', $controller))) . '/' . $action;
$allControllers = $this->ControllerList->getControllerWithMethods();
$errorPage = false;
if (!in_array($access, $allControllers)) {
$errorPage = true;
}
if ((empty($pageRedirect) || $actionUrl != 'users/login') && !$requested && !in_array($actionUrl, $permissionFree) && !$errorPage) {
App::import("Model", "Usermgmt.UserGroup");
$userGroupModel = new UserGroup();
if (!$this->isLogged()) {
//redirect to login
if (!$userGroupModel->isGuestAccess($controller, $action)) {
$c->log('permission: actionUrl-' . $actionUrl, LOG_DEBUG);
$c->Session->write('permission_error_redirect', '/users/login');
$c->Session->setFlash(__('您需要登陆才能看这个页面哦...'));
$cUrl = '/' . $c->params->url;
if (!empty($_SERVER['QUERY_STRING'])) {
$rUrl = $_SERVER['REQUEST_URI'];
$pos = strpos($rUrl, $cUrl);
$cUrl = substr($rUrl, $pos, strlen($rUrl));
}
$c->Session->write('Usermgmt.OriginAfterLogin', $cUrl);
$c->redirect('/login');
}
} else {
//logged
$this->setUser($c);
if (!$userGroupModel->isUserGroupAccess($controller, $action, $this->getGroupId())) {
$c->log('permission: actionUrl-' . $actionUrl, LOG_DEBUG);
$c->Session->write('permission_error_redirect', '/users/login');
$c->redirect('/accessDenied');
}
}
}
}