4

I have successfully created a custom registration page in joomla 2.5 and based on the user type i want to redirect the users to different views after log in. How can i achieve this? Do i need to create an Authentication plugin or a custom log in module?

Thanks

Ololade enifeni
  • 111
  • 3
  • 7
  • 15

3 Answers3

1

Try this,

Joomla have a module for login purpose you can use that or just check com_users/view/

for redirecting after successful login in joomla from any page you can use

<input type="hidden" name="return" value="<?php echo base64_encode("your return url"); ?>" />

This hidden field should found inside your login module form some thing like below.

<form action="<?php echo JRoute::_('index.php?option=com_users&task=user.login'); ?>" method="post">

        <fieldset>
            <?php foreach ($this->form->getFieldset('credentials') as $field): ?>
                <?php if (!$field->hidden): ?>
                    <div class="login-fields"><?php echo $field->label; ?>
                    <?php echo $field->input; ?></div>
                <?php endif; ?>
            <?php endforeach; ?>
            <button type="submit" class="button"><?php echo JText::_('JLOGIN'); ?></button>
            <input type="hidden" name="return" value="<?php echo base64_encode($this->params->get('login_redirect_url',$this->form->getValue('return'))); ?>" />
            <?php echo JHtml::_('form.token'); ?>
        </fieldset>
    </form>

You just need to put your return url in the hidden field with base64_encoded Joomla will redirect to this url when the login was success.

This is not a core file editing if you required to redirect after authentication, that means you already providing a login form that should have hidden field like return or just add it.

In another case if you want to know just the redirection option.

$mainframe = JFactory::getApplication();
$mainframe->redirect("your redirect url",'message' ,'message type');

Hope its helps...

Lodder
  • 19,758
  • 10
  • 59
  • 100
Jobin
  • 8,238
  • 1
  • 33
  • 52
  • I really do not want to edit joomla core files. Isn't there any way to do that? – Ololade enifeni Oct 07 '13 at 12:52
  • @Ololadeenifeni - You won't be editing any Joomla core files as you said that it was a custom form that **wasn't** done through Joomla – Lodder Oct 07 '13 at 12:53
  • Okay. I quite understand what you have asked me to do. Here is the thing i have created two different user types while registering e.g agent and user. I look for the user if agent or user then do my redirect. – Ololade enifeni Oct 07 '13 at 13:11
  • @Ololadeenifeni the above codes are not a core file edit, its just an example of login module form for your purpose you can use login module or if you using custom form like your registration just add the hidden fields it will works.. – Jobin Oct 08 '13 at 02:29
  • @jobinJose - thanks. i also figured out i could write a plugin as call the onAfterRoute event then i saw a plugin that i thought was helpful. Thanks a lot – Ololade enifeni Oct 08 '13 at 10:10
  • @Ololadeenifeni what is the name of the plugin, I need to implement something exactly like this, redirect users after login based on the type – kolexinfos Dec 23 '14 at 14:18
1

What about the non-commercial "Redirect on Login" extension: http://extensions.joomla.org/extensions/access-a-security/site-access/login-redirect/15257 which redirects users on login based on access level/user group or a similar extension in the Login Redirect category in JED: http://extensions.joomla.org/extensions/access-a-security/site-access/login-redirect

Neil Robertson
  • 3,295
  • 3
  • 28
  • 49
0

Its Just short cut method in 3.x

Open Path in Joomla plugins\authentication\cookie\cookie.php

In function onUserAfterLogin($options) on top,

$user   = JFactory::getUser();
        $groups = $user->get('groups');

            if(in_array(10, $groups)) 
            {
             $url = JRoute::_('index.php?option=com_students');
             $this->app->redirect($url);
            } 
Musakkhir Sayyed
  • 7,012
  • 13
  • 42
  • 65
Satyanarayana
  • 139
  • 1
  • 4