我正在使用该代码进行验证码:https ://github.com/solutudo/cakephp-captcha
这是我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');
}
}
}
}
}
查看用户.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');
?>
模型用户.php
<?php
class User extends AppModel {
public $actsAs = array(
'Captcha' => array(
'field' => 'captcha',
'error' => 'Captcha code entered invalid'
)
);
}
?>
验证码验证和验证码不起作用,无需输入验证码我就可以登录,我在相同控制器的添加功能中使用了相同的代码user_controller.php
,当时验证码正在工作。
我希望用户在输入正确的验证码后登录。