1

我正在使用他们的 fb 用户 ID 登录用户。因此,我在登录用户时不需要用户名或密码。这工作正常。但是,当我尝试访问时,$this->Auth->user什么都没有保存。请看下面的代码。

$this->authUser = $this->User->findById($user_profile['id']);
        if($this->authUser){
            if($this->Auth->login($this->authUser)){
            $this->redirect('/Users/dash');
            }

有任何想法吗?

如果我调试$this->Auth而不是进行重定向,我会得到以下信息:

object(AuthComponent) {
components => array(
    (int) 0 => 'Session',
    (int) 1 => 'RequestHandler'
)
authenticate => array(
    (int) 0 => 'Form'
)
authorize => array(
    (int) 0 => 'Controller'
)
ajaxLogin => null
flash => array(
    'element' => 'default',
    'key' => 'auth',
    'params' => array()
)
loginAction => array(
    'controller' => 'users',
    'action' => 'login',
    'plugin' => null
)
loginRedirect => null
logoutRedirect => array(
    'controller' => 'users',
    'action' => 'login',
    'plugin' => null
)
authError => 'You can't access that page'
allowedActions => array(
    (int) 0 => 'index',
    (int) 1 => 'view'
)
request => object(CakeRequest) {
    params => array(
        'plugin' => null,
        'controller' => 'Users',
        'action' => 'index',
        'named' => array(),
        'pass' => array()
    )
    data => array(
        'signed_request' => 'Xyx9uGB4OZT_S59w-sMmJe5ofuzCwib2F1dGhfdG9rZW4iOiJBQUFEcDlCdlpDMzRjQkFJSlBaQ3VwVGtoTlJRRGdIWkJEU0IxeWlTZDFhRTNLcXg1TzJma2Ewek1yOUlrTkVUZTBWbGNpaUxhMFpDUWFQd0ZOWVF3MnZyU1B4NXFrV2VqMjlOMzY4NXJ2d1pEWkQiLCJwYWdlIjp7ImlkIjoiMjQ3ODg2NjY1MzMxOTgwIiwibGlrZWQiOnRydW8BPoTx2YAtQtdin0.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImV4cGlyZXMiOjEzNDYyNjMyMDAsImlzc3VlZF9hdCI6MTM0NjI1NzU3NUsImFkbWluIjp0cnVlfSwidXNlciI6eyJjb3VudHJ5IjoiZ2IiLCJsb2NhbGUiOiJlbl9HQiIsImFnZSI6eyJtaW4iOjIxfX0sInVzZXJfaWQiOiI2NjEyNjMzODgifQ'
    )
    query => array()
    url => 'Users/index'
    base => ''
    webroot => '/'
    here => '/Users/index'
}
response => object(CakeResponse) {

}
settings => array(
    'authError' => 'You can't access that page',
    'authorize' => array(
        (int) 0 => 'Controller'
    )
)
Session => object(SessionComponent) {
    settings => array()
    components => array()
}

}

谢谢!

4

2 回答 2

1

试试这个(对我有用,我用它在帐户激活后自动登录用户):

$user = $this->User->findById($id);
$user = $user['User'];
$this->Auth->login($user);

$this->Auth->user 也不是属性。如果你想访问它,你必须写$this->Auth->user();.

于 2012-08-31T06:23:08.500 回答
0

您无法登录,因为查找结果包含散列密码。并且$this->Auth->login()方法将再次将其转换为散列密码。您无法解密散列密码

您可以使用以下代码执行此操作:

        if($this->Auth->login($user_profile['id'])){
        $this->redirect('/users/dash');
        }

Auth::login 接受用户名/密码组合或简单的用户 ID(数据库中用户模型的主键)。

于 2012-08-30T04:42:36.060 回答