jAuth
in package
This is the main class for authentification process.
Tags
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
- _getConfig() : mixed
- _getDriver() : mixed
Properties
$config
protected
static mixed
$config
$driver
protected
static jIAuthDriver
$driver
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
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)
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
Return values
bool —true if the cookie was ok and login has been succeed
checkReturnUrl()
public
static checkReturnUrl(mixed $url) : mixed
Parameters
- $url : mixed
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
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
Return values
int —expiration date (UNIX timestamp), or 0 if cookie is not set
getDriver()
return the auth driver.
public
static getDriver() : jIAuthDriver
Tags
Return values
jIAuthDriver —getDriverConfig()
public
static getDriverConfig() : mixed
Tags
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
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 = 10 ][, bool $withoutSpecialChars = false ]) : string
Parameters
- $length : int = 10
-
the length of the generated password
- $withoutSpecialChars : bool = false
-
(optional, default false) the generated password may be use this characters : !@#$%^&*?_,~
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
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
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
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
Return values
object —the user data
isConnected()
Says if the user is connected.
public
static isConnected() : bool
Return values
bool —isPersistant()
Check if persistant session is enabled in config.
public
static isPersistant() : bool
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> $newconfig = null ]) : array<string|int, mixed>
Parameters
- $newconfig : array<string|int, mixed> = null
-
the configuration of jAuth
Tags
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
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
Return values
mixed —reloadUser()
public
static reloadUser() : mixed
Tags
Return values
mixed —reloadUserSession()
public
static reloadUserSession() : mixed
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
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
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
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
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)
Return values
false|object —if ok, returns the user as object
_buildDriverConfig()
protected
static _buildDriverConfig(array<string|int, mixed> $authConfig, object $appConfig) : array<string|int, mixed>|null
Parameters
- $authConfig : array<string|int, mixed>
- $appConfig : object
Return values
array<string|int, mixed>|null —_getConfig()
protected
static _getConfig() : mixed
Tags
Return values
mixed —_getDriver()
protected
static _getDriver() : mixed