我使用的代碼驗證碼:https://github.com/solutudo/cakephp-captcha圖形驗證碼不是在登錄表單工作在CakePHP
這是我的代碼user_controller.php
在登錄操作:
public function login() {
if (!empty($this->data)
&& !empty($this->Auth->data['User']['username'])
&& !empty($this->Auth->data['User']['password'])) {
// captcha code
if ($this->RequestHandler->isPost()) {
$this->User->setCaptcha($this->Captcha->getCode());
$this->User->set($this->data);
if ($this->User->validates()) {
// captcha code
$user = $this->User->find('first', array(
'conditions' => array(
'User.email' => $this->Auth->data['User']['username'],
'User.password' => $this->Auth->data['User']['password']),
'recursive' => -1
));
if (!empty($user) && $this->Auth->login($user)) {
if ($this->Auth->autoRedirect) {
$this->redirect($this->Auth->redirect());
}
} else {
$this->Session->setFlash($this->Auth->loginError, $this->Auth->flashElement, array(), 'auth');
}
}
}
}
}
查看user.ctp
<?php
echo $this->Form->create(array('action'=>'login'));
echo $this->Form->input('username');
echo $this->Form->input('password');
// captcha code
echo $this->Html->image('captcha.jpg', array('style' => 'padding: 0.5%;'));
echo $this->Form->input('captcha');
// captcha code
echo $this->Form->end('Login');
?>
型號user.php的
<?php
class User extends AppModel {
public $actsAs = array(
'Captcha' => array(
'field' => 'captcha',
'error' => 'Captcha code entered invalid'
)
);
}
?>
驗證碼驗證和驗證碼不工作,沒有輸入驗證碼我能夠登錄,我已經使用相同的代碼添加功能與相同的控制器user_controller.php
,並且時間captcha代碼工作。
我希望用戶在輸入正確的驗證碼後登錄。
隨着調試,你看到任何錯誤?你有附件嗎?模型上的驗證字段?你認爲如何產生它?我們需要更多信息來幫助你。 – jeremyharris
不,我沒有發現調試模式的任何錯誤,是的,我已附加captcha component.i更新與視圖和模型代碼的問題。 –
驗證碼比較代碼是否正在運行?在那裏放一些調試語句。查看提交的驗證碼和正在比較的驗證碼的值。他們的價值觀是你期望的嗎?如果不是,爲什麼?按照這些值的路徑找到問題的發生地點。這是基本的調試。 –