Yii Framework Forum

Captcha Conflict with accessControl in Controller in Yii1.1


(Urajesh647) #1

Hi ,
Firstly when I use the accessControl filter in my controller ,captcha in login page is not displaying and here goes my code in controller

public function actions()
	{
		return array(
				// captcha action renders the CAPTCHA image displayed on the contact page
				'captcha'=>array(
						'class'=>'CCaptchaAction',
						'backColor'=>0xF8F8F8,
						'foreColor'=>0x000000,
				),
				// page action renders "static" pages stored under 'protected/views/site/pages'
				// They can be accessed via: index.php?r=site/page&view=FileName
				'page'=>array(
						'class'=>'CViewAction',
				),
		);
	}
	public function filters()
	{
		return array(
			'accessControl', // perform access control for CRUD operations
			//	'postOnly + delete', // we only allow deletion via POST request
			
		);
		
	}
    public function accessRules()
    	{
    		return array(
    				array('allow',  // allow all users to perform 'index' and 'view' actions
    						'actions'=>array('actions'),
    						'users'=>array('*'),
    				),
array('allow',  // allow all users to perform 'index' and 'view' actions
						'actions'=>array('index','captcha',),
	'users'=>array('*'),
)
)

              }

here is my code in view
$this->widget('CCaptcha', array( 'showRefreshButton'=>true,'buttonOptions'=>array('id'=>'refreshCaptcha','title'=>'Get a new code') ));

Where did I make mistake.Please suggest me the right way to sort out this issue of conflicting captcha with accessControl . Thanks in advance


#2

If you enable accessControl filter you have to also define accessRules() to enable access for the captcha.

See


(Urajesh647) #3

Thank you sir for reply .
And As shown in question ,I have defined the rules to access the captcha but nothing works out well.


#4

Sorry, I missed that part in your code.

Your first access rule does not make sense, there is no action named “actions”.

You also did not list the login action in accessRules() is it in another controller?

Your captcha widget might be missing the URL to the correct action if that is the case.

https://www.yiiframework.com/doc/api/1.1/CCaptcha#captchaAction-detail


(Urajesh647) #5

Hi Sir, Thank you for reply
For me it is login screen is in view index.php
and the captcha I have pasted is from the index.php
and still nothing works out well
should I need to add the url for the Captcha ?
I have tried that too and still the issue exists
what should I do sir?


(Urajesh647) #6

Hi ,
For me login screen is in view index.php
and the I have pasted captcha from the index.php
and still nothing works out well.
I have observed that while loading the page with captcha and the accesscontrole, several javascript files from assets are loading may be this is the issue of conflict of captcha and accesscontrol .
if it is the problem, what should we do to over come this issue?
should I need to add the url for the Captcha ?
I have tried that too and still the issue exists
what should we do sir?
Please suggest me the right way to sort out this issue

Thanks & Regards,
Rajesh