Jelix 1.6.40

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()  : mixed
checkReturnUrl()  : mixed
createUserObject()  : object
Create a new user object
generateCookieToken()  : mixed
getDriver()  : jIAuthDriver
return the auth driver
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
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()  : object|false
verify that the password correspond to the login
_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)

Return values
bool

true if the change succeed

checkCookieToken()

public static checkCookieToken() : mixed
Return values
mixed

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
since
1.0b2
Return values
object

the returned object depends on the driver

generateCookieToken()

public static generateCookieToken(mixed $login, mixed $password) : mixed
Parameters
$login : mixed
$password : mixed
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
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
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([null $newconfig = null ]) : array<string|int, mixed>
Parameters
$newconfig : null = null
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

Return values
bool

true if authentification is ok

logout()

logout a user and delete the user in the php session

public static logout() : 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
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

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) : object|false
Parameters
$login : string

the login of the user

$password : string

the password to test (not encrypted)

Return values
object|false

if ok, returns the user as object

Search results