Login | Sign up | Toll-Free: 1-800-752-0455



5 posts by 2 authors in: Forums > CMS Builder
Last Post: September 12, 2017

Hi Ryan, 

There's actually a plugin hook in websiteMemebership.php called 'wsm_loginSuccess' that gets called on successful logins.

You can call a function with it like this:

addAction('wsm_loginSuccess', 'yourPlugin_logLogin', null, 0);

You could have a look at /cmsb/plugins/samplePlugin.php and see if you can copy that.

Alternatively, you could also check for the parameters that trigger website membership to login the user, like this: 

if (@$_REQUEST['action'] == 'login') { /* your logging code here */ }

Hope that helps!

Dave Edis - Senior Developer

Thanks Dave,

I don't really understand how to use hooks & plugins from the frontend of my application so i'll try the IF statement approach.

Should this code be added to the websiteMembership.php page or can i add to the successful login landing page?


Hi Ryan, 

Either would work.  If you add it to websiteMembership I recommend renaming the plugin websiteMembership_CUSTOM.php so it doesn't get accidentally overwritten when upgrading the plugin in future.  You could add some custom code after where wsm_loginSuccess is listed.

Or if you add it to your website files you could put it on the login landing page.  That would work as well.

Good luck with it!

Dave Edis - Senior Developer

Hi Dave,

That worked for me thanks.

For the benefit of anyone else looking to do something similar I added the following code to the membership plugin.

//Fetch User Info from CMS for Selected User & Log to DB  

   $LoggedOnUserName = mysql_escape($_REQUEST['username']);

   //Fetch User Data FROM accounts table
   list($accountsRecords, $accountsMetaData) = getRecords(array(
   'tableName'   => 'accounts',
   'where'       => 'username = "'.$LoggedOnUserName.'"', 
   'loadUploads' => true,
   'allowSearch' => false,
   'limit'       => '1'

   $accountsRecord = @$accountsRecords[0]; // get first record
   $LoginUserNum = $accountsRecord['num']; // Set User Number

   // ADD record to login audit table 
   $tablename   = 'login_audit';
   $colsToValues = array(); // 
   $colsToValues['createdDate=']      = 'NOW()';
   $colsToValues['updatedDate=']      = 'NOW()';
   $colsToValues['createdByUserNum']  = $LoginUserNum;
   $colsToValues['updatedByUserNum']  = $LoginUserNum;   
   $colsToValues['user']              = $LoginUserNum;
   $colsToValues['ip_address']        = $_SERVER['REMOTE_ADDR']; // Log IP 
   $hideMissingFieldErrors = true;
   $newRecordNum = mysql_insert($tablename, $colsToValues, $hideMissingFieldErrors); 

   //***************************** END OF TRACKING CODE UPDATE

Just before where the form values get cleared.

 // clear form values
  $_REQUEST['username'] = '';
  $_REQUEST['password'] = '';