0

I'm developing a website that contain SSO customers. They do NOT have customer password when creating customer account. That caused a problem in a scenario: If they attempt to change email, they need to enter current password.

But as I said before, they do not have customer password, so they simply can't edit their email currently. Every time they try the change email, it shows the error message "The password doesn't match this account.". So, is there any methods to change the email address without entering customer password?

1
  • The solution above does not work. The Plugins which are used before will only works with public methods. In this case, Use a alternate route and remove password check. Jan 30, 2019 at 10:12

1 Answer 1

2

You this you to need customize EditPost controller class below file:

Magento\Customer\Controller\Account\EditPost

In excute method below function check if email change request is sent or not

// whether a customer enabled change email option
$this->processChangeEmailRequest($currentCustomerDataObject);

In processChangeEmailRequest function there is check for Password check.

/**
 * Process change email request
 *
 * @param \Magento\Customer\Api\Data\CustomerInterface $currentCustomerDataObject
 * @return void
 * @throws InvalidEmailOrPasswordException
 * @throws UserLockedException
 */
private function processChangeEmailRequest(\Magento\Customer\Api\Data\CustomerInterface $currentCustomerDataObject)
{
    if ($this->getRequest()->getParam('change_email')) {
        // authenticate user for changing email
        try {
            $this->getAuthentication()->authenticate(
                $currentCustomerDataObject->getId(),
                $this->getRequest()->getPost('current_password')
            );
        } catch (InvalidEmailOrPasswordException $e) {
            throw new InvalidEmailOrPasswordException(__('The password doesn\'t match this account.'));
        }
    }
}

You can disable this function call processChangeEmailRequest by creating Around event plugin for EditPost controller.

1
  • I'm so sorry that due to changed requirement, I don't need to do this task. But I'll still test your answer when I have time, thanks very much!
    – PY Yick
    Sep 26, 2017 at 11:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.