class UserCredentials in DRD Agent 8.3
Same name and namespace in other branches
- 4.0.x src/Agent/Action/UserCredentials.php \Drupal\drd_agent\Agent\Action\UserCredentials
Provides a 'UserCredentials' code.
Hierarchy
- class \Drupal\drd_agent\Agent\Action\Base implements ContainerInjectionInterface, BaseInterface
- class \Drupal\drd_agent\Agent\Action\UserCredentials
Expanded class hierarchy of UserCredentials
File
- src/
Agent/ Action/ UserCredentials.php, line 11
Namespace
Drupal\drd_agent\Agent\ActionView source
class UserCredentials extends Base {
/**
* {@inheritdoc}
*/
public function execute() {
$args = $this
->getArguments();
/** @var \Drupal\user\Entity\User $account */
$account = User::load($args['uid']);
if (!$account) {
$this->messenger
->addMessage('User does not exist.', 'error');
}
else {
$this
->setUsername($account, $args);
$this
->setPassword($account, $args);
$this
->setStatus($account, $args);
try {
$account
->save();
} catch (Exception $ex) {
$this->messenger
->addMessage('Changing user credentials failed.', 'error');
}
}
return [];
}
/**
* Callback to set the new username if it is not taken yet.
*
* @param \Drupal\user\Entity\User $account
* User account which should be changed.
* @param array $args
* Array of arguments.
*/
private function setUsername(User $account, array $args) {
if (empty($args['username'])) {
return;
}
$check = user_validate_name($args['username']);
if (!empty($check)) {
$this->messenger
->addMessage($check, 'error');
return;
}
$user = user_load_by_name($args['username']);
if (!empty($user) && $user->uid !== $args['uid']) {
$this->messenger
->addMessage('Username already taken.', 'error');
return;
}
$account
->setUsername($args['username']);
}
/**
* Callback to set the new password.
*
* @param \Drupal\user\Entity\User $account
* User account which should be changed.
* @param array $args
* Array of arguments.
*/
private function setPassword(User $account, array $args) {
if (empty($args['password'])) {
return;
}
$account
->setPassword($args['password']);
}
/**
* Callback to set the status of the user account.
*
* @param \Drupal\user\Entity\User $account
* User account which should be changed.
* @param array $args
* Array of arguments.
*/
private function setStatus(User $account, array $args) {
if (!isset($args['status'])) {
return;
}
if ($args['status']) {
$account
->activate();
}
else {
$account
->block();
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Base:: |
protected | property | ||
Base:: |
private | property | ||
Base:: |
protected | property | ||
Base:: |
protected | property | ||
Base:: |
protected | property | Crypt object for this DRD request. | |
Base:: |
protected | property | ||
Base:: |
private | property | ||
Base:: |
protected | property | ||
Base:: |
protected | property | ||
Base:: |
protected | property | ||
Base:: |
protected | property | ||
Base:: |
protected | property | ||
Base:: |
protected | property | ||
Base:: |
protected | property | ||
Base:: |
private | function | Authenticate the request or throw an exception. | |
Base:: |
public | function |
Authorize the DRD instance, all validations have passed successfully. Overrides BaseInterface:: |
|
Base:: |
public | function | Callback to authorize a DRD instance with a given secret. | |
Base:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
Base:: |
public | function |
Get the arguments for this request. Overrides BaseInterface:: |
|
Base:: |
public | function |
Get authorised Crypt object or FALSE if none is available. Overrides BaseInterface:: |
|
Base:: |
public | function |
Get an array of database connection information. Overrides BaseInterface:: |
|
Base:: |
public | function |
Get the debug mode. Overrides BaseInterface:: |
|
Base:: |
public | function |
Overrides BaseInterface:: |
|
Base:: |
public | function |
Overrides BaseInterface:: |
|
Base:: |
public | function |
Validate a one-time-token. Overrides BaseInterface:: |
|
Base:: |
public | function |
Change current session to user 1. Overrides BaseInterface:: |
|
Base:: |
private | function | Read and decode the input from the POST request. | |
Base:: |
public | function |
Overrides BaseInterface:: |
|
Base:: |
public | function | Main callback to execute an action. | |
Base:: |
constant | |||
Base:: |
constant | |||
Base:: |
constant | |||
Base:: |
public | function |
Set the debug mode. Overrides BaseInterface:: |
|
Base:: |
private | function | Recursivly convert request arguments to an array. | |
Base:: |
public | function |
Logging if in debug mode. Overrides BaseInterface:: |
|
Base:: |
public | function | Base constructor. | |
UserCredentials:: |
public | function |
Execute an action. Overrides Base:: |
|
UserCredentials:: |
private | function | Callback to set the new password. | |
UserCredentials:: |
private | function | Callback to set the status of the user account. | |
UserCredentials:: |
private | function | Callback to set the new username if it is not taken yet. |