我使用的代码验证码: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更新与视图和模型代码的问题。 –
验证码比较代码是否正在运行?在那里放一些调试语句。查看提交的验证码和正在比较的验证码的值。他们的价值观是你期望的吗?如果不是,为什么?按照这些值的路径找到问题的发生地点。这是基本的调试。 –