magento custom redirect after registration - magento

i'm trying since few day to change the redirection when a"customers" complete is registration on my magento website. Actually, when the registration is complete you are redirect to your account. And i just want to redirect to the index.php ( the homepage of my website). I'm a newbie and i just want to change few lines on code. I'll not able to creat event for exemple.
Can someone help me ?
I think the page is AccountController.php and code :
protected function _welcomeCustomer(Mage_Customer_Model_Customer $customer, $isJustConfirmed = false)
{
$this->_getSession()->addSuccess(
$this->__('Thank you for registering with %s.', Mage::app()->getStore()->getFrontendName())
);
$customer->sendNewAccountEmail(
$isJustConfirmed ? 'confirmed' : 'registered',
'',
Mage::app()->getStore()->getId()
);
$successUrl = Mage::getUrl('/*/*/index', array('_secure'=>true));
if ($this->_getSession()->getBeforeAuthUrl()) {
$successUrl = $this->_getSession()->getBeforeAuthUrl(false);
}
return $successUrl;
}
I've tried to change this line :
$successUrl = Mage::getUrl('/*/*/index', array('_secure'=>true));
to
$successUrl = Mage::getUrl('index.php', array('_secure'=>true));
but nothing happens...

The Mage::getUrl() method is designed around the $module/$controller/$action of Magento routes. If you just want to redirect to the homepage, you could use:
$successUrl = Mage::getBaseUrl();

Redirection after logged In, Logged Out and Registration is very common issue in magento. Please find the code below, it can help you.
public function customerRegistration(Varien_Event_Observer $observer)
{
$_session = Mage::getSingleton('customer/session');
$_session->setBeforeAuthUrl(CustomUrl);
}
Customurl is a url on which you want to redirect after registraion.
If you want complete solution for custom url redirection for your ecommerce website after logged In, Logged Out and Registration. Custom Redirection extension can help you. Click on link to get extension. http://www.magentocommerce.com/magento-connect/custom-redirection.html

Related

How to logout from site?

How to logout from all pages of view, when I click on logout link I just from only one page when I am trying to logout from another page its not work.
My controller code is:
public function do_login()
{
$this->user = $this->input->post('user_email',TRUE);
$this->pass = $this->input->post('user_pass',TRUE);
$this->pass=md5(sha1(sha1($this->pass)));
$u = new User();
$login_data = array('email' => $this->user, 'password' => $this->pass);
$u->where($login_data)->get();
if(!empty($u->id) && $u->id > 0 )
{
$_SESSION['user_id'] = $u->id;
$_SESSION['user_name']= $u->username;
$_SESSION['fullname']= $u->fullname;
$_SESSION['is_verefied'] = $u->active;
$_SESSION['user_email']= $u->email;
$u->lastlogin = time();
$u->save();
setcookie("logged", 1, time()+86400);
if(empty($_POST['referer']))
{
if(empty($_GET['referer']))
{
$url = "./";
}
else
{
$url = $_GET['referer'];
}
}
else
{
$url = $_POST['referer'];
}
redirect($url);
}
else
{
$this->template->set_layout('inner');
$this->template->build('login_view',$this->data);
}
}
public function logout()
{
setcookie("logged", 0, time()+86400);
$_COOKIE["logged"] = '';
$_SESSION['user_id'] = '';
$_SESSION['user_name']= '';
$_SESSION['fullname']= '';
$_SESSION['is_verefied'] = '';
$_SESSION['user_email']= '';
redirect('./home/index/logout');
}
When I logout from site, and click back from browser the user information session its not deleted.
The back button of your browser might get you to cached version of you page, cached from back when you were logged it. Also, I suggest you use CodeIgniter's sessions.
To make sure you're doing everything right.
Destroy the session:
$this->session->sess_destroy();
Clear the cookie, make sure you use the same domain as when you set it up, and that the time is set to past:
setcookie('logged', '', time()-3600); // minus one hour
This script will log the user out of all pages that have a session started on them. You know a page uses sessions if this code is at the top of the code for that page:
<?php session_start(); ?>
Logging out of a website is simply clearing any session data and then destroying it.
Try the following in your logout.php:
<?php
session_start();
// what were doing here is checking for any cookies used by the session.
//If there are any, we are going to delete the data with it.
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}
//now lets unset the session and destroy it
session_unset();
session_destroy();
// for the redirect, we simple use the php header to send the redirect url to the browser
header("Location: login");
Make sure when using the header function that there is no output, caused by blank spaces or html. As a logout page, there should be no output anyways since navigating to the logout page should log the user out and immediately redirect.
I use this script on all my sites and it works great. Anywhere I want the logout link to appear, I just link to the page as such:
Logout
Just make a file called logout.php and put this code into it.
Hope this helps you!

ZF2 Session not lasting on redirect

My site uses multiple languages and my users can click on flags to set their desired language. When that flag is clicked, a Session should store that information and then i want my controller to redirect the user to another page. This i do with the following code:
<?php
public function setLangAction () {
$oLanguageCookie = new Container('language');
$oLanguageCookie->lang = $this->params ('langvar');
$this->redirect()->toRoute('loadpage', array('page' => 'home'));
}
?>
However, when i print_r($_SESSION) in the indexAction (the action where loadpage routes to), $_SESSION is empty.
Can somebody help me?
Depending where you param comes from you should execute
$this->params()->fromQuery('langvar');
$this->params()->fromPost('langvar');
unless it is a route parameter then you can use either:
$this->params()->fromRoute('langvar');
$this->params('langvar');

how to redirect to previous page after registration in magento?

I was trying to redirect the customer to the review page that is a customer has to login or register to rate a product , and i was able to redirect the customer to the review page after login but i could not redirect the customers back to the review page after they have registered to the website, I found the code which is redirecting the customer to the Dashboard but i don't know how to redirect to the previous page.
protected function _welcomeCustomer(Mage_Customer_Model_Customer $customer, $isJustConfirmed = false)
{
$this->_getSession()->addSuccess(
$this->__('Thank you for registering with %s.', Mage::app()->getStore()->getFrontendName())
);
$customer->sendNewAccountEmail(
$isJustConfirmed ? 'confirmed' : 'registered',
'',
Mage::app()->getStore()->getId()
);
$successUrl = Mage::getUrl('*/*/index', array('_secure'=>true));
if ($this->_getSession()->getBeforeAuthUrl()) {
$successUrl = $this->_getSession()->getBeforeAuthUrl(true);
}
return $successUrl;
}
Figured it out myself,
had to add a session variable on the page which has the link to the registration page
$session = Mage::getSingleton('customer/session');
$session->setBeforeAuthUrl( Mage::helper('core/url')->getCurrentUrl() );
And i didn't had to change anything on the "_welcomeCustomer" function.
That should get the customer back to the page from where they clicked the registration link.

JToolbar::save() redirection

I'm going through the Joomla 2.5 tutorial to build a custom component. Now I'm facing an issue on the redirection after using JToolbar::save() or JToolBarHelper::cancel for that matter. By default Joomla wants to redirect to the default layout (from the edit layout). However I don't want it to do that. I want it to redirect back to another view. In Joomla 1.5 I would have done this through adding the function into the controller - something like
function cancel()
{
//redirects user back to blog homepage with Cancellation Message
$msg = JText::_( 'COM_BLOG_POST_CANCELLED' );
$this->setRedirect( 'index.php?option=com_jjblog&view=jjblog', $msg );
}
Now that works beautifully for the cancel function, however for save this is a much more complex thing. If I want to overwrite the url do I have to redirect the controller to the model and then write in all the code for the model interaction? Because that seems slightly excessive just for a url redirection like you would in Joomla 1.5?
Hope you have added the save toolbar code with the proper controller name like this
JToolBarHelper::save('controllerName.save');
Create a save function in appropriate controller.
Add the task in the form
Finnally make sure you have added form action withthe corresponding component name.
You can try this-
In the controller firstly you call the parent save function than redirect to url.
function save(){
parent::save();
$this->setredirect('index.php?option=com_mycomponent');
}
OK it didn't need to $this->setRedirect at all. Just needed me to change the value to
protected $view_list = 'jjBlog';
which then sets the redirects of everything back to that list view.
Source link for this is here.
Thanks for all the responses though!!
view.html.php
protected function addToolbar ()
{
JRequest::setVar ('hidemainmenu', false);
JToolBarHelper::title (JText::_ ('Configuration'), 'configuration.gif');
JToolBarHelper::save($task = 'save', $alt = 'JTOOLBAR_SAVE');
}
controller.php
public function save()
{
$mainframe = JFactory::getApplication();
$mainframe->enqueueMessage (JText::_ ('COM_SOCIALLOGIN_SETTING_SAVED'));
$this->setRedirect (JRoute::_ ('index.php', false));
}
I think you can use
global $mainframe;
$mainframe->redirect("index.php?option=com_user&task=activate&activation=".$activation);
If you are overriding joomla's default save function in your custom component like
function save( $task = 'CustomSave', $alt = 'Save' ) // or even same name Save
Inside your controller you can use the CustomSave as the task and use $mainframe for redirect.
or
$mainframe = &JFactory::getApplication();
$mainframe->redirect("index.php?option=com_user&task=activate&activation=".$activation);
Hope this may help you..

How to determine the authorization in Joomla

After login i use need to set up redirect to custom page. How to catch this authorization in onAfterRoute event?
You should go to this path:
JOOMLAROOT/components/com_user/controller.php
in function register_save(), find this code:
if ( $useractivation == 1 ) {
$message = JText::_( 'REG_COMPLETE_ACTIVATE' );
} else {
$message = JText::_( 'REG_COMPLETE' );
}
after line put this code:
$this->setRedirect('/Your Custom Page Address', $message);
Why not just use the built in redirect in either the Joomla user login menu item or the standard Joomla login module. Both offer the option to redirect a user after a successful login. In the case of the module, you would need to create a menu item pointing to the custom page, but that's easy enough to do.
Is there something you need to do other than just a simple redirect? If not, then just use the system as it is designed.
I would create a small plugin that handles the redirect after login.
After a user has been logged in, the event onUserLogin is triggered, and you could simply do a redirect when the event is called.
Avoid any core hacks, since you'll allways end up having a hazzle during updates.
The code for a plugin like this could look like this:
class plgAuthenticationMyredirect extends JPlugin{
function onUserLogin ($user, $options){
$link = 'index.php?option=.....';
$msg = 'Message to show after login';
$app = JFactory::getApplication();
$app->redirect($link, $msg);
}
}

Resources