Skip to Content Skip to Menu

function onAfterLogin help

17 years 7 months ago #33835 by SimonBaumer
function onAfterLogin help was created by SimonBaumer
I'm beginning my CB Plug-In Development learning, and have reviewed the API. I am having some troubles understanding the proper use of:
[code:1]
function onBeforeLogin ($username, $passwd2)
function onAfterLogin ($row, true)
[/code:1]
A few questions:

1. Is the onBeforeLogin function required in order to use the onAfterLogin function, or is that just in the event that you want to manipulate information pre-login?

2. I'm not sure what information needs to be in the '$row' and 'true' positions above. If I wanted to to create a plug-in that emailed the administrator every time a user logged in, would this suffice as the process.php file (assuming I had XML/Install/Uninstall files all correctly established)?

[code:1]
function onAfterLogin ($row, true) {
global $database, $my;
$userid = $my->id;
[here would be the php code to mail the administrator that userid has logged in]
}
[/code:1]

Please help me to better understand these functions so that I can further my adventures. I'm clearly missing a key element to understanding this but look forward to learning. Thanks.

Please Log in or Create an account to join the conversation.

  • mikko
  • mikko
  • OFFLINE
  • Posts: 703
  • Thanks: 0
  • Karma: 115
17 years 7 months ago #33842 by mikko
Replied by mikko on topic Re:function onAfterLogin help
1) these are independent functions
2) $row contains details of the loged in user. It is liky $my, but with the CB fields added. you should assign a variable name for true, for example

function onAfterLogin($row, $success){
}

mikko

Please Log in or Create an account to join the conversation.

17 years 7 months ago #33956 by SimonBaumer
Replied by SimonBaumer on topic Re:function onAfterLogin help
Thanks so much for your help mikko. I was successfully able to create the function that I was trying for.

Now I am playing with updating a database table after certain end-user triggered events. I am able to insert data successfully into the database table with the exception of the user id.

My code is as follows:
[code:1]
global $database, $my;

$userid = $my->id; // Find user id

$query1="INSERT INTO #__comprofiler_plug_act SET userid='$userid'";
$database->setquery($query1);
return $database->query();
[/code:1]

No matter what account logs in to CB on the front-end the userid is always equal to 0. What am I doing wrong?

Please Log in or Create an account to join the conversation.

  • mikko
  • mikko
  • OFFLINE
  • Posts: 703
  • Thanks: 0
  • Karma: 115
17 years 7 months ago #33958 by mikko
Replied by mikko on topic Re:function onAfterLogin help
Turn on debugging and you will see what the error is.

See MySQL manual for the correct syntax for INSERT.

Also it is possible that you are trying to insert text to a column which takes only integers. Remove '' around the id and id should work.

mikko

Please Log in or Create an account to join the conversation.

17 years 7 months ago #33959 by SimonBaumer
Replied by SimonBaumer on topic Re:function onAfterLogin help
Thanks for the speedy reply!

How do I turn on debugging? I couldn't find anything in the API or via a search through the forums. Is there a general CB debugging functionality, or one specifically for the plug-ins?

Please Log in or Create an account to join the conversation.

  • mikko
  • mikko
  • OFFLINE
  • Posts: 703
  • Thanks: 0
  • Karma: 115
17 years 7 months ago #33962 by mikko
Replied by mikko on topic Re:function onAfterLogin help
joomla configuration at the back end

mikko

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum