dsgs8208 2014-07-09 08:46
浏览 25

Cakephp管理路由前缀在登录后不会重定向到正确的前缀

I have 2 admin roles (super, admin), at first login, everything works fine but after logout and login as a different admin, it redirect be to the super prefix.

Here is my app controller:

class AppController extends Controller {
public $helpers = array('Js', 'Session');
public $components = array(
    'Session',
    'RequestHandler',
    'DebugKit.Toolbar',
    'Auth' => array(
        'autoRedirect' => false,
        'loginAction' => array(
            'admin' => false,
            'super' => false,
            'controller' => 'users',
            'action' => 'login'
        ),
        'loginRedirect' => array(
            'controller' => 'users',
            'action' => 'dashboard',
            'admin'=> true,
            'super'=> true
        ),
        'logoutRedirect' => array(
            'admin' => false,
            'super' => false,
            'controller' => 'users',
            'action' => 'login'
        ),
        'authError' => 'Please login to continue.',
        'flash' => array('element' => 'flash/default', 'key' => 'auth', 'params' => array('class' => 'error', 'title' => 'Authentication Error')),
        'authorize' => 'Controller',
        'authenticate' => array(
            'Form' => array(
                'userModel' => 'User',
                'fields' => array(
                    'username' => 'email'
                    ),
            )
        ),
    )
);

public function isAuthorized($user) {
    # Accept if Admin
    if($user['admin']){
        return true;
    }

    # Check if current prefix is admin or physician and authenticate user
    if(isset($this->request->prefix)) {
        switch ($this->request->prefix) {
            case 'super':
                if(!$user['super']){
                    $this->Auth->authError = 'Sorry, you do not have permission to access the Manager\'s area';
                }
                return $user['super'];
                break;
             case 'admin':
                if(!$user['admin']){
                    $this->Auth->authError = 'Sorry, you do not have permission to access the Administrators\'s area';
                }else{
                    $this->layout = 'admin_layout';
                }
                return $user['admin'];
                break;
        }
    }else{
        $this->layout = 'super_layout';
        return true;
    }

    $this->Auth->authError = 'Sorry, you do not have permission to access the Admin area';
    return false;
}

public function beforefilter(){
    $this->appSettings = Configure::read('appSettings');
    $this->set('appSettings',  Configure::read('appSettings'));

    if (!$this->Auth->loggedIn()) {
        $this->Auth->authError = false;
    }

     if(isset($this->request->prefix)) {
        switch ($this->request->prefix) {
            case 'admin':
                $this->layout = 'admin_layout';
                $admin = true;
                break;
            case 'super':
                $this->layout = 'super_layout';
                $super = true;
                break;
        }
    }

}
  • 写回答

1条回答 默认 最新

  • duanliexi1052 2014-07-09 09:26
    关注

    property AuthComponent::$loginRedirect

    The URL (defined as a string or array) to the controller action users should be redirected to after logging in. This value will be ignored if the user has an Auth.redirect value in their session.

    If you tried accessed domain.com/super/ and tried to login as an admin, cake will ignore the $loginRedirect attribute and after you login , it will try to redirect you to domain.com/super/ which is the link you tried to access at first

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度