Skip to content

Commit

Permalink
LYNX-361: Implemented GraphQL email confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
svera committed Mar 8, 2024
1 parent f7f4436 commit 6a65d58
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Magento\CustomerGraphQl\Model\Customer\ExtractCustomerData;
use Magento\Framework\Exception\State\InputMismatchException;
use Magento\Framework\Exception\State\InvalidTransitionException;
use Magento\Framework\Exception\StateException;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Framework\GraphQl\Query\Resolver\Value;
Expand Down Expand Up @@ -66,13 +67,15 @@ public function resolve(
if (!$this->emailValidator->isValid($args['input']['email'])) {
throw new GraphQlInputException(__('Email is invalid'));
}

try {
$customer = $this->accountManagement->activate($args['input']['email'], $args['input']['confirmation_key']);
} catch (InvalidTransitionException | InputMismatchException $e) {
throw new GraphQlInputException(__($e->getMessage()));
throw new GraphQlInputException(__($e->getRawMessage()));
} catch (StateException) {
throw new GraphQlInputException(__('This confirmation key is invalid or has expired.'));
} catch (\Exception) {
throw new GraphQlInputException(__('There was an error confirming the account'));
}

return ['customer' => $this->extractCustomerData->execute($customer)];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public function testConfirmEmail()
public function testConfirmEmailWrongEmail()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Email is invalid');

$this->graphQlMutation(
sprintf(
Expand All @@ -126,6 +127,7 @@ public function testConfirmEmailWrongEmail()
public function testConfirmEmailWrongConfirmation()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('The confirmation token is invalid. Verify the token and try again.');

$this->graphQlMutation(
sprintf(
Expand Down

0 comments on commit 6a65d58

Please sign in to comment.