The Joomla! Forum ™



Forum rules


Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.



Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: Sat Feb 18, 2012 10:31 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Thu Jan 26, 2012 12:11 am
Posts: 12
Hi All,

I'm in the midst of hacking a plugin called plg_FirstLoginRedirct. Originally written for J1.5, I'm attempting to make it 2.5 compatible, however, my knowledge of PHP and the Joomla API is limited. I think I am nearly there, I just need a little help to get over the line. This is a function which I believe is highly sought after. The plugin is GPL'd and I'd be happy to add your name to the credits and re-publish a new version if you lend me a hand.

The original plugin can be found here http://construct-framework.com/redirect-first-login-plugin

Below is my modified code. The plugin simply checks the user's last login date and if it is not set (all 0's) sets it and redirects appropriately.

It currently causes my local Apache install to drop the connection when logging in while the plugin is active. Any comments/code help/pointers would be much appreciated.

Cheers

Code:
// no direct access
defined('_JEXEC') or die;

jimport( 'joomla.plugin.plugin' );

class plgUserRedirectFirstLogin extends JPlugin
{
   
   function onUserLogin($user, $options)
   {         
      $app =& JFactory::getApplication();
      $user =& JFactory::getUser();      

      if ($user->get('guest') != 1 && $user->lastvisitDate == "0000-00-00 00:00:00")
      {
         $user->setLastVisit();
         $date = JFactory::getDate();
         $user->lastvisitDate = $date->toMySQL();         
         $app->redirect($this->params->get('destination'));
         return true;
      }
   }
}


Last edited by combrains on Sat Feb 18, 2012 9:08 pm, edited 2 times in total.

Top
 Profile  
 
PostPosted: Sat Feb 18, 2012 6:24 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Tue Sep 21, 2010 3:35 pm
Posts: 37
Location: Madrid (Spain)
onUserLogin is a method to handle login, so it is supposed to return true or false to indicate the login status. You have no return statement in your function, so the framework treats it as a null/false response and then cancels login.

Your code should work fine by just adding "return true;" at the end.

HTH.

_________________
Soporte técnico Joomla en Español: http://www.expertosjoomla.es


Top
 Profile  
 
PostPosted: Sat Feb 18, 2012 9:16 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Thu Jan 26, 2012 12:11 am
Posts: 12
Thanks for the tip Nacho, login now works. I have updated the code snippet above to reflect my changes.

However, the redirect still does not. If I reset a user's login date to all 0's in the DB, it should trigger the plugin and redirect. I have tried to hard-code the redirect URL and this does not work either. The system seems to always redirect to option=com_content&view=featured&Itemid=21 on login.

I'm using the standard com_user component and the mod_login module to handle logins. could either of these be overriding my redirect? Or is there something wrong with my redirect code? Is there a way I can debug my code and see what it is doing, and any errors it is producing?

Sorry for all the questions but I'm quite new to all this :)

Cheers


Last edited by combrains on Sat Feb 18, 2012 9:40 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Sat Feb 18, 2012 9:23 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Tue Sep 21, 2010 3:35 pm
Posts: 37
Location: Madrid (Spain)
Well, If you are working in a local web server you can use your IDE to debug Joomla. I personally use Netbeans + MAMP on Mac OSX and works quite well.

_________________
Soporte técnico Joomla en Español: http://www.expertosjoomla.es


Top
 Profile  
 
PostPosted: Sat Feb 18, 2012 9:52 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Thu Jan 26, 2012 12:11 am
Posts: 12
Thanks for the quick reply.

I'm downloading NetBeans as I type.

Any ideas why the system would be ignoring my redirect and instead be redirecting all logins to option=com_content&view=featured&Itemid=21

I have tried to hard code the redirect as

Code:
$app->redirect('index.php?Itemid=178&option=com_civicrm');


however, the system still redirects to the com_content link. Should I be redirecting using the JRouter method instead?

Cheers


Top
 Profile  
 
PostPosted: Sun Feb 19, 2012 10:00 am 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Tue Sep 21, 2010 3:35 pm
Posts: 37
Location: Madrid (Spain)
Well, AFAIK, it is in the controller where you set the next url by calling $this->setRedirect(...). Then, the dispatch method calls $app->redirect($this->redirect).

So, I'd start debugging your controller action to see what happens after your code ends.

Cheers,

_________________
Soporte técnico Joomla en Español: http://www.expertosjoomla.es


Top
 Profile  
 
PostPosted: Sun May 20, 2012 8:10 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Wed May 09, 2012 9:12 am
Posts: 3
Hello Combraines,
I am totaly new to joomla,
and in need for this modification for the 2.5 joomla version of this module.
I was wondering whether you could publish the entire code you developed,
and some explanation on how exactly to do this modification (i am working on a redHat webserver).
OR- if a version of this module for 2.5 has been published (i did not find one at all)- that's good too:)
Thank you very much,
Liora


Top
 Profile  
 
PostPosted: Tue May 22, 2012 2:21 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Wed Aug 20, 2008 12:48 pm
Posts: 22
Hi Liora,
Here's the code that's working for me:

Code:
// no direct access
defined('_JEXEC') or die;

jimport( 'joomla.plugin.plugin' );

class plgUserRedirectFirstLogin extends JPlugin
{
   
   function onUserLogin($user, $options = array())
   {         
      $app =& JFactory::getApplication();
            
      $id = intval(JUserHelper::getUserId($user['username']));
      $user =& JFactory::getUser($id);
               
      if(!$user->guest && $user->lastvisitDate == "0000-00-00 00:00:00")
      {
         $user->setLastVisit();
         $date = JFactory::getDate();
         $user->lastvisitDate = $date->toMySQL();
         $app->redirect($this->params->get('destination'));

         return true;         
      }else{
         //Do whatever you want
      }
   }
}


Hope this helps in any way.
The problem with the code above is, that getUser() is not yet giving the user that logged in, but the function gets his username. So all I did was to use the username to get the id, and then get the user's details.

Joomla 2.5 docs are still a little bit messed up (to me at least), so there might be a nicer way to do this...

_________________
http://fullbackup.cloudzow.com


Top
 Profile  
 
PostPosted: Wed May 23, 2012 8:05 am 
Joomla! Fledgling
Joomla! Fledgling

Joined: Wed May 09, 2012 9:12 am
Posts: 3
Thank you!
a few more questions-
where did you insert this code- in one of the plugin files is presume.?
and another thing- did you hard coded the 'destination' as you showed above-
'index.php?Itemid=178&option=com_civicrm'?

Thanks again!
Liora


Top
 Profile  
 
PostPosted: Wed May 23, 2012 9:09 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Wed Aug 20, 2008 12:48 pm
Posts: 22
Hi,
there's only one file to edit:
/plugins/user/
you will find firstlogin.php there or inside the firstlogin directory. I don't have access from where I am now.

About hard coding: I did not hard code the URL. You put it in the plugin from backend.

_________________
http://fullbackup.cloudzow.com


Top
 Profile  
 
PostPosted: Mon Aug 13, 2012 8:16 pm 
Joomla! Intern
Joomla! Intern

Joined: Tue Apr 28, 2009 7:37 am
Posts: 50
Location: pune
Hi Combrains,

you don't need to hack any file.
you can create user plugin for joomla2.5 and check lastvisitDate on users table if last visit date is 0000-00-00 00:00:00 you can redirect where you want to.

_________________
Thanks
Kind Regards


Top
 Profile  
 
PostPosted: Sat Nov 17, 2012 8:34 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Wed Aug 29, 2012 10:24 am
Posts: 1
Dear combrains,
I'm trying to get the plugin you have developed for joomla 1.5 but the link:
http://construct-framework.com/redirect ... gin-plugin
is broken.
Can you provide me a new working link?
Thanks in advance.
Best regards,
Pietro


Top
 Profile  
 
PostPosted: Sun Jan 13, 2013 2:00 pm 
Joomla! Intern
Joomla! Intern

Joined: Tue Apr 28, 2009 7:37 am
Posts: 50
Location: pune
it seems for joomla 1.6 or grater version.

check this one may be this will help

http://extensions.joomla.org/extensions ... rect/13961

_________________
Thanks
Kind Regards


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 



Who is online

Users browsing this forum: Hocho and 30 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group