13
13
14
14
namespace ScandiPWA \CustomerGraphQl \Model \Resolver ;
15
15
16
+ use Magento \Customer \Api \CustomerRepositoryInterface ;
16
17
use Magento \Framework \Exception \InputException ;
17
18
use Magento \Framework \GraphQl \Config \Element \Field ;
18
19
use Magento \Framework \GraphQl \Exception \GraphQlInputException ;
@@ -36,12 +37,24 @@ class ResetPassword implements ResolverInterface {
36
37
*/
37
38
protected $ session ;
38
39
40
+ /**
41
+ * @var CustomerRepositoryInterface
42
+ */
43
+ protected $ customerRepository ;
44
+
45
+ /**
46
+ * ResetPassword constructor.
47
+ *
48
+ * @param CustomerRepositoryInterface $customerRepository
49
+ */
39
50
public function __construct (
40
51
Session $ customerSession ,
52
+ CustomerRepositoryInterface $ customerRepository ,
41
53
AccountManagementInterface $ accountManagement
42
54
) {
43
55
$ this ->session = $ customerSession ;
44
56
$ this ->accountManagement = $ accountManagement ;
57
+ $ this ->customerRepository = $ customerRepository ;
45
58
}
46
59
47
60
/**
@@ -57,6 +70,13 @@ public function resolve(
57
70
$ resetPasswordToken = $ args ['token ' ];
58
71
$ password = $ args ['password ' ];
59
72
$ passwordConfirmation = $ args ['password_confirmation ' ];
73
+ $ customerId = $ args ['customer_id ' ];
74
+
75
+ try {
76
+ $ customerEmail = $ this ->customerRepository ->getById ($ customerId )->getEmail ();
77
+ } catch (\Exception $ exception ) {
78
+ throw new GraphQlInputException (__ ('No customer found ' ));
79
+ }
60
80
61
81
if ($ password !== $ passwordConfirmation ) {
62
82
return [
@@ -73,13 +93,13 @@ public function resolve(
73
93
}
74
94
75
95
try {
76
- $ this ->accountManagement ->resetPassword (null , $ resetPasswordToken , $ password );
96
+ $ this ->accountManagement ->resetPassword ($ customerEmail , $ resetPasswordToken , $ password );
77
97
$ this ->session ->unsRpToken ();
78
98
return [ 'status ' => self ::STATUS_PASSWORD_UPDATED ];
79
99
} catch (InputException $ e ) {
80
100
throw new GraphQlInputException (__ ($ e ->getMessage ()));
81
101
} catch (\Exception $ exception ) {
82
- throw new GraphQlInputException (__ ('Something went wrong while saving the new password . ' ));
102
+ throw new GraphQlInputException (__ ('Your password reset link has expired . ' ));
83
103
}
84
104
}
85
105
}
0 commit comments