2

私のキャプチャは変更されていません。ボタンをクリックしない限り、常に同じ単語が表示されReload Captchaます。なぜtestLimit正しく動作しないのですか?

Controller.php

public $attempts = 5; // allowed 5 attempts
public $counter;

public function actions()
{
    return array(
        'captcha'=>array(
        'class'=>'CCaptchaAction',
        'backColor'=>0xf5f5f5,
        'testLimit'=>1,
    );
}

private function captchaRequired()
{           
    return Yii::app()->session->itemAt('captchaRequired') >= $this->attempts;
}

public function actionLogin()
{
    if (!Yii::app()->user->isGuest) $this->redirect(array('users/update'));

    $model = $this->captchaRequired()? new LoginForm('captchaRequired') : new LoginForm;

    // collect user input data
    if(isset($_POST['LoginForm']))
    {
        $model->attributes=$_POST['LoginForm'];
        // validate user input and redirect to the previous page if valid
        if($model->validate() && $model->login()) {
            $this->redirect(array('users/update'));
        } else {
            $this->counter = Yii::app()->session->itemAt('captchaRequired') + 1;
            Yii::app()->session->add('captchaRequired',$this->counter);
        }
    }
    // display the login form
    $this->render('login',array('model'=>$model));
}

View.php

<?php if($model->scenario == 'captchaRequired'): ?>
    <br>
    <legend><?php echo CHtml::activeLabelEx($model,'verifyCode'); ?></legend>
    <div class="control-group">
        <div class="controls">
            <?php $this->widget('CCaptcha'); ?>
            <?php echo CHtml::activeTextField($model,'verifyCode'); ?>
        </div>
    </div>
<?php endif; ?>
4

2 に答える 2

3

testLimit生成されたハッシュが変更される前にユーザーが試行できるキャプチャ送信の量です。タイプミスを避けるために使用します。

セッションでコード ストアを確認する ( http://www.yiiframework.com/doc/api/1.1/CCaptchaAction#getVerifyCode-detail )。したがって、デフォルト コードは次の 2 つの方法のいずれかでのみ変更できますtestLimit。またはユーザーによる手動更新。

したがって、CCaptchaAction クラスを拡張して、目的を達成することができます。fg は、$regenerate変数を強制的に true に設定します。

于 2014-01-13T23:52:39.613 に答える
0

簡単な解決策です。JScript を使用します。このスクリプトは、画像キャプチャをリロードします。

$(document).ready(function () {
setTimeout(function () {
    $("img#reviews-verifycode-image").click();
}, 100);
});
于 2017-01-06T15:17:37.693 に答える