ich habe eine kleine Datenbankanwendung mit cakephp erstellt die ACL-Zugangsbeschränkungen hat. Einige meiner User können sich nicht einloggen, andere haben keine Probleme. Da ich mich mit den Zugangsdaten der Personen problemlos einloggen kann, nehme ich an, dass es nicht an meiner Rechtevergabe liegt, sondern an den Browsereinstellungen der Personen, weiß aber nicht wonach ich suchen soll. Ich hoffe, dass hier jemand eine Idee hat.
Ich denke am besten ist es, ich gebe euch ein paar code-snippets, wie der login bei mir funktioniert.
Wenn ein User nicht eingeloggt ist, wird er als Gast behandelt, dazu im app_controller.php:
- Code: Alles auswählen
public function beforeFilter(){
// Authorization
if(isset($this->Auth)){
parent::beforeFilter();
$this->User->contain('Group');
// login guest
if($this->Auth->User('id') == false){
$data_login['User']['name'] = 'Guest';
$data_login['User']['password'] = ' ';
$data_login['User']['username'] = 'Guest';
$data_login['User']['id'] = 7;
$data_login = $this->Auth->hashPasswords($data_login);
$this->Auth->login($data_login);
}
$auth = $this->User->read(null,$this->Auth->User('id')); // array('user'=>array('id'=>,'name'=>...),'group'=>array())
$this->set('auth',$auth);
//
$this->Auth->allowedActions = array('logout','login');
$this->Auth->authorize = 'controller';
}
}
Welche Seiten Zugang haben, steckt in der Funktion isAuthorized, ebenfalls in app_controller.php. Im array $allowedActions sind alle modells (hier "example") und views (hier "index") aufgelistet und ihnen jeweils ein array (hier 1-5) von group_ids zugeordnet, die Zugriff auf die entsprechende Seite haben.
- Code: Alles auswählen
function isAuthorized(){
// set permissions array
$allowedActions = array(
'example' => array('index' => array('1','2','3','4','5'))
....
);
// test if permission and return true or false
if($this->action == 'display' and $this->Auth->user('group_id')>1){
return true;
}
if(isset($allowedActions[low($this->name)])){
$controllerActions = $allowedActions[low($this->name)];
if(isset($controllerActions[$this->action]) &&
in_array($this->Auth->user('group_id'),$controllerActions[$this->action])){
return true;
}
}
$this->redirect(array('controller'=>'users','action'=>'login'));
}
Die Login-Seite ist users/login, wie von cakephp vorgegeben.
Der users_controller.php lautet:
- Code: Alles auswählen
public function beforeFilter(){
if(isset($this->Auth)){
parent::beforeFilter();
$this->Auth->autoRedirect = false;
//
$this->User->contain('Group');
if ($this->Auth->User('id') != false){
$this->auth = $this->User->read(null,$this->Auth->User('id'));
$this->groupid = $this->auth['User']['group_id'];
$this->userid = $this->auth['User']['id'];
}
}
}
function login(){
// if $this->data is not empty, auth-login is called automatically and not this function.
// to unset this, put "$this->Auth->autoRedirect = false;" in app_controller or before filter
$this->Cookie->write('test', 1);
if(!isset($_GET['cookietest'])){
$this->redirect(array('controller' => 'users', 'action' => 'login?cookietest=true'));
}
if(count($_COOKIE) = 0){
$this->flash(__('Please enable cookies', true), array(),60*60);
}else{
if ($this->Auth->user()) { // always successful because of guest login!
$this->User->id = $this->Auth->user('id');
if($this->User->id != 7){ // not guest
$this->User->saveField('lastlogin', date("Y-m-d H:i:s"));
$this->flash(__('Login successful', true), array('controller'=>'pages','action'=>'home'));
}else{
}
}
}
}