EditController
extends AdminBaseController
in package
uses
CommonDataTrait, UsersTrait, UsersEditingTrait
Edit user controller.
Tags
Table of Contents
Properties
- $Input : Input
- $Languages : Languages
- $preventUpdateFields : array<string|int, mixed>
- $runnedCronResult : array<string|int, mixed>
- $totalLoggedInSessions : int
- $userSessionCookieData : array<string|int, mixed>
Methods
- __construct() : mixed
- {@inheritDoc}
- doUpdateAction() : string
- Update user data.
- indexAction() : string
- Edit user page.
- addUpdateUserFormValidation() : array<string|int, mixed>
- Form validation for add and update user.
- checkLogin() : mixed
- Check for logged in, if not then redirect to login page.
- checkPermission() : mixed
- Check permission and (redirect OR response error message).
- decryptUserFieldsKey() : string
- Decrypt user fields key.
- doConfirmChangeEmail() : array<string|int, mixed>
- Confirm change email.
- doUpdateAddChangedEmailToHistoryVar() : array<string|int, mixed>
- Add previous email to history variable that is ready to update in next step.
- doUpdateGetData() : array<string|int, mixed>
- Get and set data for `users` table.
- doUpdateGetDataFields() : array<string|int, mixed>
- Get and set data for `user_fields` table.
- doUpdateGetDataUsersRoles() : array<string|int, mixed>
- Get and set data for `users_roles` table.
- doUpdateRemoveUnchangableData() : mixed
- Remove unchangable data.
- doUpdateRemoveUnUpdatableDataFields() : mixed
- Remove fields that is unable to update manually to user_fields table.
- doUpdateSendEmailChanging() : array<string|int, mixed>
- Send email to notify or confirmation for changing email.
- generateUserFieldsKey() : array<string|int, mixed>
- Generate user fields key.
- getConfigDb() : array<string|int, mixed>
- Get config from DB.
- getConfigDbUser() : array<string|int, mixed>
- Get configuration from DB about user.
- getPageHtmlClasses() : string
- Get page HTML classes.
- getPageHtmlTitle() : string
- Get page HTML title including site name if it was set.
- getRdbAdminAssets() : array<string|int, mixed>
- Get RdbAdmin module's assets.
- getRoles() : array<string|int, mixed>
- Get list of roles (for display in select box in user management only).
- getUserUrlsMethods() : array<string|int, mixed>
- Get URLs and methods about user pages.
- isEditingHigherRole() : bool
- Check if target user has higher priority role than a user who is editing them.
- isMe() : bool
- Check that the specified `$user_id` is me or not.
- isUserLoggedIn() : bool
- Check if user is logged in.
- logoutUser() : mixed
- Logout target user.
- maybeRunCron() : mixed
- Maybe run cron job if config is set to not use server cron.
- responseJson() : string
- {@inheritDoc}
- responseXml() : string
- {@inheritDoc}
- sessionTraitLogoutAll() : mixed
- Logout all succeeded login sessions, lock user account, send login link to user's email.
- setBasicConfig() : mixed
- Setup basic PHP configurations such as default timezone.
- setCssAssets() : mixed
- Set CSS assets for common admin pages.
- setHeaderAllowOrigin() : mixed
- Set header allow origin for CORS.
- setJsAssetsAndObject() : mixed
- Set JS assets and its object for XHR common data.
- isModuleExcute() : bool
- Check if current call is `Modules->execute()`
- sessionsTraitCheckIsLoggedInFromContainer() : array<string|int, mixed>
- Check is logged in from container if exists.
- sessionTraitLogoutPreviousSessions() : mixed
- Logout all sessions before latest succeeded login. (logout only succeeded login).
Properties
$Input
protected
Input
$Input
$Languages
protected
Languages
$Languages
$preventUpdateFields
protected
array<string|int, mixed>
$preventUpdateFields
= ['rdbadmin_uf_adduser_waitactivation_since', 'rdbadmin_uf_admindashboardwidgets_order', 'rdbadmin_uf_changeemail_key', 'rdbadmin_uf_changeemail_time', 'rdbadmin_uf_changeemail_value', 'rdbadmin_uf_changeemail_history', 'rdbadmin_uf_login2stepverification_key', 'rdbadmin_uf_login2stepverification_time', 'rdbadmin_uf_login2stepverification_tmpdata', 'rdbadmin_uf_registerconfirm_key', 'rdbadmin_uf_resetpassword_key', 'rdbadmin_uf_resetpassword_time', 'rdbadmin_uf_simultaneouslogin_reset_key', 'rdbadmin_uf_simultaneouslogin_reset_time', 'rdbadmin_uf_avatar']
User fields that must not be update via the REST API (at least with this controller). refer these fields from UserFIeldsDb->rdbaUserFields
property.
$runnedCronResult
protected
array<string|int, mixed>
$runnedCronResult
= []
Runned cron jobs result.
This is for use in case that set cron job, cron tab to run by URL.
The CronController
will be call to this BaseController
.
So, it is no need to using Libraries\Cron
class to run jobs again.
Just get the run result from this property.
This property will be set by maybeRunCron()
method.
$totalLoggedInSessions
protected
int
$totalLoggedInSessions
= 0
The number of sessions that found this user logged in. This property is able to access after called to isUserLoggedIn()
method.
$userSessionCookieData
protected
array<string|int, mixed>
$userSessionCookieData
= []
The cookie data of logged in user. This property is able to access after called to isUserLoggedIn()
method.
Methods
__construct()
{@inheritDoc}
public
__construct(Container $Container) : mixed
Parameters
- $Container : Container
doUpdateAction()
Update user data.
public
doUpdateAction([string $user_id = '' ]) : string
Parameters
- $user_id : string = ''
Return values
stringindexAction()
Edit user page.
public
indexAction([string $user_id = '' ]) : string
Parameters
- $user_id : string = ''
Return values
stringaddUpdateUserFormValidation()
Form validation for add and update user.
protected
addUpdateUserFormValidation(array<string|int, mixed> $data[, array<string|int, mixed> $dataField = [] ][, array<string|int, mixed> $dataUsersRoles = [] ][, string $saveType = 'insert' ][, string|int $user_id = '' ]) : array<string|int, mixed>
Validate required and valid form fields.
Validate that selected roles did not have higher priority that the user who add or update them.
Validate username and email must not exists.
This method was called from doAddAction()
method.
Parameters
- $data : array<string|int, mixed>
-
The associative array form data.
- $dataField : array<string|int, mixed> = []
-
Associative array for
user_fields
table. - $dataUsersRoles : array<string|int, mixed> = []
-
Associative array for
users_roles
table. - $saveType : string = 'insert'
-
Type of saving data. It can be 'insert' or 'update'. Default is 'insert'.
- $user_id : string|int = ''
-
The
user_id
to check where$saveType
is 'update' that any user else data must be unique.
Return values
array<string|int, mixed> —Return associative array with keys if contain at least one error:
formResultStatus
(if error),
formResultMessage
(if error) The result message,
formFieldsValidation
(optional) Fields that contain errors,
responseStatus
(optional) For HTTP response status,
checkLogin()
Check for logged in, if not then redirect to login page.
protected
checkLogin() : mixed
checkPermission()
Check permission and (redirect OR response error message).
protected
checkPermission(string $moduleSystemName, string $page, string|array<string|int, mixed> $action[, array<string|int, mixed> $identity = [] ]) : mixed
This will be redirect user to /admin page if request from web page.
This will be response error message if request via REST API or AJAX.
Parameters
- $moduleSystemName : string
-
The module (module system name or folder name) to check.
- $page : string
-
The page name to check.
- $action : string|array<string|int, mixed>
-
The action(s) on that page. Use string if check for single action, use array if check for multiple actions.
If checking for multiple actions, any single action matched with certain module, page will be returntrue
. - $identity : array<string|int, mixed> = []
-
The associative array of identity.
Tags
decryptUserFieldsKey()
Decrypt user fields key.
protected
decryptUserFieldsKey(string|object $encryptedKey) : string
Parameters
- $encryptedKey : string|object
-
The encrypted key string. Or you may set user_fields object from PDO query instead.
Return values
string —Return decrypted key string or return empty string if failed to decrypted.
doConfirmChangeEmail()
Confirm change email.
protected
doConfirmChangeEmail(int $user_id, mixed $token) : array<string|int, mixed>
This method was called from indexAction()
method.
Parameters
- $user_id : int
- $token : mixed
Return values
array<string|int, mixed> —Return associative array with keys:
formResultStatus
(error or success),
formResultMessage
(error or success),
responseStatus
(error only),
doUpdateAddChangedEmailToHistoryVar()
Add previous email to history variable that is ready to update in next step.
protected
doUpdateAddChangedEmailToHistoryVar(int $user_id, string $previousEmail) : array<string|int, mixed>
This method was called from doUpdateAction()
, doConfirmChangeEmail()
methods.
Parameters
- $user_id : int
- $previousEmail : string
Return values
array<string|int, mixed> —Return added previous email to array that key is field name and ready to update.
doUpdateGetData()
Get and set data for `users` table.
protected
doUpdateGetData() : array<string|int, mixed>
This method was called from doUpdateAction()
method.
Tags
Return values
array<string|int, mixed>doUpdateGetDataFields()
Get and set data for `user_fields` table.
protected
doUpdateGetDataFields() : array<string|int, mixed>
This method was called from doUpdateAction()
method.
Tags
Return values
array<string|int, mixed>doUpdateGetDataUsersRoles()
Get and set data for `users_roles` table.
protected
doUpdateGetDataUsersRoles(int $user_id) : array<string|int, mixed>
This method was called from doUpdateAction()
method.
Parameters
- $user_id : int
-
Selected user ID.
Tags
Return values
array<string|int, mixed>doUpdateRemoveUnchangableData()
Remove unchangable data.
protected
doUpdateRemoveUnchangableData(array<string|int, mixed> &$data) : mixed
Remove data that contain column name that must not be update.
Or remove data that there is no this column name in users
table.
This method was called from doUpdateAction()
method.
Parameters
- $data : array<string|int, mixed>
doUpdateRemoveUnUpdatableDataFields()
Remove fields that is unable to update manually to user_fields table.
protected
doUpdateRemoveUnUpdatableDataFields(array<string|int, mixed> &$dataFields) : mixed
This method was called from doUpdateAction()
method.
Parameters
- $dataFields : array<string|int, mixed>
doUpdateSendEmailChanging()
Send email to notify or confirmation for changing email.
protected
doUpdateSendEmailChanging([array<string|int, mixed> $options = [] ]) : array<string|int, mixed>
Send an email to request confirmation for changing self email.
Or send a notification email for changing others email.
Parameters
- $options : array<string|int, mixed> = []
-
The options keys:
'changeEmailOf' (required) value is 'self', 'other'.
'user_id' (required) Target user ID.
'user_login' (required) Target username.
'user_email' (required) Target email.
Below is for send verification emails (email require confirm link clicked).
'readableChangeEmailKey' For change self email that must click on confirmation link with key only.
Below is for send notification emails.
'previous_email' For send to notify change 'other' email by sending to their previous email. An error will be thrown if not specify for send notify email.
'admin_email' For send to notify change 'other' email.
Tags
Return values
array<string|int, mixed> —Return associative array with keys:
success
(success only),
formResultStatus
(error only),
formResultMessage
(error only) The result message,
responseStatus
(error only) For HTTP response status,
generateUserFieldsKey()
Generate user fields key.
protected
generateUserFieldsKey([int $length = 8 ]) : array<string|int, mixed>
Generate keys that can be use in change email confirmation, register confirmation, etc.
Parameters
- $length : int = 8
-
The length of key.
Return values
array<string|int, mixed> —Return associative array with 'readableKey', 'encryptedKey' keys.
getConfigDb()
Get config from DB.
protected
getConfigDb() : array<string|int, mixed>
This will get commonly used between admin controllers with these data.
rdbadmin_SiteName, rdbadmin_SiteTimezone, rdbadmin_AdminItemsPerPage,
Return values
array<string|int, mixed>getConfigDbUser()
Get configuration from DB about user.
protected
getConfigDbUser() : array<string|int, mixed>
Return values
array<string|int, mixed>getPageHtmlClasses()
Get page HTML classes.
protected
getPageHtmlClasses([array<string|int, mixed> $classes = [] ]) : string
Parameters
- $classes : array<string|int, mixed> = []
-
The classes to set for this html page.
Tags
Return values
string —Return generated html classes names.
getPageHtmlTitle()
Get page HTML title including site name if it was set.
protected
getPageHtmlTitle(string $title[, string|null|false $siteName = false ]) : string
Parameters
- $title : string
-
The site title.
- $siteName : string|null|false = false
-
Site name should be string.
Set to empty string ornull
will not include the site name.
Set tofalse
to automatic get the site name from config DB.
Tags
Return values
stringgetRdbAdminAssets()
Get RdbAdmin module's assets.
protected
getRdbAdminAssets() : array<string|int, mixed>
These contain the assets that is required for admin page to work.
Return values
array<string|int, mixed> —Return associative array with 'css' and 'js' in keys.
getRoles()
Get list of roles (for display in select box in user management only).
protected
getRoles() : array<string|int, mixed>
Return values
array<string|int, mixed>getUserUrlsMethods()
Get URLs and methods about user pages.
protected
getUserUrlsMethods([string $user_id = '' ]) : array<string|int, mixed>
Parameters
- $user_id : string = ''
-
The user ID.
Return values
array<string|int, mixed> —Return associative array.
isEditingHigherRole()
Check if target user has higher priority role than a user who is editing them.
protected
isEditingHigherRole(string|int $user_id) : bool
Parameters
- $user_id : string|int
-
The target user ID.
Return values
bool —Return false
if not editing higher priority role, return true
if yes.
isMe()
Check that the specified `$user_id` is me or not.
protected
isMe(string|int $user_id) : bool
Parameters
- $user_id : string|int
-
User ID to check. Cannot leave blank!
Return values
bool —Return true
if it was me, false
if not.
isUserLoggedIn()
Check if user is logged in.
protected
isUserLoggedIn([int $user_id = null ][, string $userlogin_session_key = '' ]) : bool
After called this method and it was true
then you can access total sessions via totalLoggedInSessions
property.
After called this method and cookie is valid then you can access cookie data via userSessionCookieData
property.
If there is simultaneous login and user's setting is something that is not allowed (such as logout previous, logout all), it will be process here.
Parameters
- $user_id : int = null
-
The user ID. Set to
null
(default) to auto detect from cookie. - $userlogin_session_key : string = ''
-
The logged in session key. Set to empty string (default) to auto detect from cookie.
Return values
bool —Return true
if logged in, false
for not.
logoutUser()
Logout target user.
protected
logoutUser([array<string|int, mixed> $cookieData = [] ][, bool $logoutAllDevice = false ]) : mixed
Parameters
- $cookieData : array<string|int, mixed> = []
-
The associative array of cookie data. This value can get from
Cookie
class. The array keys are:
user_id
(required).
sessionKey
(optional) For delete specific session key fromuser_logins
table. - $logoutAllDevice : bool = false
-
Set to
true
to logout all device,false
for specific session key.
maybeRunCron()
Maybe run cron job if config is set to not use server cron.
protected
maybeRunCron() : mixed
responseJson()
{@inheritDoc}
protected
responseJson(mixed $output) : string
Parameters
- $output : mixed
Return values
stringresponseXml()
{@inheritDoc}
protected
responseXml(mixed $output) : string
Parameters
- $output : mixed
Return values
stringsessionTraitLogoutAll()
Logout all succeeded login sessions, lock user account, send login link to user's email.
protected
sessionTraitLogoutAll(int $user_id, UserLoginsDb $UserLoginsDb, UserFieldsDb $UserFieldsDb) : mixed
This method also set cache that email was sent recently.
This method was called from isUserLoggedIn()
.
This method was called from LoginController->doLogin()
.
Parameters
- $user_id : int
- $UserLoginsDb : UserLoginsDb
- $UserFieldsDb : UserFieldsDb
setBasicConfig()
Setup basic PHP configurations such as default timezone.
protected
setBasicConfig() : mixed
setCssAssets()
Set CSS assets for common admin pages.
protected
setCssAssets(Assets $Assets, array<string|int, mixed> $assetsData) : mixed
This is required to make basic admin pages working correctly.
Parameters
- $Assets : Assets
-
The Assets class.
- $assetsData : array<string|int, mixed>
-
The assets data. Please read more on
\Rdb\Modules\RdbAdmin\Libraries\Assets::addMultipleAssets()
.
setHeaderAllowOrigin()
Set header allow origin for CORS.
protected
setHeaderAllowOrigin() : mixed
setJsAssetsAndObject()
Set JS assets and its object for XHR common data.
protected
setJsAssetsAndObject(Assets $Assets, array<string|int, mixed> $assetsData) : mixed
This is required to make basic admin pages working correctly.
Parameters
- $Assets : Assets
-
The Assets class.
- $assetsData : array<string|int, mixed>
-
The assets data. Please read more on
\Rdb\Modules\RdbAdmin\Libraries\Assets::addMultipleAssets()
.
isModuleExcute()
Check if current call is `Modules->execute()`
private
isModuleExcute() : bool
This method was called from maybeRunCron()
, __construct()
.
Tags
Return values
bool —Return true
if it is, false
if it is not.
sessionsTraitCheckIsLoggedInFromContainer()
Check is logged in from container if exists.
private
sessionsTraitCheckIsLoggedInFromContainer() : array<string|int, mixed>
The check data in container must not older than N seconds.
Tags
Return values
array<string|int, mixed> —Return indexed array where first index is UsersSessionsTrait
object in the container if exists. This value can be null
.
Second index is result of "is logged in". This value can be null
.
sessionTraitLogoutPreviousSessions()
Logout all sessions before latest succeeded login. (logout only succeeded login).
private
sessionTraitLogoutPreviousSessions(int $user_id, UserLoginsDb $UserLoginsDb) : mixed
This method was called from isUserLoggedIn()
.
Parameters
- $user_id : int
- $UserLoginsDb : UserLoginsDb