2016-08-22 2 views
0

Ich benutze CakePHP 3.2.11 auf Cloud 9 IDE-Server.CakePHP 3 - Auth Sitzung kann nicht

  1. Wenn ich mich über Auth-Komponente bei meiner App abgemeldet habe. Ich habe mich nicht erneut angemeldet, aber ich habe versucht, auf einige Seiten zuzugreifen. Es wurde Auth-Session Login-Anfrage erscheint wie: (ich habe es nicht Design)

enter image description here

I Benutzername & Passwort in meinem Benutzer Tabelle in der Datenbank eingeben. Es wurde eingeloggt.

  1. Jetzt, als ich versuchte mich abzumelden, zerstöre alle Sitzungen; Meine App hat immer noch die Sitzung aufgezeichnet, in der ich mich angemeldet habe. Ich benutze Debug zu überprüfen:

    debug ($ this-> request-> session() -> lesen ('Auth'));

Hier mein logout()

public function logout() 
    { 
     $this->request->session()->destroy(); 
     return $this->redirect($this->Auth->logout()); 
    } 

Meine AppController.php mit Auth Komponente Config

$this->loadComponent('Auth', [ 
      'authenticate' => array(
       'Form' => array(
        // 'fields' => array('username' => 'email'), 
        'scope' => array('is_delete' => '0') 
       ) 
      ), 
      'loginAction' => [ 
       'controller' => 'MUsers', 
       'action' => 'login'    
      ], 
      'authorize' => ['Controller'], 
      'loginRedirect' => [ 
       'controller' => 'Pages', 
       'action' => 'dashboard' 
      ], 
      'logoutRedirect' => [ 
       'controller' => 'MUsers', 
       'action' => 'login' 
      ], 
      'storage' => 'Session', 
      'authError' => 'Woopsie, you are not authorized to access this area.', 
      'flash' => [ 
       'params' => [ 
        'class' => 'alert alert-danger alert-dismissible text-c', 
          ] 
         ] 

Jetzt kann ich nicht, dass die Sitzung unter Verwendung von Code löschen, ich kann es nur löschen, indem klar der Browser-Cache. Also meine Fragen sind:

Wie kann ich dieses Problem mit Code oder Konfiguration meiner App-Einstellungen lösen?

UPDATE

Basierend auf @Kamlesh Gupta beantwortet, es ist mein Code bearbeitet und es ist in Ordnung.

$this->loadComponent('Auth', [ 
      'authenticate' => array(
       'Form' => array(
       'userModel' => 'MUsers', //Add this line 
       'fields' => array('username' => 'username', 
            'password' => 'password'), //Edited this line 
        'scope' => array('is_delete' => '0') 
       ) 
      ), 
      'loginAction' => [ 
       'controller' => 'MUsers', 
       'action' => 'login'    
      ], 
      'authorize' => ['Controller'], 
      'loginRedirect' => [ 
       'controller' => 'Pages', 
       'action' => 'dashboard' 
      ], 
      'logoutRedirect' => [ 
       'controller' => 'MUsers', 
       'action' => 'login' 
      ], 
      'storage' => 'Session', 
      'authError' => 'Woopsie, you are not authorized to access this area.', 
      'flash' => [ 
       'params' => [ 
        'class' => 'alert alert-danger alert-dismissible text-c', 
          ] 
         ] 

Antwort

2
For login authentication, 

Use below code in appController.php 

$this->loadComponent('Auth', [ 
      'authenticate' => [ 
       'Form' => [ 
        'userModel' => 'Users', 
        'fields' => array(
         'username' => 'email', 
         'password' => 'password' 
        ), 
       ], 
      ], 
      'logoutRedirect' => [ 
        'controller' => 'users', 
        'action' => 'login' 
       ], 
      'loginAction' => [ 
       'controller' => 'Users', 
       'action' => 'login' 
      ], 
      'unauthorizedRedirect' => false, 
      'storage' => 'Session' 
     ]); 

**for destroying session** 
public function logout() 
{ 
    $this->Auth->logout(); 
} 

Dieser Code ist für mich zu arbeiten. Ich verwende in meiner App.

Sie können auch versuchen, ändern Sie einfach Modellname und Feldname, Aktion

+1

Sie sind super, danke. – TommyDo