22
22
use Magento \Customer \Api \AccountManagementInterface ;
23
23
use Magento \Customer \Api \CustomerRepositoryInterface ;
24
24
use Magento \Integration \Api \CustomerTokenServiceInterface ;
25
+ use Magento \Framework \Encryption \EncryptorInterface as Encryptor ;
26
+ use Magento \Customer \Model \AuthenticationInterface ;
27
+ use Magento \Customer \Model \CustomerRegistry ;
25
28
26
29
class ConfirmEmail implements ResolverInterface {
27
30
const STATUS_TOKEN_EXPIRED = 'token_expired ' ;
28
31
32
+ /**
33
+ * @var AuthenticationInterface
34
+ */
35
+ private $ authentication ;
36
+
29
37
/**
30
38
* @var Session
31
39
*/
@@ -46,24 +54,42 @@ class ConfirmEmail implements ResolverInterface {
46
54
*/
47
55
protected $ customerTokenService ;
48
56
57
+ /**
58
+ * @var Encryptor
59
+ */
60
+ protected $ encryptor ;
61
+
62
+ /**
63
+ * @var CustomerRegistry
64
+ */
65
+ protected $ customerRegistry ;
66
+
49
67
/**
50
68
* ConfirmEmail constructor.
69
+ * @param AuthenticationInterface $authentication
51
70
* @param Session $customerSession
52
71
* @param AccountManagementInterface $customerAccountManagement
53
72
* @param CustomerRepositoryInterface $customerRepository
54
73
* @param CustomerTokenServiceInterface $customerTokenService
55
- * @param CustomerDataProvider $customerDataProvider
74
+ * @param Encryptor $encryptor
75
+ * @param CustomerRegistry $customerRegistry
56
76
*/
57
77
public function __construct (
78
+ AuthenticationInterface $ authentication ,
58
79
Session $ customerSession ,
59
80
AccountManagementInterface $ customerAccountManagement ,
60
81
CustomerRepositoryInterface $ customerRepository ,
61
- CustomerTokenServiceInterface $ customerTokenService
82
+ CustomerTokenServiceInterface $ customerTokenService ,
83
+ Encryptor $ encryptor ,
84
+ CustomerRegistry $ customerRegistry
62
85
) {
86
+ $ this ->authentication = $ authentication ;
63
87
$ this ->customerTokenService = $ customerTokenService ;
64
88
$ this ->session = $ customerSession ;
65
89
$ this ->customerAccountManagement = $ customerAccountManagement ;
66
90
$ this ->customerRepository = $ customerRepository ;
91
+ $ this ->encryptor = $ encryptor ;
92
+ $ this ->customerRegistry = $ customerRegistry ;
67
93
}
68
94
69
95
/**
@@ -78,26 +104,31 @@ public function resolve(
78
104
)
79
105
{
80
106
if ($ this ->session ->isLoggedIn ()) {
81
- return [ ' status ' => AccountManagementInterface:: ACCOUNT_CONFIRMATION_NOT_REQUIRED ] ;
107
+ $ this -> session -> logOut () ;
82
108
}
83
109
84
110
try {
85
- $ customerId = $ args ['id ' ];
111
+ $ customerEmail = $ args ['email ' ];
86
112
$ key = $ args ['key ' ];
87
113
$ password = $ args ['password ' ];
88
114
89
- $ customerEmail = $ this ->customerRepository ->getById ($ customerId )->getEmail ();
90
- $ customer = $ this ->customerAccountManagement ->activate ($ customerEmail , $ key );
91
- $ this ->session ->setCustomerDataAsLoggedIn ($ customer );
92
- $ token = $ this ->customerTokenService ->createCustomerAccessToken ($ customer ->getEmail (), $ password );
115
+ $ id = $ this ->customerRepository ->get ($ customerEmail )->getId ();
116
+ $ currentPasswordHash = $ this ->customerRegistry ->retrieveSecureData ($ id )->getPasswordHash ();
117
+
118
+ if ($ this ->encryptor ->validateHash ($ password , $ currentPasswordHash )) {
119
+ $ customer = $ this ->customerAccountManagement ->activate ($ customerEmail , $ key );
93
120
94
- return [
95
- 'customer ' => $ this ->customerRepository ->getById ((int )$ customer ->getId ()),
96
- 'status ' => AccountManagementInterface::ACCOUNT_CONFIRMED ,
97
- 'token ' => $ token
98
- ];
121
+ $ this ->session ->setCustomerDataAsLoggedIn ($ customer );
122
+ $ token = $ this ->customerTokenService ->createCustomerAccessToken ($ customerEmail , $ password );
123
+ return [
124
+ 'status ' => AccountManagementInterface::ACCOUNT_CONFIRMED ,
125
+ 'token ' => $ token
126
+ ];
127
+ } else {
128
+ throw new GraphQlInputException (__ ('Password is incorrect ' ));
129
+ }
99
130
} catch (StateException $ e ) {
100
- return [ 'status ' => self ::STATUS_TOKEN_EXPIRED ];
131
+ return ['status ' => self ::STATUS_TOKEN_EXPIRED ];
101
132
} catch (\Exception $ e ) {
102
133
throw new GraphQlInputException (__ ('There was an error confirming the account ' ), $ e );
103
134
}
0 commit comments