5555use Magento \Store \Model \ScopeInterface ;
5656use Magento \Store \Model \StoreManagerInterface ;
5757use Psr \Log \LoggerInterface as PsrLogger ;
58+ use Magento \Framework \AuthorizationInterface ;
5859
5960/**
6061 * Handle various customer account actions
@@ -69,104 +70,104 @@ class AccountManagement implements AccountManagementInterface
6970 /**
7071 * Configuration paths for create account email template
7172 *
72- * @deprecated get rid of Helpers in Password Security Management.
73- * @see \Magento\Customer\Model\ EmailNotification::XML_PATH_REGISTER_EMAIL_TEMPLATE
73+ * @deprecated Get rid of Helpers in Password Security Management
74+ * @see EmailNotification::XML_PATH_REGISTER_EMAIL_TEMPLATE
7475 */
7576 const XML_PATH_REGISTER_EMAIL_TEMPLATE = 'customer/create_account/email_template ' ;
7677
7778 /**
7879 * Configuration paths for register no password email template
7980 *
80- * @deprecated get rid of Helpers in Password Security Management.
81- * @see \Magento\Customer\Model\ EmailNotification::XML_PATH_REGISTER_NO_PASSWORD_EMAIL_TEMPLATE
81+ * @deprecated Get rid of Helpers in Password Security Management
82+ * @see EmailNotification::XML_PATH_REGISTER_EMAIL_TEMPLATE
8283 */
8384 const XML_PATH_REGISTER_NO_PASSWORD_EMAIL_TEMPLATE = 'customer/create_account/email_no_password_template ' ;
8485
8586 /**
8687 * Configuration paths for remind email identity
8788 *
88- * @deprecated get rid of Helpers in Password Security Management.
89- * @see \Magento\Customer\Model\ EmailNotification::XML_PATH_REGISTER_EMAIL_IDENTITY
89+ * @deprecated Get rid of Helpers in Password Security Management
90+ * @see EmailNotification::XML_PATH_REGISTER_EMAIL_TEMPLATE
9091 */
9192 const XML_PATH_REGISTER_EMAIL_IDENTITY = 'customer/create_account/email_identity ' ;
9293
9394 /**
9495 * Configuration paths for remind email template
9596 *
96- * @deprecated get rid of Helpers in Password Security Management.
97- * @see \Magento\Customer\Model\ EmailNotification::XML_PATH_REMIND_EMAIL_TEMPLATE
97+ * @deprecated Get rid of Helpers in Password Security Management
98+ * @see EmailNotification::XML_PATH_REGISTER_EMAIL_TEMPLATE
9899 */
99100 const XML_PATH_REMIND_EMAIL_TEMPLATE = 'customer/password/remind_email_template ' ;
100101
101102 /**
102103 * Configuration paths for forgot email email template
103104 *
104- * @deprecated get rid of Helpers in Password Security Management.
105- * @see \Magento\Customer\Model\ EmailNotification::XML_PATH_FORGOT_EMAIL_TEMPLATE
105+ * @deprecated Get rid of Helpers in Password Security Management
106+ * @see EmailNotification::XML_PATH_REGISTER_EMAIL_TEMPLATE
106107 */
107108 const XML_PATH_FORGOT_EMAIL_TEMPLATE = 'customer/password/forgot_email_template ' ;
108109
109110 /**
110111 * Configuration paths for forgot email identity
111112 *
112- * @deprecated get rid of Helpers in Password Security Management.
113- * @see \Magento\Customer\Model\ EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY
113+ * @deprecated Get rid of Helpers in Password Security Management
114+ * @see EmailNotification::XML_PATH_REGISTER_EMAIL_TEMPLATE
114115 */
115116 const XML_PATH_FORGOT_EMAIL_IDENTITY = 'customer/password/forgot_email_identity ' ;
116117
117118 /**
118119 * Configuration paths for account confirmation required
119120 *
120- * @deprecated get rid of Helpers in Password Security Management.
121+ * @deprecated Get rid of Helpers in Password Security Management
121122 * @see AccountConfirmation::XML_PATH_IS_CONFIRM
122123 */
123124 const XML_PATH_IS_CONFIRM = 'customer/create_account/confirm ' ;
124125
125126 /**
126127 * Configuration paths for account confirmation email template
127128 *
128- * @deprecated get rid of Helpers in Password Security Management.
129- * @see \Magento\Customer\Model\ EmailNotification::XML_PATH_CONFIRM_EMAIL_TEMPLATE
129+ * @deprecated Get rid of Helpers in Password Security Management
130+ * @see EmailNotification::XML_PATH_REGISTER_EMAIL_TEMPLATE
130131 */
131132 const XML_PATH_CONFIRM_EMAIL_TEMPLATE = 'customer/create_account/email_confirmation_template ' ;
132133
133134 /**
134135 * Configuration paths for confirmation confirmed email template
135136 *
136- * @deprecated get rid of Helpers in Password Security Management.
137- * @see \Magento\Customer\Model\ EmailNotification::XML_PATH_CONFIRMED_EMAIL_TEMPLATE
137+ * @deprecated Get rid of Helpers in Password Security Management
138+ * @see EmailNotification::XML_PATH_REGISTER_EMAIL_TEMPLATE
138139 */
139140 const XML_PATH_CONFIRMED_EMAIL_TEMPLATE = 'customer/create_account/email_confirmed_template ' ;
140141
141142 /**
142143 * Constants for the type of new account email to be sent
143144 *
144- * @deprecated get rid of Helpers in Password Security Management.
145- * @see \Magento\Customer\Model\ EmailNotificationInterface::NEW_ACCOUNT_EMAIL_REGISTERED
145+ * @deprecated Get rid of Helpers in Password Security Management
146+ * @see EmailNotificationInterface::NEW_ACCOUNT_EMAIL_REGISTERED
146147 */
147148 const NEW_ACCOUNT_EMAIL_REGISTERED = 'registered ' ;
148149
149150 /**
150151 * Welcome email, when password setting is required
151152 *
152- * @deprecated get rid of Helpers in Password Security Management.
153- * @see \Magento\Customer\Model\ EmailNotificationInterface::NEW_ACCOUNT_EMAIL_REGISTERED_NO_PASSWORD
153+ * @deprecated Get rid of Helpers in Password Security Management
154+ * @see EmailNotificationInterface::NEW_ACCOUNT_EMAIL_REGISTERED
154155 */
155156 const NEW_ACCOUNT_EMAIL_REGISTERED_NO_PASSWORD = 'registered_no_password ' ;
156157
157158 /**
158159 * Welcome email, when confirmation is enabled
159160 *
160- * @deprecated get rid of Helpers in Password Security Management.
161- * @see \Magento\Customer\Model\ EmailNotificationInterface::NEW_ACCOUNT_EMAIL_CONFIRMATION
161+ * @deprecated Get rid of Helpers in Password Security Management
162+ * @see EmailNotificationInterface::NEW_ACCOUNT_EMAIL_REGISTERED
162163 */
163164 const NEW_ACCOUNT_EMAIL_CONFIRMATION = 'confirmation ' ;
164165
165166 /**
166167 * Confirmation email, when account is confirmed
167168 *
168- * @deprecated get rid of Helpers in Password Security Management.
169- * @see \Magento\Customer\Model\ EmailNotificationInterface::NEW_ACCOUNT_EMAIL_CONFIRMED
169+ * @deprecated Get rid of Helpers in Password Security Management
170+ * @see EmailNotificationInterface::NEW_ACCOUNT_EMAIL_REGISTERED
170171 */
171172 const NEW_ACCOUNT_EMAIL_CONFIRMED = 'confirmed ' ;
172173
@@ -192,19 +193,26 @@ class AccountManagement implements AccountManagementInterface
192193 /**
193194 * Configuration path to customer reset password email template
194195 *
195- * @deprecated get rid of Helpers in Password Security Management.
196- * @see \ Magento\ Customer\ Model\ EmailNotification::XML_PATH_RESET_PASSWORD_TEMPLATE
196+ * @deprecated Get rid of Helpers in Password Security Management
197+ * @see Magento/ Customer/ Model/ EmailNotification::XML_PATH_REGISTER_EMAIL_TEMPLATE
197198 */
198199 const XML_PATH_RESET_PASSWORD_TEMPLATE = 'customer/password/reset_password_template ' ;
199200
200201 /**
201202 * Minimum password length
202203 *
203- * @deprecated get rid of Helpers in Password Security Management.
204+ * @deprecated Get rid of Helpers in Password Security Management
204205 * @see \Magento\Customer\Model\AccountManagement::XML_PATH_MINIMUM_PASSWORD_LENGTH
205206 */
206207 const MIN_PASSWORD_LENGTH = 6 ;
207208
209+ /**
210+ * Authorization level of a basic admin session
211+ *
212+ * @see _isAllowed()
213+ */
214+ const ADMIN_RESOURCE = 'Magento_Customer::manage ' ;
215+
208216 /**
209217 * @var CustomerFactory
210218 */
@@ -375,6 +383,11 @@ class AccountManagement implements AccountManagementInterface
375383 */
376384 private $ sessionCleaner ;
377385
386+ /**
387+ * @var AuthorizationInterface
388+ */
389+ private $ authorization ;
390+
378391 /**
379392 * @param CustomerFactory $customerFactory
380393 * @param ManagerInterface $eventManager
@@ -410,6 +423,7 @@ class AccountManagement implements AccountManagementInterface
410423 * @param GetCustomerByToken|null $getByToken
411424 * @param AllowedCountries|null $allowedCountriesReader
412425 * @param SessionCleanerInterface|null $sessionCleaner
426+ * @param AuthorizationInterface|null $authorization
413427 * @SuppressWarnings(PHPMD.CyclomaticComplexity)
414428 * @SuppressWarnings(PHPMD.ExcessiveParameterList)
415429 * @SuppressWarnings(PHPMD.NPathComplexity)
@@ -450,7 +464,8 @@ public function __construct(
450464 AddressRegistry $ addressRegistry = null ,
451465 GetCustomerByToken $ getByToken = null ,
452466 AllowedCountries $ allowedCountriesReader = null ,
453- SessionCleanerInterface $ sessionCleaner = null
467+ SessionCleanerInterface $ sessionCleaner = null ,
468+ AuthorizationInterface $ authorization = null
454469 ) {
455470 $ this ->customerFactory = $ customerFactory ;
456471 $ this ->eventManager = $ eventManager ;
@@ -490,6 +505,7 @@ public function __construct(
490505 $ this ->allowedCountriesReader = $ allowedCountriesReader
491506 ?: $ objectManager ->get (AllowedCountries::class);
492507 $ this ->sessionCleaner = $ sessionCleaner ?? $ objectManager ->get (SessionCleanerInterface::class);
508+ $ this ->authorization = $ authorization ?? $ objectManager ->get (AuthorizationInterface::class);
493509 }
494510
495511 /**
@@ -836,6 +852,11 @@ public function getConfirmationStatus($customerId)
836852 */
837853 public function createAccount (CustomerInterface $ customer , $ password = null , $ redirectUrl = '' )
838854 {
855+ $ groupId = $ customer ->getGroupId ();
856+ if (isset ($ groupId ) && !$ this ->authorization ->isAllowed (self ::ADMIN_RESOURCE )) {
857+ $ customer ->setGroupId (null );
858+ }
859+
839860 if ($ password !== null ) {
840861 $ this ->checkPasswordStrength ($ password );
841862 $ customerEmail = $ customer ->getEmail ();
0 commit comments