Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
User Class Reference
Inheritance diagram for User:
AbstractModel StorageInterface UserInterface DataObject

Public Member Functions

 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\User\Helper\Data $userData, \Magento\Backend\App\ConfigInterface $config, \Magento\Framework\Validator\DataObjectFactory $validatorObjectFactory, \Magento\Authorization\Model\RoleFactory $roleFactory, \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder, \Magento\Framework\Encryption\EncryptorInterface $encryptor, \Magento\Store\Model\StoreManagerInterface $storeManager, UserValidationRules $validationRules, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[], Json $serializer=null, DeploymentConfig $deploymentConfig=null, ?NotificatorInterface $notificator=null)
 
 __sleep ()
 
 __wakeup ()
 
 beforeSave ()
 
 afterSave ()
 
 saveExtra ($data)
 
 getRoles ()
 
 getRole ()
 
 deleteFromRole ()
 
 roleUserExists ()
 
 sendPasswordResetConfirmationEmail ()
 
 sendPasswordResetNotificationEmail ()
 
 sendNotificationEmailsIfRequired ()
 
 getName ($separator=' ')
 
 getAclRole ()
 
 authenticate ($username, $password)
 
 verifyIdentity ($password)
 
 login ($username, $password)
 
 reload ()
 
 loadByUsername ($username)
 
 hasAssigned2Role ($user)
 
 changeResetPasswordLinkToken ($newToken)
 
 isResetPasswordLinkTokenExpired ()
 
 hasAvailableResources ()
 
 setHasAvailableResources ($hasResources)
 
 getFirstName ()
 
 setFirstName ($firstName)
 
 getLastName ()
 
 setLastName ($lastName)
 
 getEmail ()
 
 setEmail ($email)
 
 getUserName ()
 
 setUserName ($userName)
 
 getPassword ()
 
 setPassword ($password)
 
 getCreated ()
 
 setCreated ($created)
 
 getModified ()
 
 setModified ($modified)
 
 getIsActive ()
 
 setIsActive ($isActive)
 
 getInterfaceLocale ()
 
 setInterfaceLocale ($interfaceLocale)
 
 performIdentityCheck ($passwordString)
 
- Public Member Functions inherited from AbstractModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 __sleep ()
 
 __wakeup ()
 
 setIdFieldName ($name)
 
 getIdFieldName ()
 
 getId ()
 
 setId ($value)
 
 isDeleted ($isDeleted=null)
 
 hasDataChanges ()
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 setDataChanges ($value)
 
 getOrigData ($key=null)
 
 setOrigData ($key=null, $data=null)
 
 dataHasChangedFor ($field)
 
 getResourceName ()
 
 getResourceCollection ()
 
 getCollection ()
 
 load ($modelId, $field=null)
 
 beforeLoad ($identifier, $field=null)
 
 afterLoad ()
 
 isSaveAllowed ()
 
 setHasDataChanges ($flag)
 
 save ()
 
 afterCommitCallback ()
 
 isObjectNew ($flag=null)
 
 beforeSave ()
 
 validateBeforeSave ()
 
 getCacheTags ()
 
 cleanModelCache ()
 
 afterSave ()
 
 delete ()
 
 beforeDelete ()
 
 afterDelete ()
 
 afterDeleteCommit ()
 
 getResource ()
 
 getEntityId ()
 
 setEntityId ($entityId)
 
 clearInstance ()
 
 getStoredData ()
 
 getEventPrefix ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 
- Public Member Functions inherited from UserInterface
 getId ()
 
 setId ($id)
 

Data Fields

const XML_PATH_FORGOT_EMAIL_TEMPLATE = 'admin/emails/forgot_email_template'
 
const XML_PATH_FORGOT_EMAIL_IDENTITY = 'admin/emails/forgot_email_identity'
 
const XML_PATH_USER_NOTIFICATION_TEMPLATE = 'admin/emails/user_notification_template'
 
const XML_PATH_RESET_PASSWORD_TEMPLATE = 'admin/emails/reset_password_template'
 
const MESSAGE_ID_PASSWORD_EXPIRED = 'magento_user_password_expired'
 

Protected Member Functions

 _construct ()
 
 _willSavePassword ()
 
 validatePasswordChange ()
 
 createChangesDescriptionString ()
 
 sendUserNotificationEmail ($changes, $email=null)
 
 _getEncodedPassword ($password)
 
- Protected Member Functions inherited from AbstractModel
 _construct ()
 
 _init ($resourceModel)
 
 _setResourceModel ($resourceName, $collectionName=null)
 
 _getResource ()
 
 _getEventData ()
 
 _beforeLoad ($modelId, $field=null)
 
 _afterLoad ()
 
 _hasModelChanged ()
 
 _getValidatorBeforeSave ()
 
 _createValidatorBeforeSave ()
 
 _getValidationRulesBeforeSave ()
 
 _clearReferences ()
 
 _clearData ()
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $_eventPrefix = 'admin_user'
 
 $_role
 
 $_hasResources = true
 
 $_userData = null
 
 $_config
 
 $_validatorObject
 
 $_roleFactory
 
 $_encryptor
 
 $_transportBuilder
 
 $_storeManager
 
 $validationRules
 
- Protected Attributes inherited from AbstractModel
 $_eventPrefix = 'core_abstract'
 
 $_eventObject = 'object'
 
 $_idFieldName = 'id'
 
 $_hasDataChanges = false
 
 $_origData
 
 $_isDeleted = false
 
 $_resource
 
 $_resourceCollection
 
 $_resourceName
 
 $_collectionName
 
 $_cacheTag = false
 
 $_dataSaveAllowed = true
 
 $_isObjectNew = null
 
 $_validatorBeforeSave = null
 
 $_eventManager
 
 $_cacheManager
 
 $_registry
 
 $_logger
 
 $_appState
 
 $_actionValidator
 
 $storedData = []
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Admin user model

@api @method string getLogdate() @method \Magento\User\Model\User setLogdate(string $value) @method int getLognum() @method \Magento\User\Model\User setLognum(int $value) @method int getReloadAclFlag() @method \Magento\User\Model\User setReloadAclFlag(int $value) @method string getExtra() @method \Magento\User\Model\User setExtra(string $value) @SuppressWarnings(PHPMD.CouplingBetweenObjects) @SuppressWarnings(PHPMD.ExcessiveClassComplexity) @SuppressWarnings(PHPMD.LongVariable) @SuppressWarnings(PHPMD.ExcessivePublicCount) @api

Since
100.0.2

Definition at line 38 of file User.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Model\Context  $context,
\Magento\Framework\Registry  $registry,
\Magento\User\Helper\Data  $userData,
\Magento\Backend\App\ConfigInterface  $config,
\Magento\Framework\Validator\DataObjectFactory  $validatorObjectFactory,
\Magento\Authorization\Model\RoleFactory  $roleFactory,
\Magento\Framework\Mail\Template\TransportBuilder  $transportBuilder,
\Magento\Framework\Encryption\EncryptorInterface  $encryptor,
\Magento\Store\Model\StoreManagerInterface  $storeManager,
UserValidationRules  $validationRules,
\Magento\Framework\Model\ResourceModel\AbstractResource  $resource = null,
\Magento\Framework\Data\Collection\AbstractDb  $resourceCollection = null,
array  $data = [],
Json  $serializer = null,
DeploymentConfig  $deploymentConfig = null,
?NotificatorInterface  $notificator = null 
)
Parameters
\Magento\Framework\Model\Context$context
\Magento\Framework\Registry$registry
\Magento\User\Helper\Data$userData
\Magento\Backend\App\ConfigInterface$config
\Magento\Framework\Validator\DataObjectFactory$validatorObjectFactory
\Magento\Authorization\Model\RoleFactory$roleFactory
\Magento\Framework\Mail\Template\TransportBuilder$transportBuilder
\Magento\Framework\Encryption\EncryptorInterface$encryptor
\Magento\Store\Model\StoreManagerInterface$storeManager
UserValidationRules$validationRules
\Magento\Framework\Model\ResourceModel\AbstractResource$resource
\Magento\Framework\Data\Collection\AbstractDb$resourceCollection
array$data
Json$serializer
DeploymentConfig | null$deploymentConfig
NotificatorInterface | null$notificator@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 166 of file User.php.

183  {
184  $this->_encryptor = $encryptor;
185  parent::__construct($context, $registry, $resource, $resourceCollection, $data);
186  $this->_userData = $userData;
187  $this->_config = $config;
188  $this->_validatorObject = $validatorObjectFactory;
189  $this->_roleFactory = $roleFactory;
190  $this->_transportBuilder = $transportBuilder;
191  $this->_storeManager = $storeManager;
192  $this->validationRules = $validationRules;
193  $this->serializer = $serializer
194  ?: ObjectManager::getInstance()->get(Json::class);
195  $this->deploymentConfig = $deploymentConfig
196  ?: ObjectManager::getInstance()->get(DeploymentConfig::class);
197  $this->notificator = $notificator
198  ?: ObjectManager::getInstance()->get(NotificatorInterface::class);
199  }
$config
Definition: fraud_order.php:17
$storeManager
$resource
Definition: bulk.php:12
$deploymentConfig

Member Function Documentation

◆ __sleep()

__sleep ( )

Removing dependencies and leaving only entity's properties.

Returns
string[]

Definition at line 216 of file User.php.

217  {
219  return array_diff(
220  $properties,
221  [
222  '_eventManager',
223  '_userData',
224  '_config',
225  '_validatorObject',
226  '_roleFactory',
227  '_encryptor',
228  '_transportBuilder',
229  '_storeManager',
230  '_validatorBeforeSave',
231  'validationRules',
232  'serializer',
233  'deploymentConfig',
234  'notificator'
235  ]
236  );
237  }
$properties
Definition: categories.php:26

◆ __wakeup()

__wakeup ( )

Restoring required objects after serialization.

Returns
void

Definition at line 244 of file User.php.

245  {
248  $this->serializer = $objectManager->get(Json::class);
249  $this->_eventManager = $objectManager->get(\Magento\Framework\Event\ManagerInterface::class);
250  $this->_userData = $objectManager->get(\Magento\User\Helper\Data::class);
251  $this->_config = $objectManager->get(\Magento\Backend\App\ConfigInterface::class);
252  $this->_registry = $objectManager->get(\Magento\Framework\Registry::class);
253  $this->_validatorObject = $objectManager->get(\Magento\Framework\Validator\DataObjectFactory::class);
254  $this->_roleFactory = $objectManager->get(\Magento\Authorization\Model\RoleFactory::class);
255  $this->_encryptor = $objectManager->get(\Magento\Framework\Encryption\EncryptorInterface::class);
256  $this->_transportBuilder = $objectManager->get(\Magento\Framework\Mail\Template\TransportBuilder::class);
257  $this->_storeManager = $objectManager->get(\Magento\Store\Model\StoreManagerInterface::class);
258  $this->validationRules = $objectManager->get(UserValidationRules::class);
259  $this->deploymentConfig = $objectManager->get(DeploymentConfig::class);
260  $this->notificator = $objectManager->get(NotificatorInterface::class);
261  }
$objectManager
Definition: bootstrap.php:17

◆ _construct()

_construct ( )
protected

Initialize user model

Returns
void

Definition at line 206 of file User.php.

207  {
208  $this->_init(\Magento\User\Model\ResourceModel\User::class);
209  }

◆ _getEncodedPassword()

_getEncodedPassword (   $password)
protected

Retrieve encoded password

Parameters
string$password
Returns
string

Definition at line 683 of file User.php.

684  {
685  return $this->_encryptor->getHash($password, true);
686  }

◆ _willSavePassword()

_willSavePassword ( )
protected

Whether the password saving is going to occur

Returns
bool

Definition at line 292 of file User.php.

293  {
294  return $this->isObjectNew() || $this->hasData('password') && $this->dataHasChangedFor('password');
295  }

◆ afterSave()

afterSave ( )

Process data after model is saved

Returns
$this

Definition at line 371 of file User.php.

372  {
373  $this->_role = null;
374  return parent::afterSave();
375  }

◆ authenticate()

authenticate (   $username,
  $password 
)

Authenticate user name and password and save loaded record

Parameters
string$username
string$password
Returns
bool
Exceptions

Implements StorageInterface.

Definition at line 564 of file User.php.

565  {
566  $config = $this->_config->isSetFlag('admin/security/use_case_sensitive_login');
567  $result = false;
568 
569  try {
570  $this->_eventManager->dispatch(
571  'admin_user_authenticate_before',
572  ['username' => $username, 'user' => $this]
573  );
574  $this->loadByUsername($username);
575  $sensitive = $config ? $username == $this->getUserName() : true;
576  if ($sensitive && $this->getId()) {
577  $result = $this->verifyIdentity($password);
578  }
579 
580  $this->_eventManager->dispatch(
581  'admin_user_authenticate_after',
582  ['username' => $username, 'password' => $password, 'user' => $this, 'result' => $result]
583  );
584  } catch (\Magento\Framework\Exception\LocalizedException $e) {
585  $this->unsetData();
586  throw $e;
587  }
588 
589  if (!$result) {
590  $this->unsetData();
591  }
592  return $result;
593  }
$config
Definition: fraud_order.php:17
verifyIdentity($password)
Definition: User.php:602
loadByUsername($username)
Definition: User.php:656

◆ beforeSave()

beforeSave ( )

Processing data before model save

Returns
$this

Definition at line 268 of file User.php.

269  {
270  $data = [
271  'extra' => $this->serializer->serialize($this->getExtra()),
272  ];
273 
274  if ($this->_willSavePassword()) {
275  $data['password'] = $this->_getEncodedPassword($this->getPassword());
276  }
277 
278  if ($this->getIsActive() !== null) {
279  $data['is_active'] = intval($this->getIsActive());
280  }
281 
282  $this->addData($data);
283 
284  return parent::beforeSave();
285  }
_getEncodedPassword($password)
Definition: User.php:683

◆ changeResetPasswordLinkToken()

changeResetPasswordLinkToken (   $newToken)

Change reset password link token

Stores new reset password link token and its creation time

Parameters
string$newToken
Returns
$this
Exceptions

Definition at line 697 of file User.php.

698  {
699  if (!is_string($newToken) || empty($newToken)) {
700  throw new \Magento\Framework\Exception\LocalizedException(
701  __('The password reset token is incorrect. Verify the token and try again.')
702  );
703  }
704  $this->setRpToken($newToken);
705  $this->setRpTokenCreatedAt((new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT));
706 
707  return $this;
708  }
__()
Definition: __.php:13

◆ createChangesDescriptionString()

createChangesDescriptionString ( )
protected

Create changes description string

Returns
string
Since
100.1.0

Definition at line 495 of file User.php.

496  {
497  $changes = [];
498 
499  if ($this->getEmail() != $this->getOrigData('email') && $this->getOrigData('email')) {
500  $changes[] = __('email');
501  }
502 
503  if ($this->getPassword()
504  && $this->getOrigData('password')
505  && $this->getPassword() != $this->getOrigData('password')) {
506  $changes[] = __('password');
507  }
508 
509  if ($this->getUserName() != $this->getOrigData('username') && $this->getOrigData('username')) {
510  $changes[] = __('username');
511  }
512 
513  return implode(', ', $changes);
514  }
__()
Definition: __.php:13

◆ deleteFromRole()

deleteFromRole ( )

Unassign user from his current role

Returns
$this

Definition at line 424 of file User.php.

425  {
426  $this->_getResource()->deleteFromRole($this);
427  return $this;
428  }

◆ getAclRole()

getAclRole ( )

Get user ACL role

Returns
string

Definition at line 551 of file User.php.

552  {
553  return $this->getRole()->getId();
554  }

◆ getCreated()

getCreated ( )

@inheritDoc

Implements UserInterface.

Definition at line 845 of file User.php.

846  {
847  return $this->_getData('created');
848  }

◆ getEmail()

getEmail ( )

@inheritDoc

Implements UserInterface.

Definition at line 797 of file User.php.

798  {
799  return $this->_getData('email');
800  }

◆ getFirstName()

getFirstName ( )

@inheritDoc

Implements UserInterface.

Definition at line 765 of file User.php.

766  {
767  return $this->_getData('firstname');
768  }

◆ getInterfaceLocale()

getInterfaceLocale ( )

@inheritDoc

Implements UserInterface.

Definition at line 893 of file User.php.

894  {
895  return $this->_getData('interface_locale');
896  }

◆ getIsActive()

getIsActive ( )

@inheritDoc

Implements UserInterface.

Definition at line 877 of file User.php.

878  {
879  return $this->_getData('is_active');
880  }

◆ getLastName()

getLastName ( )

@inheritDoc

Implements UserInterface.

Definition at line 781 of file User.php.

782  {
783  return $this->_getData('lastname');
784  }

◆ getModified()

getModified ( )

@inheritDoc

Implements UserInterface.

Definition at line 861 of file User.php.

862  {
863  return $this->_getData('modified');
864  }

◆ getName()

getName (   $separator = ' ')

Retrieve user name

Parameters
string$separator
Returns
string

Definition at line 541 of file User.php.

542  {
543  return $this->getFirstName() . $separator . $this->getLastName();
544  }

◆ getPassword()

getPassword ( )

@inheritDoc

Implements UserInterface.

Definition at line 829 of file User.php.

830  {
831  return $this->_getData('password');
832  }

◆ getRole()

getRole ( )

Get admin role model

Returns
\Magento\Authorization\Model\Role

Definition at line 407 of file User.php.

408  {
409  if (null === $this->_role) {
410  $this->_role = $this->_roleFactory->create();
411  $roles = $this->getRoles();
412  if ($roles && isset($roles[0]) && $roles[0]) {
413  $this->_role->load($roles[0]);
414  }
415  }
416  return $this->_role;
417  }

◆ getRoles()

getRoles ( )

Retrieve user roles

Returns
array

Definition at line 397 of file User.php.

398  {
399  return $this->_getResource()->getRoles($this);
400  }

◆ getUserName()

getUserName ( )

@inheritDoc

Implements UserInterface.

Definition at line 813 of file User.php.

814  {
815  return $this->_getData('username');
816  }

◆ hasAssigned2Role()

hasAssigned2Role (   $user)

Check if user is assigned to any role

Parameters
int | \Magento\User\Model\User$user
Returns
null|array

Definition at line 672 of file User.php.

673  {
674  return $this->getResource()->hasAssigned2Role($user);
675  }
$user
Definition: dummy_user.php:13

◆ hasAvailableResources()

hasAvailableResources ( )

Check if user has available resources

Returns
bool

Implements StorageInterface.

Definition at line 745 of file User.php.

746  {
747  return $this->_hasResources;
748  }

◆ isResetPasswordLinkTokenExpired()

isResetPasswordLinkTokenExpired ( )

Check if current reset password link token is expired

Returns
bool

Definition at line 715 of file User.php.

716  {
717  $linkToken = $this->getRpToken();
718  $linkTokenCreatedAt = $this->getRpTokenCreatedAt();
719 
720  if (empty($linkToken) || empty($linkTokenCreatedAt)) {
721  return true;
722  }
723 
724  $expirationPeriod = $this->_userData->getResetPasswordLinkExpirationPeriod();
725 
726  $currentTimestamp = (new \DateTime())->getTimestamp();
727  $tokenTimestamp = (new \DateTime($linkTokenCreatedAt))->getTimestamp();
728  if ($tokenTimestamp > $currentTimestamp) {
729  return true;
730  }
731 
732  $hourDifference = floor(($currentTimestamp - $tokenTimestamp) / (60 * 60));
733  if ($hourDifference >= $expirationPeriod) {
734  return true;
735  }
736 
737  return false;
738  }

◆ loadByUsername()

loadByUsername (   $username)

Load user by its username

Parameters
string$username
Returns
$this

Definition at line 656 of file User.php.

657  {
658  $data = $this->getResource()->loadByUsername($username);
659  if ($data !== false) {
660  $this->setData($data);
661  $this->setOrigData();
662  }
663  return $this;
664  }

◆ login()

login (   $username,
  $password 
)

Login user

Parameters
string$username
string$password
Returns
$this

Implements StorageInterface.

Definition at line 629 of file User.php.

630  {
631  if ($this->authenticate($username, $password)) {
632  $this->getResource()->recordLogin($this);
633  }
634  return $this;
635  }
authenticate($username, $password)
Definition: User.php:564

◆ performIdentityCheck()

performIdentityCheck (   $passwordString)

Security check for admin user

Parameters
string$passwordString
Returns
$this
Exceptions

Definition at line 915 of file User.php.

916  {
917  try {
918  $isCheckSuccessful = $this->verifyIdentity($passwordString);
919  } catch (\Magento\Framework\Exception\AuthenticationException $e) {
920  $isCheckSuccessful = false;
921  }
922  $this->_eventManager->dispatch(
923  'admin_user_authenticate_after',
924  [
925  'username' => $this->getUserName(),
926  'password' => $passwordString,
927  'user' => $this,
928  'result' => $isCheckSuccessful
929  ]
930  );
931  // Check if lock information has been updated in observers
932  $clonedUser = clone($this);
933  $clonedUser->reload();
934  if ($clonedUser->getLockExpires()) {
935  throw new \Magento\Framework\Exception\State\UserLockedException(
936  __('Your account is temporarily disabled. Please try again later.')
937  );
938  }
939 
940  if (!$isCheckSuccessful) {
941  throw new \Magento\Framework\Exception\AuthenticationException(
942  __('The password entered for the current user is invalid. Verify the password and try again.')
943  );
944  }
945 
946  return $this;
947  }
verifyIdentity($password)
Definition: User.php:602
__()
Definition: __.php:13

◆ reload()

reload ( )

Reload current user

Returns
$this

Implements StorageInterface.

Definition at line 642 of file User.php.

643  {
644  $userId = $this->getId();
645  $this->setId(null);
646  $this->load($userId);
647  return $this;
648  }

◆ roleUserExists()

roleUserExists ( )

Check if such combination role/user exists.

Returns
bool

Definition at line 435 of file User.php.

436  {
437  $result = $this->_getResource()->roleUserExists($this);
438  return is_array($result) && count($result) > 0 ? true : false;
439  }

◆ saveExtra()

saveExtra (   $data)

Save admin user extra data (like configuration sections state)

Parameters
array$data
Returns
$this

Definition at line 383 of file User.php.

384  {
385  if (is_array($data)) {
386  $data = $this->serializer->serialize($data);
387  }
388  $this->_getResource()->saveExtra($this, $data);
389  return $this;
390  }

◆ sendNotificationEmailsIfRequired()

sendNotificationEmailsIfRequired ( )

Check changes and send notification emails.

Exceptions
NotificationExceptionInterface
Returns
$this
Since
100.1.0

Definition at line 476 of file User.php.

477  {
478  if ($this->isObjectNew()) {
479  //Notification about a new user.
480  $this->notificator->sendCreated($this);
482  //User changed.
483  $this->notificator->sendUpdated($this, explode(', ', $changes));
484  }
485 
486  return $this;
487  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
createChangesDescriptionString()
Definition: User.php:495

◆ sendPasswordResetConfirmationEmail()

sendPasswordResetConfirmationEmail ( )

Send email with reset password confirmation link.

Deprecated:
See also
NotificatorInterface::sendForgotPassword()
Returns
$this

Definition at line 449 of file User.php.

450  {
451  $this->notificator->sendForgotPassword($this);
452 
453  return $this;
454  }

◆ sendPasswordResetNotificationEmail()

sendPasswordResetNotificationEmail ( )

Send email to when password is resetting

Exceptions
NotificationExceptionInterface
Returns
$this
Deprecated:
100.1.0

Definition at line 463 of file User.php.

464  {
466  return $this;
467  }
sendNotificationEmailsIfRequired()
Definition: User.php:476

◆ sendUserNotificationEmail()

sendUserNotificationEmail (   $changes,
  $email = null 
)
protected

Send user notification email.

Parameters
string$changes
string$email
Exceptions
NotificationExceptionInterface
Returns
$this
Since
100.1.0
Deprecated:
See also
NotificatorInterface::sendUpdated() @SuppressWarnings(PHPMD.UnusedFormalParameter)

Definition at line 528 of file User.php.

529  {
530  $this->notificator->sendUpdated($this, explode(', ', $changes));
531 
532  return $this;
533  }

◆ setCreated()

setCreated (   $created)

@inheritDoc

Implements UserInterface.

Definition at line 853 of file User.php.

854  {
855  return $this->setData('created', $created);
856  }

◆ setEmail()

setEmail (   $email)

@inheritDoc

Implements UserInterface.

Definition at line 805 of file User.php.

806  {
807  return $this->setData('email', $email);
808  }
$email
Definition: details.phtml:13

◆ setFirstName()

setFirstName (   $firstName)

@inheritDoc

Implements UserInterface.

Definition at line 773 of file User.php.

774  {
775  return $this->setData('firstname', $firstName);
776  }

◆ setHasAvailableResources()

setHasAvailableResources (   $hasResources)

Set user has available resources

Parameters
bool$hasResources
Returns
$this

Implements StorageInterface.

Definition at line 756 of file User.php.

757  {
758  $this->_hasResources = $hasResources;
759  return $this;
760  }

◆ setInterfaceLocale()

setInterfaceLocale (   $interfaceLocale)

@inheritDoc

Implements UserInterface.

Definition at line 901 of file User.php.

902  {
903  return $this->setData('interface_locale', $interfaceLocale);
904  }

◆ setIsActive()

setIsActive (   $isActive)

@inheritDoc

Implements UserInterface.

Definition at line 885 of file User.php.

886  {
887  return $this->setData('is_active', $isActive);
888  }

◆ setLastName()

setLastName (   $lastName)

@inheritDoc

Implements UserInterface.

Definition at line 789 of file User.php.

790  {
791  return $this->setData('lastname', $lastName);
792  }

◆ setModified()

setModified (   $modified)

@inheritDoc

Implements UserInterface.

Definition at line 869 of file User.php.

870  {
871  return $this->setData('modified', $modified);
872  }

◆ setPassword()

setPassword (   $password)

@inheritDoc

Implements UserInterface.

Definition at line 837 of file User.php.

838  {
839  return $this->setData('password', $password);
840  }

◆ setUserName()

setUserName (   $userName)

@inheritDoc

Implements UserInterface.

Definition at line 821 of file User.php.

822  {
823  return $this->setData('username', $userName);
824  }

◆ validatePasswordChange()

validatePasswordChange ( )
protected

Make sure admin password was changed.

New password is compared to at least 4 previous passwords to prevent setting them again

Returns
bool|string[]
Since
100.0.3

Definition at line 346 of file User.php.

347  {
348  $password = $this->getPassword();
349  if ($password && !$this->getForceNewPassword() && $this->getId()) {
350  $errorMessage = __('Sorry, but this password has already been used. Please create another.');
351  // Check if password is equal to the current one
352  if ($this->_encryptor->isValidHash($password, $this->getOrigData('password'))) {
353  return [$errorMessage];
354  }
355 
356  // Check whether password was used before
357  foreach ($this->getResource()->getOldPasswords($this) as $oldPasswordHash) {
358  if ($this->_encryptor->isValidHash($password, $oldPasswordHash)) {
359  return [$errorMessage];
360  }
361  }
362  }
363  return true;
364  }
__()
Definition: __.php:13

◆ verifyIdentity()

verifyIdentity (   $password)

Ensure that provided password matches the current user password. Check if the current user account is active.

Parameters
string$password
Returns
bool
Exceptions

Definition at line 602 of file User.php.

603  {
604  $result = false;
605  if ($this->_encryptor->validateHash($password, $this->getPassword())) {
606  if ($this->getIsActive() != '1') {
607  throw new AuthenticationException(
608  __(
609  'The account sign-in was incorrect or your account is disabled temporarily. '
610  . 'Please wait and try again later.'
611  )
612  );
613  }
614  if (!$this->hasAssigned2Role($this->getId())) {
615  throw new AuthenticationException(__('More permissions are needed to access this.'));
616  }
617  $result = true;
618  }
619  return $result;
620  }
__()
Definition: __.php:13
hasAssigned2Role($user)
Definition: User.php:672

Field Documentation

◆ $_config

$_config
protected

Definition at line 96 of file User.php.

◆ $_encryptor

$_encryptor
protected

Definition at line 115 of file User.php.

◆ $_eventPrefix

$_eventPrefix = 'admin_user'
protected

Definition at line 68 of file User.php.

◆ $_hasResources

$_hasResources = true
protected

Definition at line 82 of file User.php.

◆ $_role

$_role
protected

Definition at line 75 of file User.php.

◆ $_roleFactory

$_roleFactory
protected

Definition at line 110 of file User.php.

◆ $_storeManager

$_storeManager
protected
Deprecated:

Definition at line 125 of file User.php.

◆ $_transportBuilder

$_transportBuilder
protected
Deprecated:

Definition at line 120 of file User.php.

◆ $_userData

$_userData = null
protected

Definition at line 89 of file User.php.

◆ $_validatorObject

$_validatorObject
protected

Definition at line 103 of file User.php.

◆ $validationRules

$validationRules
protected

Definition at line 130 of file User.php.

◆ MESSAGE_ID_PASSWORD_EXPIRED

const MESSAGE_ID_PASSWORD_EXPIRED = 'magento_user_password_expired'

Definition at line 61 of file User.php.

◆ XML_PATH_FORGOT_EMAIL_IDENTITY

const XML_PATH_FORGOT_EMAIL_IDENTITY = 'admin/emails/forgot_email_identity'
Deprecated:
See also
\Magento\User\Model\Spi\NotificatorInterface

Definition at line 50 of file User.php.

◆ XML_PATH_FORGOT_EMAIL_TEMPLATE

const XML_PATH_FORGOT_EMAIL_TEMPLATE = 'admin/emails/forgot_email_template'
Deprecated:
See also
\Magento\User\Model\Spi\NotificatorInterface

Definition at line 44 of file User.php.

◆ XML_PATH_RESET_PASSWORD_TEMPLATE

const XML_PATH_RESET_PASSWORD_TEMPLATE = 'admin/emails/reset_password_template'
Deprecated:

Definition at line 59 of file User.php.

◆ XML_PATH_USER_NOTIFICATION_TEMPLATE

const XML_PATH_USER_NOTIFICATION_TEMPLATE = 'admin/emails/user_notification_template'
Deprecated:
See also
\Magento\User\Model\Spi\NotificatorInterface

Definition at line 56 of file User.php.


The documentation for this class was generated from the following file: