簡體   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