0

I am working in Yii and I am just a beginner and trying my best to learn the framework and here is where I am stuck at :

I have created a user model and the required forms that go with it, and I am trying to implement the Captcha for it :

This is my validation rules in the user model :

$public verifyCode

public function rules()
    {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('username, password, email', 'required'),
            array('username','unique'),
            array('email','email'),
            array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),
            array('username, password', 'length', 'max'=>45),
            array('email', 'length', 'max'=>100),
            array('active', 'length', 'max'=>1),
            array('created_on, updated_on', 'safe'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, username, password, email, created_on, updated_on, active', 'safe', 'on'=>'search'),
        );
    }

And this is my overriden action() in my userController :

public function actions(){
        return array(
        'captcha'=>array(
            'class' => 'CCaptchaAction',
            )
            );
    }

And this is my view file :

<?php if(CCaptcha::checkRequirements()): ?>
    <div class="row">
        <?php echo $form->labelEx($model,'verifyCode'); ?>
        <div>
        <?php $this->widget('CCaptcha'); ?>
        <?php echo $form->textField($model,'verifyCode'); ?>
        </div>
        <div class="hint">Please enter the letters as they are shown in the image above.
        <br/>Letters are not case-sensitive.</div>
        <?php echo $form->error($model,'verifyCode'); ?>
    </div>
    <?php endif; ?>

According to me, I think that I am doing everything correctly however, the captcha image is not getting generated. Oh and yes the GD library is installed and if I navigate to the site/contact, there the captcha is generated fine.

I dont seem to understand, where am i getting it wrong.

This is the thing that I see :

enter image description here

The forms seems to be working fine however, I cant see the the captcha image.

Any help would be appreciated.

Regards,

tereško
  • 58,060
  • 25
  • 98
  • 150
Sankalp Singha
  • 4,461
  • 5
  • 39
  • 58
  • 2
    There is probably access rights to `CCaptchaAction` issue. Have you looked at [this solution](http://stackoverflow.com/a/11971926/506695)? – ezze May 18 '13 at 19:30
  • Also check if you have `gd` library in php. Try to get image directly, and see if you have any error, download image to your pc and check it's contents, there could be some hint too. –  May 19 '13 at 11:46
  • gd is ok, because `CCapcha::checkRequirements()` returns true – rzelek May 19 '13 at 12:55
  • I got the answer, it is because I had not modified my controller code. – Sankalp Singha May 19 '13 at 18:57
  • after modifying my controller accessRules but the captcha image not displaying – Kailas Dec 23 '13 at 04:06

1 Answers1

1

I got the answer, it is because of the access rules that are defined in the controller, I had to modify the controller accessControl like so :

public function accessRules()
    {
        return array(
            array('allow',  // allow all users to perform 'index' and 'view' actions
                'actions'=>array('index','view','captcha'),
                'users'=>array('*'),
            ),
            array('allow', // allow authenticated user to perform every action
                'actions'=>array('create','update','admin','delete'),
                'users'=>array('@'),
            ),

            array('deny',  // deny all users
                'users'=>array('*'),
            ),
        );
    }
Sankalp Singha
  • 4,461
  • 5
  • 39
  • 58