140 private $notificator;
145 private $deploymentConfig;
172 \
Magento\Authorization\Model\RoleFactory $roleFactory,
178 \
Magento\Framework\Data\Collection\AbstractDb $resourceCollection =
null,
180 Json $serializer =
null,
186 $this->_userData = $userData;
188 $this->_validatorObject = $validatorObjectFactory;
189 $this->_roleFactory = $roleFactory;
190 $this->_transportBuilder = $transportBuilder;
193 $this->serializer = $serializer
195 $this->deploymentConfig = $deploymentConfig
197 $this->notificator = $notificator
230 '_validatorBeforeSave',
256 $this->_transportBuilder =
$objectManager->get(\
Magento\Framework\Mail\Template\TransportBuilder::class);
258 $this->validationRules =
$objectManager->get(UserValidationRules::class);
259 $this->deploymentConfig =
$objectManager->get(DeploymentConfig::class);
260 $this->notificator =
$objectManager->get(NotificatorInterface::class);
271 'extra' => $this->serializer->serialize($this->getExtra()),
284 return parent::beforeSave();
305 $validator = $this->_validatorObject->create();
306 $this->validationRules->addUserInfoRules($validator);
310 $this->validationRules->addPasswordRules($validator);
311 if ($this->hasPasswordConfirmation()) {
312 $this->validationRules->addPasswordConfirmationRule($validator, $this->getPasswordConfirmation());
325 public function validate()
328 $validator = $this->_validatorObject->create();
329 $this->validationRules->addUserInfoRules($validator);
331 if (!$validator->isValid($this)) {
332 return $validator->getMessages();
349 if ($password && !$this->getForceNewPassword() && $this->
getId()) {
350 $errorMessage =
__(
'Sorry, but this password has already been used. Please create another.');
352 if ($this->_encryptor->isValidHash($password, $this->getOrigData(
'password'))) {
353 return [$errorMessage];
357 foreach ($this->
getResource()->getOldPasswords($this) as $oldPasswordHash) {
358 if ($this->_encryptor->isValidHash($password, $oldPasswordHash)) {
359 return [$errorMessage];
374 return parent::afterSave();
385 if (is_array(
$data)) {
409 if (
null === $this->_role) {
410 $this->_role = $this->_roleFactory->create();
412 if ($roles && isset($roles[0]) && $roles[0]) {
413 $this->_role->load($roles[0]);
451 $this->notificator->sendForgotPassword($this);
480 $this->notificator->sendCreated($this);
483 $this->notificator->sendUpdated($this, explode(
', ',
$changes));
530 $this->notificator->sendUpdated($this, explode(
', ',
$changes));
553 return $this->
getRole()->getId();
566 $config = $this->_config->isSetFlag(
'admin/security/use_case_sensitive_login');
570 $this->_eventManager->dispatch(
571 'admin_user_authenticate_before',
572 [
'username' => $username,
'user' => $this]
576 if ($sensitive && $this->
getId()) {
580 $this->_eventManager->dispatch(
581 'admin_user_authenticate_after',
582 [
'username' => $username,
'password' => $password,
'user' => $this,
'result' =>
$result]
605 if ($this->_encryptor->validateHash($password, $this->getPassword())) {
609 'The account sign-in was incorrect or your account is disabled temporarily. ' 610 .
'Please wait and try again later.' 629 public function login($username, $password)
644 $userId = $this->
getId();
646 $this->
load($userId);
659 if (
$data !==
false) {
685 return $this->_encryptor->getHash($password,
true);
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.')
704 $this->setRpToken($newToken);
705 $this->setRpTokenCreatedAt((
new \DateTime())->format(\
Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT));
717 $linkToken = $this->getRpToken();
718 $linkTokenCreatedAt = $this->getRpTokenCreatedAt();
720 if (empty($linkToken) || empty($linkTokenCreatedAt)) {
724 $expirationPeriod = $this->_userData->getResetPasswordLinkExpirationPeriod();
726 $currentTimestamp = (new \DateTime())->getTimestamp();
727 $tokenTimestamp = (new \DateTime($linkTokenCreatedAt))->getTimestamp();
728 if ($tokenTimestamp > $currentTimestamp) {
732 $hourDifference = floor(($currentTimestamp - $tokenTimestamp) / (60 * 60));
733 if ($hourDifference >= $expirationPeriod) {
758 $this->_hasResources = $hasResources;
767 return $this->
_getData(
'firstname');
775 return $this->
setData(
'firstname', $firstName);
791 return $this->
setData(
'lastname', $lastName);
839 return $this->
setData(
'password', $password);
855 return $this->
setData(
'created', $created);
871 return $this->
setData(
'modified', $modified);
879 return $this->
_getData(
'is_active');
887 return $this->
setData(
'is_active', $isActive);
895 return $this->
_getData(
'interface_locale');
903 return $this->
setData(
'interface_locale', $interfaceLocale);
920 $isCheckSuccessful =
false;
922 $this->_eventManager->dispatch(
923 'admin_user_authenticate_after',
926 'password' => $passwordString,
928 'result' => $isCheckSuccessful
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.')
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.')
setInterfaceLocale($interfaceLocale)
isResetPasswordLinkTokenExpired()
setData($key, $value=null)
elseif(isset( $params[ 'redirect_parent']))
sendPasswordResetNotificationEmail()
load($modelId, $field=null)
sendUserNotificationEmail($changes, $email=null)
verifyIdentity($password)
loadByUsername($username)
performIdentityCheck($passwordString)
authenticate($username, $password)
login($username, $password)
setHasAvailableResources($hasResources)
__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)
const XML_PATH_FORGOT_EMAIL_TEMPLATE
setOrigData($key=null, $data=null)
_getEncodedPassword($password)
const MESSAGE_ID_PASSWORD_EXPIRED
const XML_PATH_USER_NOTIFICATION_TEMPLATE
sendPasswordResetConfirmationEmail()
_getValidationRulesBeforeSave()
dataHasChangedFor($field)
sendNotificationEmailsIfRequired()
createChangesDescriptionString()
const XML_PATH_RESET_PASSWORD_TEMPLATE
const XML_PATH_FORGOT_EMAIL_IDENTITY
changeResetPasswordLinkToken($newToken)