55
55
use Magento \Store \Model \ScopeInterface ;
56
56
use Magento \Store \Model \StoreManagerInterface ;
57
57
use Psr \Log \LoggerInterface as PsrLogger ;
58
+ use Magento \Framework \AuthorizationInterface ;
58
59
59
60
/**
60
61
* Handle various customer account actions
@@ -69,104 +70,104 @@ class AccountManagement implements AccountManagementInterface
69
70
/**
70
71
* Configuration paths for create account email template
71
72
*
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
74
75
*/
75
76
const XML_PATH_REGISTER_EMAIL_TEMPLATE = 'customer/create_account/email_template ' ;
76
77
77
78
/**
78
79
* Configuration paths for register no password email template
79
80
*
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
82
83
*/
83
84
const XML_PATH_REGISTER_NO_PASSWORD_EMAIL_TEMPLATE = 'customer/create_account/email_no_password_template ' ;
84
85
85
86
/**
86
87
* Configuration paths for remind email identity
87
88
*
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
90
91
*/
91
92
const XML_PATH_REGISTER_EMAIL_IDENTITY = 'customer/create_account/email_identity ' ;
92
93
93
94
/**
94
95
* Configuration paths for remind email template
95
96
*
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
98
99
*/
99
100
const XML_PATH_REMIND_EMAIL_TEMPLATE = 'customer/password/remind_email_template ' ;
100
101
101
102
/**
102
103
* Configuration paths for forgot email email template
103
104
*
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
106
107
*/
107
108
const XML_PATH_FORGOT_EMAIL_TEMPLATE = 'customer/password/forgot_email_template ' ;
108
109
109
110
/**
110
111
* Configuration paths for forgot email identity
111
112
*
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
114
115
*/
115
116
const XML_PATH_FORGOT_EMAIL_IDENTITY = 'customer/password/forgot_email_identity ' ;
116
117
117
118
/**
118
119
* Configuration paths for account confirmation required
119
120
*
120
- * @deprecated get rid of Helpers in Password Security Management.
121
+ * @deprecated Get rid of Helpers in Password Security Management
121
122
* @see AccountConfirmation::XML_PATH_IS_CONFIRM
122
123
*/
123
124
const XML_PATH_IS_CONFIRM = 'customer/create_account/confirm ' ;
124
125
125
126
/**
126
127
* Configuration paths for account confirmation email template
127
128
*
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
130
131
*/
131
132
const XML_PATH_CONFIRM_EMAIL_TEMPLATE = 'customer/create_account/email_confirmation_template ' ;
132
133
133
134
/**
134
135
* Configuration paths for confirmation confirmed email template
135
136
*
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
138
139
*/
139
140
const XML_PATH_CONFIRMED_EMAIL_TEMPLATE = 'customer/create_account/email_confirmed_template ' ;
140
141
141
142
/**
142
143
* Constants for the type of new account email to be sent
143
144
*
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
146
147
*/
147
148
const NEW_ACCOUNT_EMAIL_REGISTERED = 'registered ' ;
148
149
149
150
/**
150
151
* Welcome email, when password setting is required
151
152
*
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
154
155
*/
155
156
const NEW_ACCOUNT_EMAIL_REGISTERED_NO_PASSWORD = 'registered_no_password ' ;
156
157
157
158
/**
158
159
* Welcome email, when confirmation is enabled
159
160
*
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
162
163
*/
163
164
const NEW_ACCOUNT_EMAIL_CONFIRMATION = 'confirmation ' ;
164
165
165
166
/**
166
167
* Confirmation email, when account is confirmed
167
168
*
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
170
171
*/
171
172
const NEW_ACCOUNT_EMAIL_CONFIRMED = 'confirmed ' ;
172
173
@@ -192,19 +193,26 @@ class AccountManagement implements AccountManagementInterface
192
193
/**
193
194
* Configuration path to customer reset password email template
194
195
*
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
197
198
*/
198
199
const XML_PATH_RESET_PASSWORD_TEMPLATE = 'customer/password/reset_password_template ' ;
199
200
200
201
/**
201
202
* Minimum password length
202
203
*
203
- * @deprecated get rid of Helpers in Password Security Management.
204
+ * @deprecated Get rid of Helpers in Password Security Management
204
205
* @see \Magento\Customer\Model\AccountManagement::XML_PATH_MINIMUM_PASSWORD_LENGTH
205
206
*/
206
207
const MIN_PASSWORD_LENGTH = 6 ;
207
208
209
+ /**
210
+ * Authorization level of a basic admin session
211
+ *
212
+ * @see _isAllowed()
213
+ */
214
+ const ADMIN_RESOURCE = 'Magento_Customer::manage ' ;
215
+
208
216
/**
209
217
* @var CustomerFactory
210
218
*/
@@ -375,6 +383,11 @@ class AccountManagement implements AccountManagementInterface
375
383
*/
376
384
private $ sessionCleaner ;
377
385
386
+ /**
387
+ * @var AuthorizationInterface
388
+ */
389
+ private $ authorization ;
390
+
378
391
/**
379
392
* @param CustomerFactory $customerFactory
380
393
* @param ManagerInterface $eventManager
@@ -410,6 +423,7 @@ class AccountManagement implements AccountManagementInterface
410
423
* @param GetCustomerByToken|null $getByToken
411
424
* @param AllowedCountries|null $allowedCountriesReader
412
425
* @param SessionCleanerInterface|null $sessionCleaner
426
+ * @param AuthorizationInterface|null $authorization
413
427
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
414
428
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
415
429
* @SuppressWarnings(PHPMD.NPathComplexity)
@@ -450,7 +464,8 @@ public function __construct(
450
464
AddressRegistry $ addressRegistry = null ,
451
465
GetCustomerByToken $ getByToken = null ,
452
466
AllowedCountries $ allowedCountriesReader = null ,
453
- SessionCleanerInterface $ sessionCleaner = null
467
+ SessionCleanerInterface $ sessionCleaner = null ,
468
+ AuthorizationInterface $ authorization = null
454
469
) {
455
470
$ this ->customerFactory = $ customerFactory ;
456
471
$ this ->eventManager = $ eventManager ;
@@ -490,6 +505,7 @@ public function __construct(
490
505
$ this ->allowedCountriesReader = $ allowedCountriesReader
491
506
?: $ objectManager ->get (AllowedCountries::class);
492
507
$ this ->sessionCleaner = $ sessionCleaner ?? $ objectManager ->get (SessionCleanerInterface::class);
508
+ $ this ->authorization = $ authorization ?? $ objectManager ->get (AuthorizationInterface::class);
493
509
}
494
510
495
511
/**
@@ -836,6 +852,11 @@ public function getConfirmationStatus($customerId)
836
852
*/
837
853
public function createAccount (CustomerInterface $ customer , $ password = null , $ redirectUrl = '' )
838
854
{
855
+ $ groupId = $ customer ->getGroupId ();
856
+ if (isset ($ groupId ) && !$ this ->authorization ->isAllowed (self ::ADMIN_RESOURCE )) {
857
+ $ customer ->setGroupId (null );
858
+ }
859
+
839
860
if ($ password !== null ) {
840
861
$ this ->checkPasswordStrength ($ password );
841
862
$ customerEmail = $ customer ->getEmail ();
0 commit comments