繁体   English   中英

注册表中的验证码

[英]captcha in registration form

我已经从实用的cakephp书中使用过Ascii Captcha。但是我无法同时验证用户信息和验证码。 下面是我的代码

**In user controller ** 

 function check() {
        if (!empty($this->data['User']['secure'])) {
            if ($this->data['User']['secure'] == $this->Session->read('string')) {
                $this->Session->setFlash(__('You have entered the right characters', true));
            } else {
                $this->Session->setFlash(__('You have entered the wrong characters. Please, try again.', true));
            }
        } else {
            $this->Session->setFlash(__('You need to enter the correct characters. Please, try again.', true));
        }
    }

function register() {

        $captcha = $this->AsciiCaptcha->getCaptcha();

        $string = implode("", array_keys($captcha));
        $this->set(compact('captcha', 'string'));
        $this->Session->write('string', $string);

        if (!empty($this->data)) {
            $this->User->create();
            if ($this->User->save($this->data)) {

                $data = $this->User->read();
                $this->Auth->login($data);
                $aro = new Aro();
                $parent = $aro->findByAlias($this->User->find('count') > 1 ? 'User' : 'Admin');
                $aro->create();
                $aro->save(array(
                    'model' => 'User',
                    'foreign_key' => $this->User->id,
                    'parent_id' => $parent['Aro']['id'],
                    'alias' => 'User::' . $this->User->id
                ));
                $this->Session->setFlash(__('The user has been saved', true));
                $this->Auth->logout();
                $this->redirect('login');
            } else {
                $this->Session->setFlash(__('The user could not be saved. Please, try again.', true));
            }
        }

        $groups = $this->User->Group->find('list');
        $this->set(compact('groups'));
    }

我使用了很多方法来检查用户信息是否正确以及代码是否匹配,但是找不到任何解决方案。 请帮忙。

看起来您应该在方法底部,在$ groups = ...之前/之后使用它。

$captcha = $this->AsciiCaptcha->getCaptcha();
$string = implode("", array_keys($captcha));
$this->set(compact('captcha', 'string'));
$this->Session->write('string', $string);

在验证之前,您已经在会话中写了很多东西,因此它总是错误的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM