Cakephp手动登录不启动会话 [英] Cakephp manual login not initiating session

查看:60
本文介绍了Cakephp手动登录不启动会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm logging in a user using their fb user id. I therefore have no need for username or password when logging in a user. This works fine. However when I try to access $this->Auth->user nothing is saved. Please see code below.

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

有任何想法吗?

如果我调试 $ this-> Auth 而不是做重定向,我得到以下:

If I debug $this->Auth instead of doing the redirect I get the following:

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

}

谢谢!

推荐答案

尝试这个(适用于我,我使用它在帐户后自动登录用户激活):

Try this (works for me, i'm using it to auto-login a user after account activation):

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

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

Also $this->Auth->user is not a property. If you want to access it, you have to write $this->Auth->user();.

这篇关于Cakephp手动登录不启动会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆