How to Call Captcha Action in Yii Framework to create image - yii

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,
),
);
}

Related

Yii - Route without Controller

I'm using an existing upload script that require user authentication. However since I did not write the upload script, it's nearly impossible for me to read the source code and make it into separate view and controller file. The problem is if the script does not get routed by the bootstrap file, it has no access to the Yii variable and thus user log in information.
I tried to set a custom session variable when the user login. However it work barely because my custom session would expire before the session set by Yii.
Any help would be appreciated.
Because of the way the script is written I've only been able to find one way of doing this. It will involve re-writing some elements of the script.
Save the filemanager in protected/vendors.
You need a controller to handle the routing of the request. This will also give you the access control that you need. Call it FileUpload and create it where you normally create controllers in your project. Right at the start of the controller, before the class is declared, import the fileUpload files from it's previously saved location; Yii::import('application.vendors.*');
You need an action to handle the incoming request. Call this actionIndex. Give it the following code.
public function actionIndex() {
//Start capturing the output from the script
ob_start();
require_once('filemanager/dialog.php');
//Finish capturing output, and save to a variable
$output = ob_end_clean();
$this->render('index', array('output' => $output));
}
Then you need a view file. Call it 'output.php' and it just contains one line; <?php echo $output; ?>
This will render the html generated by the script, and hopefully contain it within your existing template.
Your first problem is that the script sends headers which aren't discarded by ob_start. You will need to delete these from the script. It also starts a session, which will throw an error 'Session already started', which can be cured by changing the first line of config.php to
if(!isset($_SESSION))
{
session_start();
}
Your next problem will be that none of the scripts and stylesheets are loaded, because the vendor hasn't used relative filepaths, and also because you've just deleted the headers. You will need to re-write lots of the script to include the necessary files. Fortunately, you now have access to Yii functions, so can use the asset manager to publish all the js and css files needed by the script.
Your final (hopefully!) problem will be the urls used by the script page. Currently they are all pointing to files within the script. You will need to rewrite these to use Yii routing. Fortunately, inside the main file dialog.php you should have access to all the normal Yii functions, so you can set $baseUrl as $this->createUrl() etc. If you need to add extra actions to the controller you can follow the pattern above to call other files, like the upload.php file in the script.
Hope that all works for you!
You are using a Framework with mvc pattern so controllers are preferred way to route requests .As per your problem i would suggest you to use htaccess file to do the routing to the required file and handle other files by Yii
copy code from existing source to new Yii Controler/Action ... done :D

Yii Captcha don't refresh image on refresh button clicked

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.

Is there a way of adding a quick link on the administration page to a module's configuration?

Is it possible to add a link on the top menubar of the Administration page (Catalog, Orders, Customers...) going straight to a module's configuration page? I've inherited a large module with a ton of messy code that I'd really like to leave be, if at all possible.
The only requirement is that its configuration has to be accessible from that menu bar in particular (or, if there's no other possible option, from the quick links section; this one in particular can easily be achieved, except for the token part).
EDIT: I managed to pull it off by creating an Admin controller, but I am having issues generating the correct access token. I do not really know what to do to fix it and, as such, I am hereby launching (yet another) bounty.
Here's the code I am using for the redirect:
<?php
class AdminMultiBlockController extends AdminController
{
public function __construct()
{
global $cookie;
// this doesn't really work
$tab = 'adminmodules';
$token = Tools::getAdminToken($tab.(int)(Tab::getIdFromClassName($tab)).(int)($cookie->id_employee));
Tools::redirectAdmin('index.php?controller=adminmodules&configure=egr_MultiBlockSlider&token=' . $token);
}
}
My workaround was to force a working token, but this won't do.
What am I doing wrong? What parameters should I put inside the getAdminToken() function in order to successfully access a module's configuration?
I am currently using Prestashop v1.5.1.
Cheers guys!
Not being able to reproduce the problem, I can only guess.
However, try with the following code:
$url = 'index.php?controller=AdminModules&configure=egr_MultiBlockSlider';
$url .= '&token='.Tools::getAdminTokenLite('AdminModules');
Tools::redirectAdmin($url);

Invoke action in Yii

This is my scenario. A home page with a upload form, user upload the images and submit, then the controller will catch the data from user, add it in the Model. Finally the image info will display in the another page.
I put the actionIndex() in the siteController to render the home page, the actionUpload() in the same file to handle the data user. So in the view, what should I put in the form action to invoke the actionUpload(). I think the flow is quite weird in Yii when I read the blog demo code, I just follow same way with the ASP.NET MVC. Suggest me the right way, plz. Thanks
Depends on how you build your form. If using CHtml, do the following:
<?= CHtml::beginForm($this->createUrl('site/upload'))?>
If you have a model that sits behind it:
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'login-form',
'action' => $this->createUrl('site/upload'),
)); ?>
Please check the Yii documentation and examples on how to properly set up forms. You have several choices here.

how to make custom CListlView widget in yii

I am developing my web application in the Yii framework . I do not have enough experience in the Yii framework. I want to make the view for the index post page. The Yii provide the CListView for this, but I want to make some customization on that.
You can extend a widget with the following steps:
Copy CListView.php from /(yii root)/framework/zii/widgets to /(application root)/protected/widgets
Rename the file BineshListView.php
Open BineshListView.php. Add this before the class declaration
Yii::import("zii.widgets.CListView");
Change the first line of the class declaration to:
class BineshListView extends CListView { ...
Now, you have your own BineshListView class you can customize. To use it in a view, you can call it like you would CListView
$this->widget('application.widgets.BineshListView', array( 'data'=>$model, etc... ) );
Let me add that BineshListView will inherit all the properties and methods of CListView. Therefore, if you do not need to customize a property or method and want to use the original behavior of CListView, you can delete the property or method from BineshListView.
you no need to customize the ClistView . just simply make changes in the partial view file . which is called by the ClistView.
<?php
$this->widget('zii.widgets.ClistView',arrray(
'dataprovider'=>$your-data-provider,
'view-file'=>'custom-view-file'
));
?>
make changes in custom-view-file.
make sure the custom-view-file in same views folder for the controller.