UsersDb
extends BaseModel
in package
Users DB model.
Tags
Table of Contents
Constants
Properties
- $allowedSort : array<string|int, mixed>
- $passwordAlgo : int
- $passwordAlgoOptions : array<string|int, mixed>
Methods
- __construct() : mixed
- {@inheritDoc}
- add() : mixed
- Add user data.
- checkLogin() : array<string|int, mixed>
- Check login credentials.
- delete() : bool
- Delete a user and related tables.
- get() : mixed
- Get a single user data.
- hashPassword() : string|bool
- Hash the password.
- listItems() : array<string|int, mixed>
- List users.
- predefinedStatusText() : mixed
- Get pre-defined status text for use in `user_statustext` column.
- update() : bool
- Update user data.
- checkPassword() : bool
- Check password that match hashed.
- listUsersRolesForUserIds() : array<string|int, mixed>
- List user's roles by search from multiple user IDs.
- passwordNeedsRehash() : bool
- Checks if the given hash matches the given options.
Constants
LOGIN_ERR_ACCOUNT_DISABLED
public
int
LOGIN_ERR_ACCOUNT_DISABLED
= 2
Your account has been disabled. (%1$s)
LOGIN_ERR_USERPASSWORD_INCORRECT
public
int
LOGIN_ERR_USERPASSWORD_INCORRECT
= 1
The username or password is incorrect.
Properties
$allowedSort
protected
array<string|int, mixed>
$allowedSort
= ['user_id', 'user_login', 'user_email', 'user_display_name', 'user_create', 'user_create_gmt', 'user_lastupdate', 'user_lastupdate_gmt', 'user_lastlogin', 'user_lastlogin_gmt', 'user_status', 'user_statustext']
Allowed sort columns in db.
$passwordAlgo
protected
int
$passwordAlgo
The password algorithm.
$passwordAlgoOptions
protected
array<string|int, mixed>
$passwordAlgoOptions
= []
The password algo's options.
Methods
__construct()
{@inheritDoc}
public
__construct(Container $Container) : mixed
Parameters
- $Container : Container
add()
Add user data.
public
add(array<string|int, mixed> $data) : mixed
Parameters
- $data : array<string|int, mixed>
-
The associative array where key is column name and value is its value.
Return values
mixed —Return inserted ID if successfully inserted, return 0
(zero), or false
if failed to insert.
checkLogin()
Check login credentials.
public
checkLogin(array<string|int, mixed> $data) : array<string|int, mixed>
Try to check login with username or email and password with these conditions.
- username or email must be found.
- user status must be enabled.
- password must be matched (by hashed).
This will be not set any cookie when login correctly.
Parameters
- $data : array<string|int, mixed>
-
The login data such as
user_login
,user_password
in the array key.
Return values
array<string|int, mixed> —Return associate array.
On success, return keys: user_id
(int),
user
(object),
userStatus
(int),
result
(bool).
On failure, return keys: user_id
(int - optional) - if found user but something wrong,
result
(bool),
errorCode
(int),
userStatus
(int - optional),
userStatusText
(string - optional),
delete()
Delete a user and related tables.
public
delete(int $user_id) : bool
Parameters
- $user_id : int
-
The user ID.
Return values
bool —Return true
on success, false
for otherwise.
get()
Get a single user data.
public
get([array<string|int, mixed> $where = [] ][, array<string|int, mixed> $options = [] ]) : mixed
Parameters
- $where : array<string|int, mixed> = []
-
The associative array where key is column name and value is its value.
- $options : array<string|int, mixed> = []
-
The associative array with these options.
getUserFields
(bool) to get all data fromuser_fields
table.
Return values
mixed —Return object if result was found, return empty
, null
, false
if it was not found.
hashPassword()
Hash the password.
public
hashPassword(string $password[, int $algo = null ][, array<string|int, mixed> $options = [] ]) : string|bool
Parameters
- $password : string
-
The user's password (readable).
- $algo : int = null
-
The password algorithm. Leave
null
to use config. - $options : array<string|int, mixed> = []
-
The password algorithm options. Leave empty to use config.
Tags
Return values
string|bool —Return the hashed password or false
for failure.
listItems()
List users.
public
listItems([array<string|int, mixed> $options = [] ]) : array<string|int, mixed>
Parameters
- $options : array<string|int, mixed> = []
-
The associative array options. Available options keys:
search
(string) the search term,
userIdsIn
(array) the user IDs to use in the sql commandWHERE IN (...)
where
(array) the where conditions where key is column name and value is its value,
sortOrders
(array) the sort order wheresort
key is column name,order
key is mysql order (ASC, DESC),
unlimited
(bool) set totrue
to show unlimited items, unset or set tofalse
to show limited items,
limit
(int) limit items per page. maximum is 100,
offset
(int) offset or start at record. 0 is first record,
Return values
array<string|int, mixed> —Return associative array with total
and items
in keys.
predefinedStatusText()
Get pre-defined status text for use in `user_statustext` column.
public
predefinedStatusText([string|int $getKey = '' ]) : mixed
Parameters
- $getKey : string|int = ''
-
Use empty string to get all, use
integer
value to get its array key.
update()
Update user data.
public
update(array<string|int, mixed> $data, array<string|int, mixed> $where) : bool
Parameters
- $data : array<string|int, mixed>
-
The associative array where its key is column name and value is its value to update.
- $where : array<string|int, mixed>
-
The associative array where its key is column name and value is its value.
Return values
bool —Return true
on success update, false
for otherwise.
checkPassword()
Check password that match hashed.
protected
checkPassword(string $rawPassword, string $hashedPassword) : bool
Parameters
- $rawPassword : string
-
The user input password.
- $hashedPassword : string
-
The hashed password that store in the database.
Tags
Return values
bool —Return true if password checked and passed, false for otherwise.
listUsersRolesForUserIds()
List user's roles by search from multiple user IDs.
protected
listUsersRolesForUserIds(array<string|int, mixed> $userIds) : array<string|int, mixed>
Parameters
- $userIds : array<string|int, mixed>
-
The user IDs to search for.
Tags
Return values
array<string|int, mixed> —Return result from fetchAll()
or empty array if not found.
passwordNeedsRehash()
Checks if the given hash matches the given options.
protected
passwordNeedsRehash(string $hashedPassword[, int $algo = null ][, array<string|int, mixed> $options = [] ]) : bool
Parameters
- $hashedPassword : string
-
The hashed password that store in the database.
- $algo : int = null
-
The password algorithm. Leave
null
to use config. - $options : array<string|int, mixed> = []
-
The password algorithm options. Leave empty to use config.
Tags
Return values
bool —Return true
if hash should be rehash, false
for otherwise.