我试图在拨打Auth.
时使用我的Account
模型而不是标准用户。Auth基于电子邮件和令牌的登录。CakePHP 2.5.7 - 使用非标准用户登录时验证失败
当被添加的帐户,他们正在经历的BlowfishPasswordHasher.
我只是无法在它失败什么点登录时进行身份验证确定。
至于我可以看到我”已经参考Auth
以使用Account
而不是User
,并且在任何相关的地方使用电子邮件/令牌而不是用户名/密码。
有没有什么明显的突出或额外的调试线,我可以尝试?
帐户型号
App::uses('AppModel', 'Model');
App::uses('BlowfishPasswordHasher', 'Controller/Component/Auth');
class Account extends AppModel {
...
public function beforeSave($options = array()) {
if (isset($this->data['Account']['token'])) {
$passwordHasher = new BlowfishPasswordHasher();
$this->data['Account']['token'] = $passwordHasher->hash(
$this->data['Account']['token']
);
}
return true;
}
}
账户控制器
App::uses('AppController', 'Controller');
class AccountsController extends AppController {
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('add');
}
public function login() {
$this->layout = 'nosidemenu';
#debug($_SESSION);
if ($this->request->is('post')) {
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirectUrl());
}
$this->Flash->error(__('Invalid username or password, try again debug($this->Auth->login())'));
}
}
}
Login.ctp
<?php echo $this->Flash->render('auth'); ?>
<?php echo $this->Form->create('Account', array('action' => 'login')); ?>
<?php echo $this->Form->input('email', array('class' => 'form-control', 'type' => 'text', 'placeholder' => 'Email')); ?>
<?php echo $this->Form->input('token', array('class' => 'form-control', 'type' => 'password', 'placeholder' => 'Password')); ?>
<?php echo $this->Form->submit('Submit', array('class' => 'btn btn-primary btn-block btn-flat'));
echo $this->Form->end(); ?>
AppController的
App::uses('Controller', 'Controller');
class AppController extends Controller {
public $components = array(
'Session',
'Flash',
'Auth' => array('authenticate' => array('Form' => array(
'userModel' => 'Account',
'passwordHasher' => 'Blowfish',
'fields' => array(
'username' => 'email',
'password' => 'token'
)
)
),
'loginRedirect' => array(
'controller' => 'accounts',
'action' => 'index'
),
'loginAction' => array(
'controller' => 'accounts',
'action' => 'login'
),
'logoutRedirect' => array(
'controller' => 'pages',
'action' => 'index',
'home'
),
'authError' => 'You don\'t have access here.',
),
);
public function beforeFilter() {
$this->Auth->allow('index', 'view');
$this->Auth->authError = sprintf(__('You are not authorized to access that location %s/%s .',true),$this->name,$this->action);
}
}
此外,我在我的登录功能,以下调试线:
编辑:
所以我一直在玩一些调试线,我添加debug($this->data);
在我的AppController beforeFilter()和AccountController login()中。
array(
'Account' => array(
'email' => '[email protected]',
'token' => 'password'
)
)
不应在登录调试消息()报告的哈希令牌: 两个该调试行报告同一阵列的实例?即使使用哈希密码将帐户添加到数据库中,当通过登录进行呼叫时,它们是否可能不会被哈希?
以这种方式提出你的问题,如果有的话,不会给你很多帮助。请参阅此帮助指南,了解如何提出正确类型的问题http://stackoverflow.com/help/how-to-ask – Relequestual
我的问题不是正确的问题类型?我已经看到类似的要求,所以我想我会提供我迄今为止已经得到的一个转储,然后才有人结束了要求。在发布代码之前,我已经提供了与此错误相关的所有相关代码,并给出了一些背景知识。看看这个清单,我没有看到我发布的内容有很大的不同 - 这个评论是模糊的。 – user2936644
现在你已经编辑了你的问题,这是可以的。以前它不是。 =] – Relequestual