Created
December 5, 2017 00:28
-
-
Save tiagosampaio/eed8d29588a1cbaa1d47b066f7d39cc8 to your computer and use it in GitHub Desktop.
Code Example Customer Model in Magento 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Authenticate customer | |
* | |
* @param string $login | |
* @param string $password | |
* @return bool | |
* @throws \Magento\Framework\Exception\LocalizedException | |
* Use \Magento\Customer\Api\AccountManagementInterface::authenticate | |
*/ | |
public function authenticate($login, $password) | |
{ | |
$this->loadByEmail($login); | |
if ($this->getConfirmation() && $this->isConfirmationRequired()) { | |
throw new EmailNotConfirmedException( | |
__('This account is not confirmed.') | |
); | |
} | |
if (!$this->validatePassword($password)) { | |
throw new InvalidEmailOrPasswordException( | |
__('Invalid login or password.') | |
); | |
} | |
$this->_eventManager->dispatch( | |
'customer_customer_authenticated', | |
['model' => $this, 'password' => $password] | |
); | |
return true; | |
} | |
/** | |
* Load customer by email | |
* | |
* @param string $customerEmail | |
* @return $this | |
*/ | |
public function loadByEmail($customerEmail) | |
{ | |
$this->_getResource()->loadByEmail($this, $customerEmail); | |
return $this; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment