0

ユーザーが自分のユーザー名または電子メール アドレスを使用できるログイン機能を実装しようとしています。私は両方でログインを解決しましたが、ユーザーが自分の電子メールアドレスで正常にログインすると、authError がまだ点滅します (ユーザーはログインしています)。ログインアクションに「HERE」というコメントを付けましたが、その後リダイレクトで何が起こるかわかりません。

これが私のコードの関連ビットです:

アプリ コントローラー:

public $components = array(
    'Auth' => array(
        'authorize' => 'controller',
        'loginRedirect' => array(
            'controller' => 'users',
            'action' => 'welcome_page'
        ),
        'loginError' => 'Invalid user name/password',
        'authError' => 'You don\'t have permission'
    ),

    'Session',
);

ユーザーコントローラー:

public function beforeFilter() {

    parent::beforeFilter();

    $this->Auth->allow('add');
}

public function login() {       

    // At this point, the Auth Component is unable to log in user, so check with email.
    if (!empty($this->data) &&
        !empty($this->Auth->data['User']['username']) &&
        !empty($this->Auth->data['User']['password'])) {        

        // Look for user with email address using the entered username
        $user = $this->User->find('first', array(
            'conditions' => array(
                'User.email' => $this->Auth->data['User']['username'],
                'User.password' => $this->Auth->data['User']['password']
            ),
            'recursive' => -1
        ));

        // Check if a matching user is found and that if login was succesfull
        if (!empty($user) && $this->Auth->login($user)) {       

            if ($this->Auth->autoRedirect) {
                // NOTE: user trying to log in with email reaches HERE
                $this->redirect($this->Auth->redirect());   // this is the default authentication redirect defined in App Controller
            }


        } else {
            $this->Session->setFlash($this->Auth->loginError, $this->Auth->flashElement, array(), 'auth');
        }
    }

}
4

1 に答える 1

0

元の投稿を編集して、セッション変数からメッセージを削除しました。

<?php

$this->Session->delete('Message.flash');
$this->Session->delete('Message.auth');

?>

お役に立てれば!

-アンドリュー

于 2013-03-26T02:44:49.283 に答える