Jelix 1.8.13

jAuth
in package

This is the main class for authentification process.

Tags
subpackage

auth

Table of Contents

$config  : mixed
$driver  : jIAuthDriver
canChangePassword()  : bool
Indicate if the password can be changed technically.
changePassword()  : bool
change a user password
checkCookieToken()  : bool
check the token from the cookie used for persistant session.
checkReturnUrl()  : mixed
createUserObject()  : object
Create a new user object.
generateCookieToken()  : int
Generate and set an encrypted cookie with the given login password.
getDriver()  : jIAuthDriver
return the auth driver.
getDriverConfig()  : mixed
getDriverParam()  : string
return the value of a parameter of the configuration of the current driver.
getRandomPassword()  : string
generate a password with random letters, numbers and special characters.
getReasonToForbiddenPasswordChange()  : string
If the password cannot be changed, this method gives the reason.
getUser()  : object
load user data.
getUserList()  : array<string|int, object>
construct the user list.
getUserSession()  : object
return the user stored in the php session.
isConnected()  : bool
Says if the user is connected.
isPersistant()  : bool
Check if persistant session is enabled in config.
loadConfig()  : array<string|int, mixed>
Load the configuration of authentification, stored in the auth plugin config.
login()  : bool
authentificate a user, and create a user in the php session.
logout()  : mixed
logout a user and delete the user in the php session.
reloadUser()  : mixed
reloadUserSession()  : mixed
removeUser()  : bool
remove a user send first AuthCanRemoveUser event, then if ok, send AuthRemoveUser and then remove the user.
saveNewUser()  : object
Save a new user.
setUserSession()  : object
Sets the given user in session without authentication.
updateUser()  : bool
update user data.
verifyPassword()  : false|object
verify that the password correspond to the login.
_buildDriverConfig()  : array<string|int, mixed>|null
read the configuration specific to the authentication driver
_getConfig()  : mixed
_getDriver()  : mixed

Properties

Methods

canChangePassword()

Indicate if the password can be changed technically.

public static canChangePassword(string $login) : bool

Not related to rights with jAcl2

Parameters
$login : string

the login of the user

Tags
since
1.6.21
Return values
bool

changePassword()

change a user password

public static changePassword(string $login, string $newpassword) : bool
Parameters
$login : string

the login of the user

$newpassword : string

the new password (not encrypted)

Tags
Return values
bool

true if the change succeed

checkCookieToken()

check the token from the cookie used for persistant session.

public static checkCookieToken() : bool

If the cookie is good, the login is made

Tags
throws
jException
Return values
bool

true if the cookie was ok and login has been succeed

checkReturnUrl()

public static checkReturnUrl(mixed $url) : mixed
Parameters
$url : mixed
Tags
Return values
mixed

createUserObject()

Create a new user object.

public static createUserObject(string $login, string $password) : object

You should call this method if you want to create a new user. It returns an object, representing a user. Then you should fill its properties and give it to the saveNewUser method.

Parameters
$login : string

the user login

$password : string

the user password (not encrypted)

Tags
since
1.0b2
Return values
object

the returned object depends on the driver

generateCookieToken()

Generate and set an encrypted cookie with the given login password.

public static generateCookieToken(string $login, string $password) : int

The cookie may not be set if the persistence is disable or if there is an issue with the encryption.

Parameters
$login : string
$password : string
Tags
Return values
int

expiration date (UNIX timestamp), or 0 if cookie is not set

getDriverConfig()

public static getDriverConfig() : mixed
Tags
throws
jException
Return values
mixed

getDriverParam()

return the value of a parameter of the configuration of the current driver.

public static getDriverParam(string $paramName) : string
Parameters
$paramName : string
Tags
Return values
string

the value. null if it doesn't exist

getRandomPassword()

generate a password with random letters, numbers and special characters.

public static getRandomPassword([int $length = 12 ][, bool $withoutSpecialChars = false ]) : string
Parameters
$length : int = 12

the length of the generated password

$withoutSpecialChars : bool = false

(optional, default false) the generated password may be use this characters : !@#$%^&*?_,~

Tags
Return values
string

the generated password

getReasonToForbiddenPasswordChange()

If the password cannot be changed, this method gives the reason.

public static getReasonToForbiddenPasswordChange() : string

It may returns a reason only after a call of the canChangePassword() method.

Tags
throws
jException
since
1.6.37
Return values
string

getUser()

load user data.

public static getUser(string $login) : object

This method returns an object, generated by the driver, and which contains data corresponding to the given login. This method should be called if you want to update data of a user. see updateUser method.

Parameters
$login : string
Tags
Return values
object

the user

getUserList()

construct the user list.

public static getUserList([string $pattern = '%' ]) : array<string|int, object>
Parameters
$pattern : string = '%'

'' for all users

Tags
Return values
array<string|int, object>

array of objects representing the users

getUserSession()

return the user stored in the php session.

public static getUserSession() : object
Tags
Return values
object

the user data

isConnected()

Says if the user is connected.

public static isConnected() : bool
Tags
Return values
bool

isPersistant()

Check if persistant session is enabled in config.

public static isPersistant() : bool
Tags
Return values
bool

true if persistant session in enabled

loadConfig()

Load the configuration of authentification, stored in the auth plugin config.

public static loadConfig([array<string|int, mixed>|null $newconfig = null ][, object|null $appConfig = null ]) : array<string|int, mixed>

The configuration is readed from the auth.coord.ini.php if it exists and indicated into the coordplugin section. or readed from the section auth from the main configuration or readed from the section coordplugin_auth from the main configuration

The plugin configuration file can be merged with the section auth or coordplugin_auth if there is a auth.mergeconfig parameter in the coordplugins section.

The driver to should be indicated into the driver configuration parameter from the auth.coord.ini.php file, or into the driver configuration of the coordplugin_auth section.

Parameters
$newconfig : array<string|int, mixed>|null = null

a specific configuration of jAuth. If not given, configuration is readed from the files

$appConfig : object|null = null

the application configuration as given by jApp::config()

Tags
throws
jException
since
1.2.10
Return values
array<string|int, mixed>

login()

authentificate a user, and create a user in the php session.

public static login(string $login, string $password[, bool $persistant = false ]) : bool
Parameters
$login : string

the login of the user

$password : string

the password to test (not encrypted)

$persistant : bool = false

(optional) the session must be persistant

Tags
jelixevent

AuthBeforeLogin listeners should return processlogin=false to refuse authentication and to avoid a password check (when a user is blacklisted for exemple) you can also respond to this event to do record in a log file or else. parameters: login

jelixevent

AuthCanLogin sent when password is ok. parameters: login, user=user object listeners can respond with canlogin=false to refuse the authentication.

jelixevent

AuthLogin sent when the login process is finished and the user is authenticated. listeners receive the login and a boolean indicating the persistence

jelixevent

AuthErrorLogin sent when the password is bad. Listeners receive the login.

Return values
bool

true if authentification is ok

logout()

logout a user and delete the user in the php session.

public static logout() : mixed
Tags
jelixevent

AuthLogout listeners received the login

Return values
mixed

reloadUser()

public static reloadUser() : mixed
Tags
deprecated
see
reloadUserSession()
Return values
mixed

reloadUserSession()

public static reloadUserSession() : mixed
Tags
Return values
mixed

removeUser()

remove a user send first AuthCanRemoveUser event, then if ok, send AuthRemoveUser and then remove the user.

public static removeUser(string $login) : bool
Parameters
$login : string

the user login

Tags
Return values
bool

true if ok

saveNewUser()

Save a new user.

public static saveNewUser(object $user) : object

if the saving has succeed, a AuthNewUser event is sent The given object should have been created by calling createUserObject method :

example :

  $user = jAuth::createUserObject('login','password');
  $user->email ='bla@foo.com';
  jAuth::saveNewUser($user);
 

the type of $user depends of the driver, so it can have other properties.

Parameters
$user : object

the user data

Tags
Return values
object

the user (eventually, with additional data)

setUserSession()

Sets the given user in session without authentication.

public static setUserSession(string $login) : object

It is useful if you manage a kind of session that is not the PHP session. For example, in a controller, you call jAuth::login() to verify the authentication, (and allowing listeners to interact during the authentication). In other controller, you just call setUserSession() with the login you retrieve some where, with the help of some request parameters (from a JWT token for example). And you could call jAuth::logout() when the user ends its "session".

Parameters
$login : string
Tags
since
1.6.30
Return values
object

the user data

updateUser()

update user data.

public static updateUser(object $user) : bool

It send a AuthUpdateUser event if the saving has succeed. If you want to change the user password, you must use jAuth::changePassword method instead of jAuth::updateUser method.

The given object should have been created by calling getUser method. Example :

  $user = jAuth::getUser('login');
  $user->email ='bla@foo.com';
  jAuth::updateUser($user);
 

the type of $user depends of the driver, so it can have other properties.

Parameters
$user : object

user data

Tags
Return values
bool

true if the user has been updated

verifyPassword()

verify that the password correspond to the login.

public static verifyPassword(string $login, string $password) : false|object
Parameters
$login : string

the login of the user

$password : string

the password to test (not encrypted)

Tags
Return values
false|object

if ok, returns the user as object

_buildDriverConfig()

read the configuration specific to the authentication driver

protected static _buildDriverConfig(array<string|int, mixed> $authConfig, object $appConfig) : array<string|int, mixed>|null

the driver config is readed from the section named after the driver name, into $authconfig. And into the auth_<drivername> from the main configuration. Both are merged if they exist both.

Parameters
$authConfig : array<string|int, mixed>

content of the auth.coord.ini.php or the auth section or the coordplugin_auth section;

$appConfig : object
Tags
Return values
array<string|int, mixed>|null

Search results