after many hours of trying and searching to solve an issue with captcha issue and several faild attempts to fix the problem I decide to ask for your help, I have a web site on Joomla 2.5 I have a custom register form for new users and I want to add a captcha mechanism, where here what I made (i found it here in stackoverflow but i have some qusetions).
So far I made the followings:
1)I enabled the capcha-recaptcha plugin and I enter private key and site key from google captcha
2)I set captcha-Recaptcha to Default captcha at global configuration
3)In my file template\mytemplate\html\mod_login\default.php
I enter the following code which I found here in stackoverflow
//php code
JPluginHelper::importPlugin('captcha');
$dispatcher = JDispatcher::getInstance();
$dispatcher->trigger('onInit','dynamic_recaptcha_1');
//html code inside form tag
<div id="dynamic_recaptcha_1"></div>
So far so good it appears the captcha image and entry box but when I press submit button I receive Invalid token
I suspect that it has something to do with the following part of code which it should validate/proccess the form
$post = JRequest::get('post');
JPluginHelper::importPlugin('captcha');
$dispatcher = JDispatcher::getInstance();
$res = $dispatcher->trigger('onCheckAnswer',$post['recaptcha_response_field']);
if(!$res[0]){
die('Invalid Captcha');
}
in joomla in which file I should insert the validation code? I have tried in submit button at : template\mytemplate\html\mod_login\default.php
but nothing, I have tried also at com_users\controllers\registrattion.php still nothing any ideas where I should insert this part of code? in order to make it work?
Thnks in advance for your time!!
Regards,
Jim
EDITED ANSWER
Try this code below from https://forum.joomla.org/viewtopic.php?t=833213
$app = JFactory::getApplication();
$captchaResponse = JRequest::get('recaptcha_response_field');
JPluginHelper::importPlugin('captcha');
$dispatcher = JDispatcher::getInstance();
$res = $dispatcher->trigger('onCheckAnswer',$captchaResponse);
if(!$res[0])
{
// Invalid captcha
$app->redirect(JRoute::_('index.php?option=com_users&view=login', false));
return false;
}
ORIGINAL ANSWER
Make sure you are using newest version of the 2.5 series. The original recaptcha plugin won't work because Google changed their API script location from recaptcha.net to google.com/recaptcha . You can open the recaptcha files to do a quick check.
Related
I've implemented a Max Order Value restriction on my Magento Store from this tutorial: http://inchoo.net/magento/magento-maximum-allowed-order-amount/
The notification uses the following to show the error message:
Mage::getSingleton('checkout/session')->addError(
$this->_helper->__($this->_helper->getSingleOrderTopAmountMsg(), $formattedPrice));
Unfortunately, this is only shown on the next page load since it's Session based.
However, I would like the message as a popup when 'Add to cart' button is clicked. This could be a simple javascript alert or ideally a nicely styled popup.
I've looked into Ajax using:
$response = array();
$response['message'] = 'Your cart exceeds the maximum allowed order value';
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
but I'm not entirely sure how to get the response on the front end via jQuery.
Any help would be appreciate :)
Cheers
I am trying to load a view from my controller using the follow code but I only get a raw HTML view and does not show the site's template.
$view = $this->getView( 'download', 'html' );
$view->display();
Can some help me in what I am doing wrong to display the site's template.
I also tried a redirect but that did not work either
$this->redirect(JRoute::_('index.php?option=com_atdwcsv&view=download'), false);
Edit: I figured out what was wrong with the redirect. Code I needed was
$this->setRedirect('index.php?option=com_atdwcsv&view=download');
$this->redirect();
I could be wrong, but I don't think you need to use the display() method on the view, I think you need to use $this->display(); instead.
Ok i cant figure this out at all. I have searched and i cant find anything either. Whats the best way to add a new page to the account section. I am trying to integrate a support ticket system into a magento account page i.e. so the user must be logged in and registered to use this feature. i can get this to work using a cms page and custom page layout. but then how do i set this custom cms page to only work for logged in users?
Also doing it this way this is showing the category menu and not the account menu. How can i get the my account menu to show instead? or is there a better way of doing this? Im new to magento and im really stuck and cant figure this out so any help would be appreciated.
Im running magento 1.7.0.2 community edition.
If I understand you correctly, just check to see if the customer is logged in, but in order to use PHP you're going to have to use the teplating system and create a module, or generate your own "stand alone page" If you go the module route:
if ($this->helper('customer')->isLoggedIn()){
//show page contents or do whatever ..
}
else{
header( 'Location: http://www.yoursite.com/customer/account/login/' ) ;
}
is all you'll need. IF you go the stand alone route:
//LOAD MAGENTO
require_once 'YOUR_PATH_TO_MAGENTO/app/Mage.php';
umask(0);
Mage::app('YOUR_WEBSITE_CODE', 'website');
//GET SESSION DATA
Mage::getSingleton('core/session', array('name'=>'frontend'));
$session = Mage::getSingleton('customer/session', array('name'=>'frontend'));
$customer_data = Mage::getModel('customer/customer')->$session->id);
//CHECK IF LOGGED IN
if($session->isLoggedIn()){
echo 'Welcome ' . $customer_data->firstname . " " . $customer_data->lastname;
} else {
echo "Access Denied: Sorry, but this page is for registered members only.";
exit;
}
Hope that helps
For any action there is a controller and action function.
So for your new feature you define an action.Make sure this action value is in URL.
Now within your controller add this action function
myAction()
{
if ($this->helper('customer')->isLoggedIn()){
//show page contents or do whatever ..
}
else{
header( 'Location: http://www.yoursite.com/customer/account/login/' ) ;
}
}
Although both of the answers above might have sufficed for the question posted, just for a note, it is surely not the correct way to work with Magento, a better understanding of how this can be achieved in the way according to magento practices, I think this tutorial from Alan Stormis a great place, however there is some problem with the preDispatch method in that blog, for which I think it might be better alternative:
public function preDispatch() {
parent::preDispatch();
if (!Mage::getSingleton('customer/session')->authenticate($this)) {
$this->setFlag('', 'no-dispatch', true);
}
}
Which I got from here.
In Alan's blog, If a customer is already logged in and try to go the custom account page, he is redirected to the homepage(It did in my case.)
I implemented Recaptcha to Silverstripe and it seems to work.
The only problem is that the formular and the captcha code are at the very end of the page and if you type in a wrong code then the page reloads and jumps back to the top so that the user doesn´t see the formular and captcha code anymore.
how can i make the window not to scroll to the top after entering a wrong captcha code?
Since the HTTP spec doesn't allow to a serverside redirection including an anchor tag, you'll need to use JavaScript to accomplish this. Since the field is highlighted with a validation message in the standard SilverStripe form rendering, you can use this to determine the state of the field once the submitted form loads again.
jQuery(document).ready(function() {
var captchaEl = jQuery('#MyCaptcha');
if(captchaEl.find('.message.required').length) {
window.scrollTo(0, captchaEl.scrollTop());
}
});
Is it possible in Joomla to place a certain article in a template, additionally to the normal content? I want the article to show up on every page.
You can simply take it from the databse and print its content. In the template, where you want to show the article, write this:
$id=/*Id of the article to show*/;
$db=&JFactory::getDBO();
$db->setQuery("SELECT * FROM #__content WHERE id=$id");
$item=$db->loadObject();
echo $item->introtext;
UPDATE: ENABLE PLUGINS
I can't find where i've used that code and i can't copy-paste it, so i try to write it again by looking at the view.html.php of the com_content:
JPluginHelper::importPlugin('content');
$dispatcher =& JDispatcher::getInstance();
$params = &$mainframe->getParams();
$dispatcher->trigger('onPrepareContent', array (&$item, &$params, 0));
//The last line triggers the onPrepareContent event, so if it does not work maybe you need other events, so try with onAfterDisplayTitle, onBeforeDisplayContent or onAfterDisplayContent
Have you seen this? http://extensions.joomla.org/extensions/news-display/content-embed/7528
It allows you to place any article as a module on your Joomla site. And with modules you can have them displayed site wide.