Magento creating new customer page - magento

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.)

Related

Roles and permissions issues in laravel project

I am working on a laravel project. I have a side menu that is persistent across all pages. However the menu items to be shown is dependent on the role assigned to the user. I achieved that by doing this:
<?php
/**$links = Session::get('links'); **/
use Illuminate\Support\Facades\DB;
$id_hr_employee= Auth::user()->id_hr_employee;
$links = DB::select("select a.link as links from sys_menu_links as a a.id_hr_employee = $id_hr_employee)
");
?>
#if(isset($links))
#foreach($links as $link)
<li><hr class="light-grey-hr mb-10"/></li>
#include("$link->links")
#endforeach
#endif
This works quite alright. However, if someone enters a route to a menu (that he is not assigned to) on the address bar, he sees that page.
Please how do I prevent this?
i would highly recommend you using laratrust: https://laratrust.readthedocs.io/en/4.0/.
And to secure your sides: 1.option work with middelware to Block your admin views 2. Option Check for permission in the Controller files.
As a guidance you could look up this tutorial: http://itsolutionstuff.com/post/laravel-52-user-acl-roles-and-permissions-with-middleware-using-entrust-from-scratch-tutorialexample.html
greetings

Captcha Custom Form in Joomla 2.5

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.

Magento Geolocalization/FPC

In Magento EE I need to redirect customers depending Origin country, browser lang and previous preference set in a cookie.
I have huge problems making it work with FPC.
I tryed to observe the controller_action_predispatch event, but FPC somehow caches my redirect instruction and customer is not redirected.
I then tried another solution: extending the run() method in Mage_Core_Model_App in order to perform operations before FPC starts to work.
Unfortunately, I don't know why, inside this method you can't access Mage::getModel(), Mage::helper(), Mage::getConfig() ecc
Can you help me please?
Thank you
I've recently been through exactly the same pain. You are on the right track;
controller_action_predispatch
Is the correct event to observe, and you can use this quite happily if you are redirecting to a category or product page with FPC enabled. The problem is the home page - which is a cms page. The cms page cache does not fire controller_action_predispatch. I got around this by adding this to my observer;
public function switchUser($event)
{
// CMS page bug, disable FPC to still use observer
$action = $event->getEvent()->getControllerAction();
if($action instanceof Mage_Cms_IndexController) {
$cache = Mage::app()->getCacheInstance();
$cache->banUse('full_page');
}
// do the rest of your code here
}
The blocks within the cms page will still cache so the page is still nippy, though obviously not as fast as it would be with full FPC enabled. Its a sound trade off in my opinion.

Using Magento Observers to display a popup of the last item added to the cart

I am trying to use observers in Magento 1.7.0.2 to catch when a product is added to cart.
After that event has happened (I believe it is the event checkout_cart_add_product_complete) I would like to show a popup that gives an overview of the product that the customer has just bought, as it would be seen in an item line in the cart.
I have tried to build a module that would catch this event, but I can't find a way to test if I have the same event, what models I need to use or pretty much anything.
So far, I have this written
public function checkoutCartAddProductComplete (Varien_Event_Observer $observer)
{
$product = $observer->getEvent()->getProduct();
$session = Mage::getSingleton("checkout/session")->addSuccess($message);
$message = $this->__('Changed! You added %s to your shopping cart.', Mage::helper('core')->escapeHtml($product->getName()));
$session->addSuccess($message);
}
However I took that code from the Internet, and it doesn't seem to be working.
There is something in \app\code\core\Mage\Checkout\controllers\CartController.php (around line 205) that shows the eventDispatcher and then the code that displays a message - however I'm not sure how to actually transplant this to a module, short of copying the whole file and overwriting it.
I'm trying to do this as a module so I can take it across various projects, but it is turning out to be a project on it's own...
You $session variable is set like:
$session = Mage::getSingleton("checkout/session")->addSuccess($message);
But at the same time you $message is not yet set.
So when after you set your message and are trying to save you message you are actually doing.
Mage::getSingleton("checkout/session")->addSuccess($message)->addSuccess($message);
Remove ->addSuccess($message); from your session variable and you should be fine.

How to display error messages in CodeIgniter

In my controller I put this code to check if the shopping cart is empty:
if (!$this->cart->contents()){
$this->session->set_flashdata('message', 'Your cart is empty!');
}
$this->data['message'] = $this->session->flashdata('message');
$this->load->view('templates/header', $this->data);
$this->load->view('bookings', $this->data);
$this->load->view('templates/footer');
On my "bookings" view I set this code to display the message:
<div id="infoMessage"><?php echo $message;?></div>
But on the first page load the message "Your cart is empty!" is not showing. However, it will display when I press the F5 key or refresh the browser.
I have already read the manual from codeigniter that says "CodeIgniter supports "flashdata", or session data that will only be available for the next server request, and are then automatically cleared."
However, I don't know where to set this message so it will be available on "next server requrest".
There is no need to pass the data to the view and assign it as flashdata.
The reason that it's not working the first time, is that flashdata is only available for the next server request. Loading the views isn't a server request. However, refreshing the page is.
There are a couple of solutions to this:
Pass the data directly and load the view. (Not using flash data.)
Use flashdata and redirect to the page.
Passing the data directly
You could just pass it directly (personally I'd go with this option - I'm not sure why you'd want to use flashdata in this case, I would've thought that you'd always like to inform the user if their cart is empty...):
Controller:
if (!$this->cart->contents())
{
$this->data['message'] = 'Your cart is empty!';
}
$this->load->view('templates/header', $this->data);
$this->load->view('bookings', $this->data);
$this->load->view('templates/footer');
View:
<div id="infoMessage"><?php echo $message;?></div>
Using flashdata
Or, if you want to use flashdata, then:
Controller:
if (!$this->cart->contents())
{
$this->session->set_flashdata('message', 'Your cart is empty!');
}
redirect('/your_page');
View:
<div id="infoMessage"><?php echo $this->session->flashdata('message');?></div>
If you want to use this method, you can't simply just load the view - due to the server request issue that I explained above - you have to redirect the user, using redirect('/your_page');, and the URL Helper $this->load->helper('url');. You can also send the appropriate HTTP header using the native PHP header function. Loading the view the first time won't work.
You can use this $this->session->keep_flashdata('message'); to preserve the data for an additional request.
I'd also check that your either auto-loading the session library or loading it in the constructor of your controller: $this->load->library('session'); (I'm fairly sure you will be, but it's worth checking anyway.)
Finally, I know that some people who store session data in their database can have issues with flashdata, so that may be worth looking into, if none of the above helps.
On a side note, personally I'd have a check to ensure that a variable is set before echoing it.

Resources