Difference between revisions of "Plugin/Events/User"

From Joomla! Documentation

< Plugin‎ | Events
(11 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{page|needs updating|Page is based on 1.5 and needs updating, links point to 1.5 api and are broken.}}
+
<noinclude><languages /></noinclude>
  
 +
<translate>
 +
<!--T:1-->
 
In a standard installation of Joomla! we have several predefined User events which, when triggered, call functions in the associated plugins.
 
In a standard installation of Joomla! we have several predefined User events which, when triggered, call functions in the associated plugins.
 +
</translate>
  
 
==onUserLogin==
 
==onUserLogin==
===Description===
+
<translate>
 +
===Description=== <!--T:2-->
 
This event is triggered after the user is authenticated against the Joomla! user-base.
 
This event is triggered after the user is authenticated against the Joomla! user-base.
  
 +
<!--T:3-->
 
If you need to abort the login process (authentication), you will need to use [[#onUserAuthenticate|onUserAuthenticate]] instead.
 
If you need to abort the login process (authentication), you will need to use [[#onUserAuthenticate|onUserAuthenticate]] instead.
 +
</translate>
  
===Parameters===
+
<translate>
* $user - an associative array of [http://api.joomla.org/cms-3/classes/JAuthenticationResponse.html JAuthenticateResponse] type (see link for array keys)
+
===Parameters=== <!--T:4-->
* $options - an associative array containing these keys: ["remember"] => bool, ["return"] => string, ["entry_url"] => string
+
* '''$user''' - an associative array of [http://api.joomla.org/cms-3/classes/JAuthenticationResponse.html JAuthenticateResponse] type (see link for array keys)
 +
* '''$options''' - an associative array containing these keys: ["remember"] => bool, ["return"] => string, ["entry_url"] => string
 +
</translate>
  
===Return Value===
+
<translate>
 +
===Return Value=== <!--T:5-->
 
Boolean
 
Boolean
===Used in files===
+
</translate>
 +
 
 +
<translate>===Used in files=== <!--T:6--></translate>
 
*<tt>libraries/joomla/application/application.php</tt>
 
*<tt>libraries/joomla/application/application.php</tt>
 
*<tt>plugins/user/joomla.php</tt>
 
*<tt>plugins/user/joomla.php</tt>
===Examples===
+
 
 +
<translate>===Example=== <!--T:7--></translate>
 
*<tt>plugins/user/example.php</tt>
 
*<tt>plugins/user/example.php</tt>
  
 
==onUserLogout==
 
==onUserLogout==
===Description===
 
This event is triggered before the user is logged out of the system. <del>If one plugin
 
returns false, the global logout fails.</del> (needs verification)
 
  
===Parameters===
+
<translate>
* $credentials - an associative array containing these keys: ["username"] => string, ["id"] => int
+
===Description=== <!--T:8-->
* $options - an associative array containing this key: ["clientid"] => int
+
This event is triggered before the user is logged out of the system.
 +
 
 +
<!--T:9-->
 +
If any plugin returns false, the global logout fails and the onUserLogoutFailure event is fired; if it succeeds, onUserAfterLogout event is triggered instead.
 +
 
 +
<!--T:10-->
 +
NOTE: as of 3.3.6, returning false does not work correctly, because stock components perform their logout operation during the onUserLogout event. So even if your plugin returns false, the stock ones have already run anyway. Thus, the user will be "mostly" logged out even if you return false. There is no actual way to cleanly abort logout.
 +
</translate>
  
===Return Value===
+
<translate>
 +
===Parameters=== <!--T:11-->
 +
* '''$credentials''' - an associative array containing these keys: ["username"] => string, ["id"] => int
 +
* '''$options''' - an associative array containing this key: ["clientid"] => int
 +
</translate>
 +
 
 +
<translate>
 +
===Return Value=== <!--T:12-->
 
Boolean
 
Boolean
===Used in files===
+
</translate>
*<tt>libraries/joomla/application/application.php</tt>
+
 
*<tt>plugins/user/joomla.php</tt>
+
<translate>===Used in files=== <!--T:13--></translate>
===Examples===
+
*<tt>libraries/cms/application/cms.php</tt>
 +
*<tt>plugins/user/joomla/joomla.php</tt>
 +
*<tt>plugins/system/logout.php</tt>
 +
*<tt>plugins/system/remember/remember.php</tt>
 +
 
 +
<translate>===Example=== <!--T:14--></translate>
 
*<tt>plugins/user/example.php</tt>
 
*<tt>plugins/user/example.php</tt>
  
 
==onUserAuthenticate==
 
==onUserAuthenticate==
===Description===
+
 
 +
<translate>
 +
===Description=== <!--T:15-->
 
This event is triggered to verify that a set of login credentials is valid.
 
This event is triggered to verify that a set of login credentials is valid.
===Parameters===
+
</translate>
 +
 
 +
<translate>
 +
===Parameters=== <!--T:16-->
 
Array of credentials. Structure:\\
 
Array of credentials. Structure:\\
 
['username']\\
 
['username']\\
 
['password']\\
 
['password']\\
 
Alternative authentication mechanisms can supply additional credentials.
 
Alternative authentication mechanisms can supply additional credentials.
 +
</translate>
  
===Return Value===
+
<translate>
 +
===Return Value=== <!--T:17-->
 
An array of JAuthenticateResponse objects detailing the results of each called plugin, including success or failure.
 
An array of JAuthenticateResponse objects detailing the results of each called plugin, including success or failure.
 +
</translate>
  
===Used in files===
+
<translate>
 +
===Used in files=== <!--T:18-->
 +
</translate>
 
*<tt>libraries/joomla/application/user/authentication.php</tt>
 
*<tt>libraries/joomla/application/user/authentication.php</tt>
 
*<tt>plugins/authentication/gmail.php</tt>
 
*<tt>plugins/authentication/gmail.php</tt>
 
*<tt>plugins/authentication/joomla.php</tt>
 
*<tt>plugins/authentication/joomla.php</tt>
 
*<tt>plugins/authentication/ldap.php</tt>
 
*<tt>plugins/authentication/ldap.php</tt>
===Examples===
+
 
 +
<translate>===Example=== <!--T:19--></translate>
 
*<tt>plugins/authentication/example.php</tt>
 
*<tt>plugins/authentication/example.php</tt>
  
 
==onUserLoginFailure==
 
==onUserLoginFailure==
===Description===
+
 
 +
<translate>
 +
===Description=== <!--T:20-->
 
This event is triggered whenever a user authentication request is failed by any plugin.
 
This event is triggered whenever a user authentication request is failed by any plugin.
===Parameters===
+
</translate>
 +
 
 +
<translate>
 +
===Parameters=== <!--T:21-->
 
Two parameters. The credentials array for the user (see onAuthenticate), and the JAuthenticateResponse that caused the failure.
 
Two parameters. The credentials array for the user (see onAuthenticate), and the JAuthenticateResponse that caused the failure.
===Return Value===
+
</translate>
 +
 
 +
<translate>
 +
===Return Value=== <!--T:22-->
 
Unknown. The return value appears to be ignored in any case.
 
Unknown. The return value appears to be ignored in any case.
===Used in files===
+
</translate>
 +
 
 +
<translate>===Used in file=== <!--T:23--></translate>
 
*<tt>libraries/joomla/application/user/authentication.php</tt>
 
*<tt>libraries/joomla/application/user/authentication.php</tt>
 +
 
==onUserAfterLogin==
 
==onUserAfterLogin==
===Description===
+
 
This event is triggered whenever a user authentication with success
+
<translate>
===Parameters===
+
===Description=== <!--T:24-->
The parameters are
+
This event is triggered whenever a user is successfully logged in.
===Return Value===
+
</translate>
Unknown
+
 
===Used in files===
+
<translate>
 +
===Parameters=== <!--T:25-->
 +
Options is array with:
 +
</translate>
 +
* remember
 +
* return
 +
* entry_url
 +
* action
 +
* user  - JUser Object
 +
* responseType
 +
 
 +
<translate>
 +
===Return Value=== <!--T:26-->
 +
Boolean
 +
</translate>
 +
 
 +
<translate>===Used in files=== <!--T:27--></translate>
 
*<tt>libraries/legacy/application/application.php</tt>
 
*<tt>libraries/legacy/application/application.php</tt>
 
*<tt>libraries/cms/application/cms.php</tt>
 
*<tt>libraries/cms/application/cms.php</tt>
*<tt>plugins/authentication/cookie/cookie.php/tt>
+
*<tt>plugins/authentication/cookie/cookie.php</tt>
  
 
==onUserBeforeSave==
 
==onUserBeforeSave==
===Description===
+
 
 +
<translate>
 +
===Description=== <!--T:28-->
 
This event is triggered before an update of a user record.
 
This event is triggered before an update of a user record.
  
Password in $user array is already hashed at this point. You may retrieve the cleartext password using $_POST['password'].
+
<!--T:29-->
 +
The old and new user parameters are provided; commonly-used members are: username, name, email, password, password_clear.
 +
 
 +
<!--T:30-->
 +
The password array entry is the hashed password value. If the user has just changed the password, you may retrieve the cleartext password from $newUser['password_clear']. (It will be set to "" if the password has not been changed.)
 +
</translate>
 +
 
 +
<translate>
 +
===Parameters=== <!--T:31-->
 +
* '''$oldUser''' - An associative array of the columns in the user table (current values).
 +
* '''$isnew''' - Boolean to identify if this is a new user (true - insert) or an existing one (false - update)
 +
* '''$newUser''' - An associative array of the columns in the user table (new values).
 +
</translate>
  
===Parameters===
+
<translate>
* $user - An associative array of the columns in the user table (current values).
+
===Return Value=== <!--T:32-->
* $isnew - Boolean to identify if this is a new user (true - insert) or an existing one (false - update)
+
Boolean. Whether the user-save should proceed or not. Any plugin that returns false aborts the save.
Note; You can retrieve the values that are about to get updated with <source>JFactory::getUser();</source>
+
</translate>
  
===Return Value===
+
<translate>===Used in file=== <!--T:33--></translate>
None
 
===Used in files===
 
 
*<tt>libraries/joomla/user/user.php</tt>
 
*<tt>libraries/joomla/user/user.php</tt>
===Examples===
+
 
 +
<translate>===Example=== <!--T:34--></translate>
 
*<tt>plugins/user/example.php</tt>
 
*<tt>plugins/user/example.php</tt>
  
 
==onUserAfterSave==
 
==onUserAfterSave==
===Description===
+
 
 +
<translate>
 +
===Description=== <!--T:35-->
 
This event is triggered after an update of a user record, or when a new user has been stored in the database.
 
This event is triggered after an update of a user record, or when a new user has been stored in the database.
  
 +
<!--T:36-->
 
Password in $user array is already hashed at this point. You may retrieve the cleartext password using $_POST['password'].
 
Password in $user array is already hashed at this point. You may retrieve the cleartext password using $_POST['password'].
 +
</translate>
  
===Parameters===
+
<translate>
 +
===Parameters=== <!--T:37-->
 
* '''$user''' - An associative array of the columns in the user table.
 
* '''$user''' - An associative array of the columns in the user table.
 
* '''$isnew''' - Boolean to identify if this is a new user (true - insert) or an existing one (false - update)
 
* '''$isnew''' - Boolean to identify if this is a new user (true - insert) or an existing one (false - update)
Line 109: Line 193:
 
* '''$msg''' - Error message if store failed
 
* '''$msg''' - Error message if store failed
 
Note: The old values that were just updated are not available here or afterwards. In case you need the old values, use onBeforeStoreUser().
 
Note: The old values that were just updated are not available here or afterwards. In case you need the old values, use onBeforeStoreUser().
 +
</translate>
  
===Return Value===
+
<translate>
 +
===Return Value=== <!--T:38-->
 
None
 
None
===Used in files===
+
</translate>
 +
 
 +
<translate>===Used in file=== <!--T:39--></translate>
 
*<tt>libraries/joomla/user/user.php</tt>
 
*<tt>libraries/joomla/user/user.php</tt>
===Examples===
+
 
 +
<translate>===Example=== <!--T:40--></translate>
 
*<tt>plugins/user/example.php</tt>
 
*<tt>plugins/user/example.php</tt>
  
 
==onUserBeforeDelete==
 
==onUserBeforeDelete==
===Description===
+
 
 +
<translate>
 +
===Description=== <!--T:41-->
 
The event is triggered when a user is about to be deleted from the system.
 
The event is triggered when a user is about to be deleted from the system.
===Parameters===
+
</translate>
* $user - An associative array of the columns in the user table.
 
  
===Return Value===
+
<translate>
 +
===Parameters=== <!--T:42-->
 +
* '''$user''' - An associative array of the columns in the user table.
 +
</translate>
 +
 
 +
<translate>
 +
===Return Value=== <!--T:43-->
 
None.
 
None.
===Used in files===
+
</translate>
 +
 
 +
<translate>===Used in files=== <!--T:44--></translate>
 
*<tt>libraries/joomla/user/user.php</tt>
 
*<tt>libraries/joomla/user/user.php</tt>
 
*<tt>plugins/user/joomla.php</tt>
 
*<tt>plugins/user/joomla.php</tt>
===Examples===
+
 
 +
<translate>===Example=== <!--T:45--></translate>
 
*<tt>plugins/user/example.php</tt>
 
*<tt>plugins/user/example.php</tt>
  
 
==onUserAfterDelete==
 
==onUserAfterDelete==
===Description===
+
 
 +
<translate>
 +
===Description=== <!--T:46-->
 
The event is triggered after a user has been deleted from the system.
 
The event is triggered after a user has been deleted from the system.
===Parameters===
+
</translate>
* $user - An associative array of the columns in the user table.
 
* $succes - Boolean to identify if the deletion was successful
 
* $msg - Error message if delete failed ([http://api.joomla.org/cms-3/classes/JError.html JError] object detailing the error, if any)
 
  
===Return Value===
+
<translate>
 +
===Parameters=== <!--T:47-->
 +
* '''$user''' - An associative array of the columns in the user table.
 +
* '''$succes''' - Boolean to identify if the deletion was successful
 +
* '''$msg''' - Error message if delete failed ([http://api.joomla.org/cms-3/classes/JError.html JError] object detailing the error, if any)
 +
</translate>
 +
 
 +
<translate>
 +
===Return Value=== <!--T:48-->
 
None.
 
None.
===Used in files===
+
</translate>
 +
 
 +
<translate>===Used in files=== <!--T:49--></translate>
 
*<tt>libraries/joomla/user/user.php</tt>
 
*<tt>libraries/joomla/user/user.php</tt>
 
*<tt>plugins/user/joomla.php</tt>
 
*<tt>plugins/user/joomla.php</tt>
===Examples===
+
 
 +
<translate>===Example=== <!--T:50--></translate>
 
*<tt>plugins/user/example.php</tt>
 
*<tt>plugins/user/example.php</tt>
  
<noinclude>[[Category:Plugin Development]][[Category:Specifications]]</noinclude>
+
<noinclude>
 +
<translate>
 +
<!--T:51-->
 +
[[Category:Plugin Development]]
 +
[[Category:Specifications]]
 +
</translate>
 +
</noinclude>

Revision as of 12:56, 19 September 2015

Other languages:
English • ‎Nederlands • ‎español • ‎français

In a standard installation of Joomla! we have several predefined User events which, when triggered, call functions in the associated plugins.

onUserLogin[edit]

Description[edit]

This event is triggered after the user is authenticated against the Joomla! user-base.

If you need to abort the login process (authentication), you will need to use onUserAuthenticate instead.

Parameters[edit]

  • $user - an associative array of JAuthenticateResponse type (see link for array keys)
  • $options - an associative array containing these keys: ["remember"] => bool, ["return"] => string, ["entry_url"] => string

Return Value[edit]

Boolean

Used in files[edit]

  • libraries/joomla/application/application.php
  • plugins/user/joomla.php

Example[edit]

  • plugins/user/example.php

onUserLogout[edit]

Description[edit]

This event is triggered before the user is logged out of the system.

If any plugin returns false, the global logout fails and the onUserLogoutFailure event is fired; if it succeeds, onUserAfterLogout event is triggered instead.

NOTE: as of 3.3.6, returning false does not work correctly, because stock components perform their logout operation during the onUserLogout event. So even if your plugin returns false, the stock ones have already run anyway. Thus, the user will be "mostly" logged out even if you return false. There is no actual way to cleanly abort logout.

Parameters[edit]

  • $credentials - an associative array containing these keys: ["username"] => string, ["id"] => int
  • $options - an associative array containing this key: ["clientid"] => int

Return Value[edit]

Boolean

Used in files[edit]

  • libraries/cms/application/cms.php
  • plugins/user/joomla/joomla.php
  • plugins/system/logout.php
  • plugins/system/remember/remember.php

Example[edit]

  • plugins/user/example.php

onUserAuthenticate[edit]

Description[edit]

This event is triggered to verify that a set of login credentials is valid.

Parameters[edit]

Array of credentials. Structure:\\ ['username']\\ ['password']\\ Alternative authentication mechanisms can supply additional credentials.

Return Value[edit]

An array of JAuthenticateResponse objects detailing the results of each called plugin, including success or failure.

Used in files[edit]

  • libraries/joomla/application/user/authentication.php
  • plugins/authentication/gmail.php
  • plugins/authentication/joomla.php
  • plugins/authentication/ldap.php

Example[edit]

  • plugins/authentication/example.php

onUserLoginFailure[edit]

Description[edit]

This event is triggered whenever a user authentication request is failed by any plugin.

Parameters[edit]

Two parameters. The credentials array for the user (see onAuthenticate), and the JAuthenticateResponse that caused the failure.

Return Value[edit]

Unknown. The return value appears to be ignored in any case.

Used in file[edit]

  • libraries/joomla/application/user/authentication.php

onUserAfterLogin[edit]

Description[edit]

This event is triggered whenever a user is successfully logged in.

Parameters[edit]

Options is array with:

  • remember
  • return
  • entry_url
  • action
  • user - JUser Object
  • responseType

Return Value[edit]

Boolean

Used in files[edit]

  • libraries/legacy/application/application.php
  • libraries/cms/application/cms.php
  • plugins/authentication/cookie/cookie.php

onUserBeforeSave[edit]

Description[edit]

This event is triggered before an update of a user record.

The old and new user parameters are provided; commonly-used members are: username, name, email, password, password_clear.

The password array entry is the hashed password value. If the user has just changed the password, you may retrieve the cleartext password from $newUser['password_clear']. (It will be set to "" if the password has not been changed.)

Parameters[edit]

  • $oldUser - An associative array of the columns in the user table (current values).
  • $isnew - Boolean to identify if this is a new user (true - insert) or an existing one (false - update)
  • $newUser - An associative array of the columns in the user table (new values).

Return Value[edit]

Boolean. Whether the user-save should proceed or not. Any plugin that returns false aborts the save.

Used in file[edit]

  • libraries/joomla/user/user.php

Example[edit]

  • plugins/user/example.php

onUserAfterSave[edit]

Description[edit]

This event is triggered after an update of a user record, or when a new user has been stored in the database.

Password in $user array is already hashed at this point. You may retrieve the cleartext password using $_POST['password'].

Parameters[edit]

  • $user - An associative array of the columns in the user table.
  • $isnew - Boolean to identify if this is a new user (true - insert) or an existing one (false - update)
  • $success - Boolean to identify if the store was successful
  • $msg - Error message if store failed

Note: The old values that were just updated are not available here or afterwards. In case you need the old values, use onBeforeStoreUser().

Return Value[edit]

None

Used in file[edit]

  • libraries/joomla/user/user.php

Example[edit]

  • plugins/user/example.php

onUserBeforeDelete[edit]

Description[edit]

The event is triggered when a user is about to be deleted from the system.

Parameters[edit]

  • $user - An associative array of the columns in the user table.

Return Value[edit]

None.

Used in files[edit]

  • libraries/joomla/user/user.php
  • plugins/user/joomla.php

Example[edit]

  • plugins/user/example.php

onUserAfterDelete[edit]

Description[edit]

The event is triggered after a user has been deleted from the system.

Parameters[edit]

  • $user - An associative array of the columns in the user table.
  • $succes - Boolean to identify if the deletion was successful
  • $msg - Error message if delete failed (JError object detailing the error, if any)

Return Value[edit]

None.

Used in files[edit]

  • libraries/joomla/user/user.php
  • plugins/user/joomla.php

Example[edit]

  • plugins/user/example.php