Skip to content

Commit c8308f9

Browse files
authored
Merge pull request #34 from AzizKHAN030/m244_customer-graphql
added customer_id field and get customers email and passing to the resetPassword method
2 parents bfd581d + 11b6315 commit c8308f9

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/Model/Resolver/ResetPassword.php

+22-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace ScandiPWA\CustomerGraphQl\Model\Resolver;
1515

16+
use Magento\Customer\Api\CustomerRepositoryInterface;
1617
use Magento\Framework\Exception\InputException;
1718
use Magento\Framework\GraphQl\Config\Element\Field;
1819
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
@@ -36,12 +37,24 @@ class ResetPassword implements ResolverInterface {
3637
*/
3738
protected $session;
3839

40+
/**
41+
* @var CustomerRepositoryInterface
42+
*/
43+
protected $customerRepository;
44+
45+
/**
46+
* ResetPassword constructor.
47+
*
48+
* @param CustomerRepositoryInterface $customerRepository
49+
*/
3950
public function __construct(
4051
Session $customerSession,
52+
CustomerRepositoryInterface $customerRepository,
4153
AccountManagementInterface $accountManagement
4254
) {
4355
$this->session = $customerSession;
4456
$this->accountManagement = $accountManagement;
57+
$this->customerRepository = $customerRepository;
4558
}
4659

4760
/**
@@ -57,6 +70,13 @@ public function resolve(
5770
$resetPasswordToken = $args['token'];
5871
$password = $args['password'];
5972
$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+
}
6080

6181
if ($password !== $passwordConfirmation) {
6282
return [
@@ -73,13 +93,13 @@ public function resolve(
7393
}
7494

7595
try {
76-
$this->accountManagement->resetPassword(null, $resetPasswordToken, $password);
96+
$this->accountManagement->resetPassword($customerEmail, $resetPasswordToken, $password);
7797
$this->session->unsRpToken();
7898
return [ 'status' => self::STATUS_PASSWORD_UPDATED ];
7999
} catch (InputException $e) {
80100
throw new GraphQlInputException(__($e->getMessage()));
81101
} 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.'));
83103
}
84104
}
85105
}

src/etc/schema.graphqls

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type Mutation {
1515
confirmCustomerEmail(key: String!, email: String!, password: String!): CreateCustomerType @resolver(class: "\\ScandiPWA\\CustomerGraphQl\\Model\\Resolver\\ConfirmEmail") @doc(description:"Confirm customer account")
1616
resendConfirmationEmail(email: String!): CustomerActionConfirmationType @resolver(class: "\\ScandiPWA\\CustomerGraphQl\\Model\\Resolver\\ResendConfirmationEmail") @doc(description:"Resend customer confirmation")
1717
forgotPassword(email: String!): CustomerActionConfirmationType @resolver(class: "\\ScandiPWA\\CustomerGraphQl\\Model\\Resolver\\ForgotPassword") @doc(description:"Resend customer confirmation")
18-
s_resetPassword(password: String!, token: String!, password_confirmation: String!): ResetPasswordType @resolver(class: "\\ScandiPWA\\CustomerGraphQl\\Model\\Resolver\\ResetPassword") @doc(description:"Resend customer confirmation")
18+
s_resetPassword(customer_id: String!,password: String!, token: String!, password_confirmation: String!): ResetPasswordType @resolver(class: "\\ScandiPWA\\CustomerGraphQl\\Model\\Resolver\\ResetPassword") @doc(description:"Resend customer confirmation")
1919
}
2020

2121
type CustomerActionConfirmationType {

0 commit comments

Comments
 (0)