2016-08-22 12 views
0

私はCloud 9 IDEサーバーでCakephp 3.2.11を使用しています。Cakephp 3 - 認証セッションは破棄できません

  1. 私はAuthコンポーネント経由でアプリケーションにログアウトしました。私は再びログインしませんでしたが、いくつかのページにアクセスしようとしました。認証セッションのログイン要求などが登場した。(私はそれを設計していなかった)

enter image description here

が、私は、データベースに私のUsersテーブルでユーザ名&パスワードを入力します。それはLOGGED INでした。

  1. ログアウトしてみると、すべてのセッションが破棄されました。私のアプリはまだ私が上記のようにログインしたセッションを記録しました。私はデバッグを使用してチェックします:

    デバッグ($ this-> request-> session() - > read( 'Auth'));

    ここ

Authコンポーネントの設定

$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', 
          ] 
         ] 

と私のログアウト()

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

マイAppController.php今私は、コードを使用して、そのセッションを削除することはできません、私は明確で、それを削除することができますブラウザのキャッシュだから私の質問は:

どのように私のコードを使用してこの問題を解決するか、私のアプリの設定を構成できますか? @Kamleshグプタに基づいて

UPDATEが、答えは私のコードを編集し、それは大丈夫です。

$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', 
          ] 
         ] 

答えて

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(); 
} 

このコードは私のための仕事です。私は私のアプリで使用しています。

また、モデル名とフィールド名を変更してみてください。

+1

ありがとうございます。 – TommyDo

関連する問題