0
내 config.php 파일에서 이것은 기본 라우터입니다.사용자가 로그인 할 때 기본 경로를 변경하려면 어떻게해야합니까?
Router::connect('/', array('controller' => 'users', 'action' => 'signup'));
사용자가 연결되어 있지 않으면 UsersController에서 편집 작업 및보기 작업에 액세스 할 수있는 권한이 없습니다.
<?php
class UsersController extends AppController{
public $uses = array('User', 'Company', 'Town');
public function beforeFilter(){
parent::beforeFilter();
// If the user is not connected he can't access to these pages
$this->Auth->deny('view', 'edit');
}
}
사용자가 로그인 양식을 사용하여 로그인하면 로그인 페이지 컨트롤러 및 색인 작업으로 리디렉션됩니다.
컨트롤러 사용자의 작업 등록에 (사용자 및 관리자 역할)을 입력 할 수 없기를 바랍니다. 따라서 사용자가 연결된 경우 (admin 또는 user) 기본 경로가 변경되었습니다. 하지만 내 경우에는 내가 무엇을해야하는지 모른다.
의 AppController :
<?php
class AppController extends Controller{
public $helpers = array('Text','Form','Html','Session','Cache');
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'pages', 'action' => 'index'),
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'email')
)
)
)
);
function beforeFilter(){
$this->Auth->loginAction = array('controller'=>'users','action'=>'login','admin'=>false);
//tell Auth to call the isAuthorized function before allowing access
$this->Auth->authorize = array('Controller');
//allow all non-logged in users access to items without a prefix
if(!isset($this->request->params['prefix'])){
$this->Auth->allow();
}
if(isset($this->request->params['prefix']) && $this->request->params['prefix'] == 'admin'){
$this->layout = 'admin';
}
// Si l'utilisateur est connecté
if (isset($this->Auth) && $this->Auth->user('id')) {
$this->layout = 'user';
}
}
function isAuthorized($user){
if(!isset($this->request->params['prefix'])){
return true;
}
$roles = array(
'admin' => 10,
'user' => 5
);
return false;
}
}
감사합니다.