- md5
- 5b3704d15c4eb8ab59ce1a6010a43996
- sha1
- 7854ae21bdf3f88a2c2e8b9a187be101cd25ab87
- sha256
- 48b0ad6698a8eb0e67a432f6f0957643798ba58eb821eb6e3d07f6ac313fff0e
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
<?php
/**
* @version $Id: example.php 21097 2011-04-07 15:38:03Z dextercowley $
* @copyright Copyright (C) 2005 - 2009 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// No direct access
defined('_JEXEC') or die;
jimport('joomla.plugin.plugin');
/**
* Example User Plugin
*
* @package Joomla.Plugin
* @subpackage User.example
* @since 1.5
*/
class plgUserExample extends JPlugin
{
/**
* Example store user method
*
* Method is called before user data is stored in the database
*
* @param array $user Holds the old user data.
* @param boolean $isnew True if a new user is stored.
* @param array $new Holds the new user data.
*
* @return void
* @since 1.6
* @throws Exception on error.
*/
public function onUserBeforeSave($user, $isnew, $new)
{
$app = JFactory::getApplication();
// throw new Exception('Some error occurred. Please do not save me');
}
/**
* Example store user method
*
* Method is called after user data is stored in the database
*
* @param array $user Holds the new user data.
* @param boolean $isnew True if a new user is stored.
* @param boolean $success True if user was succesfully stored in the database.
* @param string $msg Message.
*
* @return void
* @since 1.6
* @throws Exception on error.
*/
public function onUserAfterSave($user, $isnew, $success, $msg)
{
$app = JFactory::getApplication();
// convert the user parameters passed to the event
// to a format the external application
$args = array();
$args['username'] = $user['username'];
$args['email'] = $user['email'];
$args['fullname'] = $user['name'];
$args['password'] = $user['password'];
if ($isnew) {
// Call a function in the external app to create the user
// ThirdPartyApp::createUser($user['id'], $args);
}
else {
// Call a function in the external app to update the user
// ThirdPartyApp::updateUser($user['id'], $args);
}
}
/**
* Example store user method
*
* Method is called before user data is deleted from the database
*
* @param array $user Holds the user data.
*
* @return void
* @since 1.6
*/
public function onUserBeforeDelete($user)
{
$app = JFactory::getApplication();
}
/**
* Example store user method
*
* Method is called after user data is deleted from the database
*
* @param array $user Holds the user data.
* @param boolean $succes True if user was succesfully stored in the database.
* @param string $msg Message.
*
* @return void
* @since 1.6
*/
public function onUserAfterDelete($user, $succes, $msg)
{
$app = JFactory::getApplication();
// only the $user['id'] exists and carries valid information
// Call a function in the external app to delete the user
// ThirdPartyApp::deleteUser($user['id']);
}
/**
* This method should handle any login logic and report back to the subject
*
* @param array $user Holds the user data.
* @param array $options Extra options.
*
* @return boolean True on success
* @since 1.5
*/
public function onUserLogin($user, $options)
{
// Initialise variables.
$success = false;
// Here you would do whatever you need for a login routine with the credentials
//
// Remember, this is not the authentication routine as that is done separately.
// The most common use of this routine would be logging the user into a third party
// application.
//
// In this example the boolean variable $success would be set to true
// if the login routine succeeds
// ThirdPartyApp::loginUser($user['username'], $user['password']);
return $success;
}
/**
* This method should handle any logout logic and report back to the subject
*
* @param array $user Holds the user data.
*
* @return boolean True on success
* @since 1.5
*/
public function onUserLogout($user)
{
// Initialise variables.
$success = false;
// Here you would do whatever you need for a logout routine with the credentials
//
// In this example the boolean variable $success would be set to true
// if the logout routine succeeds
// ThirdPartyApp::loginUser($user['username'], $user['password']);
return $success;
}
}
The same content is in 5 releases, Joomla 1.6.2 to 1.6.6. See them all, or every version of this file.