2009-09-24 140 views
3

我对不同的用户使用注册表单吗?新用户登录后,注册用户应该重定向到登录后页面。我们使用Auth组件进行身份验证。在CakePHP中自动登录

我该怎么做?

回答

0

我不确定问题是什么,但它听起来像是想知道如何在成功登录后在某处发送用户。如果这是正确的,试试这个:如果你没有访问/admin/whichever_controller/desired_action

$this->Auth->loginAction = array (
    'controller' => 'whichever_controller', 
    'action'  => 'desired_action', 
    'admin'  => true 
); 

管理键可能没有必要。

0

您必须从注册操作中手动调用登录方法。

保存在一个阵列的用户名+非散列密码,然后后保存这样的方法调用它:

$data = array('username' => 'user', 'password' => $unhashedPw); 
$this->User->login($data); 
6

如果你想注册后用户可以自动登录,您可以使用AuthComponent的登录() 方法。

if ($this->User->save($this->data)) { 
    $this->Auth->login($this->data); 
} 
+0

如果您打算使用非内置密码功能,Auth dosen't的登录功能会自动手动调用hashPassword函数。 – coolkid 2011-07-09 08:45:47

3

在较新的蛋糕,你只需要添加

$this->Auth->login(); 

添加用户到数据库后。