Yii Captcha don't refresh image on refresh button clicked - yii

I don't know why my Captcha image do not refresh when i click on refresh link.
My code is :
<?php $this->widget('CCaptcha'); ?>
<?php echo $form->textField($model,'verifyCode'); ?>
I saw XHR response , it was empty and i checked the link of the refresh link , some thing like tis :
mydomain/captcha?refresh=1&_=1367673730496
and it return an image but it should return somthing like
{"hash1":311,"hash2":311,"url":"/mydomain/captcha?v=518509b295d06"}
I saw above link in the other application of mine which works fine with CCaptch.
On page refresh , Captcha image changes.
The corrupted captcha sent one XHR , the refresh one but the fine Captcha should send two as i saw in the other application,one for refresh and other for getting image.
What should i do ?
Edit:
I found another fact :
functional Captcha works with jquery.min but corrupted one works with jquery !! but i don't add anything to header , they added by Yii.
Second Edition:
I found two files which handle captcha in yii framework and i see when i send this request :
mydonmain/controller/captcha?refresh=1
And get
print_r($_GET);
die();
it return :
Array ( [/controller/captcha] => )
which means it don't understand get->refresh request !! somehow the $_GET request is disabled !!

Did you checked Yii main.php which contain urlManager section ? the rules are sequential.

Related

Yii captcha never passes the validation even if, right letters are in place

This is on my model rules:
array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),
This is on my _form:
$this->widget('CCaptcha', array('buttonOptions' => array('class' => 'captcha-anchor')));
On my accessRules:
array('allow','actions'=>array('create','index','view','member', 'captcha'),
'users'=>array('*'),
),
I keep getting,
"The verification code is incorrect"
no matter what I do.
I'm using AjaxValidation with CActiveForm, and wish to keep using it.
Any clue how to fix this?
Please don't post any link, if you happen to know the answer, please describe it, so we can discuss if in need.
Please note that the captcha image is displaying and reloading. No issues there.
Thanks.
I have same problem and it return false every time because :
1- I define Get POST in some base controller and i send a ajax request to home controller which extended from base , because i can not call base controller directly so i change ajax request to current controller not home controller for all pages.
2- I hard coded JQuery in my layout so Yii load two JQuery in the Page so it send 2 request , first verified and second fails, i disabled JQuery auto load helping by this link.

How to Call Captcha Action in Yii Framework to create image

I have app in Yii framework and i want to add Captcha in it and i don't want use Yii defaults .. long story short , i found one which works fine without framework so i created an action and i put image creation function in it, but when i call that action i get broken link.
yii/mycontroller/createcaptchaimage
What is wrong in my solution ?
the captha code is in this link .
There is nothing wrong in your solution. You Obviously have some Routing issue . Did you checked your main.php or .htaccess ?
I found this captcha-extended extension more beautiful than CCapthcha. Here is the link:
http://www.yiiframework.com/extension/captcha-extended/
You call it just like normal CCaptcha widget from any view/layout file:
<?php $this->widget('CCaptcha'); ?>
This will look for controller action "captcha" which is defined in array of actions.
public function actions(){
return array(
'captcha'=>array(
'class'=>'CaptchaExtendedAction',
// if needed, modify settings
'mode'=>CaptchaExtendedAction::MODE_MATH,
),
);
}

Yii - how to preload a widget

I am working with Yii Jui widgets to have JuiTabs in a website. The problem is when the site is loading I first see the list (without any css) and then after the page loads the tabs show as they should. I wonder if there is a way to preload JuiTabs somehow so they show correctly when the page is loading.
Here is my code:
<?php
$this->widget('zii.widgets.jui.CJuiTabs', array(
'tabs'=>array(
'PRESENTAZIONE'=>array('content'=>$this->renderPartial('spettacoli/_view_presentazione', array('model'=>$model),$this)),
...
),
'options'=>array(
'collapsible'=>false,
),
));
?>
And here is the example of the page. The problem is visible when the internet connection is slow, and it takes time until the page loads
Not sure that's possible to preload JuiTabs somehow, but you can add display: none for CJuiTabs by default and show that with JS on page load. Not the best way, but first idea came into my mind.

Yii CAPTCHA url is broken

I want to create an AJAX-registration form on my Yii-project. So on every page I have a login-button, which shows a popup if the user isn't authorized. In that popup he can see registration form with email field, password field, and CAPTCHA (default Yii captcha).
So, my model for user's registration is User. There is a validation rule:
array('code', 'captcha', 'allowEmpty'=>!Yii::app()->user->isGuest),
My controller, where all user's actions are, is User (url: site.url/user/) and I added there captcha action:
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xFFFFFF,
'foreColor'=>0x000000,
),
In my next code:
$this->widget('CCaptcha', array(
'clickableImage' => true,
'showRefreshButton' => false,
))
And here is a problem:( Being inside a popup, which can be shown on every page (index page, for example, which belongs Main controller) captcha wants to load an image from that controller (from /main/captcha, not /user/captcha).
Adding captcha in every controller is bad idea, so I added
'captchaAction' => '/user/captcha',
But after that captcha wants to load from an url
http://site.loc/user/captcha/v/4fe99aca1bbed
User-friendly url's crashed captcha and I can't avoid it (as I think, not being a yii-expert, it's because of common path-config).
Is there an easy solution to solve this? Should I repair URL's or re-configure CAPTCHA?
So, while I was waiting for help, I solved the problem by myself :)
In my project i separated my controllers into the next hierarchy:
/frontend
/backend
All controllers for common users are (of course) in Frontend section, including UserController and MainController.
Yes, I wrote some configs to hide /frontend/ in URL's like this:
'<c:\w+>/<a:\w+>' => 'frontend/<c>/<a>',
And i was sure, that string in my CAPTCHA config ('captchaAction' => '/user/captcha') knows where to go (and it was almost so!), but NO!
I should write FULL PATH to my controller and action like below:
'captchaAction' => '/frontend/main/captcha',
As I said in question, I placed my CAPTCHA action in UserController, but now you can see it is located in MainController (i deleted it from UserController)
And I got an error:
CCaptchaValidator.action "captcha" is invalid. Unable to find such an action in the current controller.
So, to solve this, I just had to use a property captchaAction of CCaptchaValidator in my User MODEL! Code:
array('code', 'captcha', 'captchaAction'=>'/frontend/main/captcha', 'allowEmpty'=>!Yii::app()->user->isGuest)
So, now my AJAX Captcha validation works correctly where I want.
Good luck with Yii's default CAPTCHA, dear community!

Redirect After Registration in Drupal

Any one know how to go back to the "last page" after a user is presented the login screen and chooses to create a new account?
Basically the sequence is this:
User tries to get to protected content
Redirected to login page
If he logs in he is redirected to original page
If he chooses "create new account" and fills it out, he is redirected to the home page
How do we get him automatically redirected to the original page (not a static page).
There are several ways to go about this. The most straight-forward is to have a login link somewhere in the navigation that appends the destination to the url. The code for this is something like:
<?php
if (user_is_anonymous()) {
$link = l(t('Login'), 'user/login', array('query' => drupal_get_destination()));
}
?>
You can also set a custom access denied page at admin/settings/error-reporting that could either go to a callback that outputs the above code, or to a simple php node that outputs that code.
Additionally, the user login block provided with Drupal core uses the same method to redirect a successful login back to the originating page.
Edit: Note that the above methods will rarely work for registration, because there are more steps involved there. Specifically, when a user needs to verify an email address, passing the originating destination along via the email would involve modifying the core user registration process.
It will potentially still work on a site configured to not verify email addresses. The idea then would be to provide 2 links: 1 for login and the other for registration, both passing along destination information.
LoginToboggan may also be worth pursuing, although it doesn't yet offer the exact registration feature you're looking for.
straight php would be to include a header of this form:
<?php header("Location: " . $_SERVER['HTTP_REFERER']); ?>
for more information refer to the php manual
EDIT:
you can also include a hidden field in your form and set it to
$url = $_SERVER['PHP_SELF']; // or HTTP_REFERER depending on the setup
include the header code snipped to your registration form.