3

i have registered with mobile instead of email in magento2. now when am i sing in with mobile and password i am getting error no such entity email with website id 1. AccountManagement.php

public function authenticatemobile($mobile,$passmobile)
    {       $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
       $connection = $objectManager->get('Magento\Framework\App\ResourceConnection')->getConnection('\Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION');
       $sql = "SELECT entity_id FROM customer_entity_varchar WHERE value='". $mobile. "'";
       $sql_sel= $connection->fetchAll($sql);
       print_r($sql_sel);
       foreach($sql_sel as $sql_se){
           $cust = $sql_se['entity_id'];
       }

        try {           $customer = $this->customerRepository->getById($cust);
        } catch (NoSuchEntityException $e) {
            throw new InvalidEmailOrPasswordException(__('Invalid Mobile or password.'));
        }
        $customerId = $customer->getId();
        if ($this->getAuthentication()->isLocked($customerId)) {
            throw new UserLockedException(__('Due to multiple failure login, Your account is temporary locked, please try after 10 minutes.'));
        }
        try {
            $this->getAuthentication()->authenticate($customerId, $passmobile);
        } catch (InvalidEmailOrPasswordException $e) {
            throw new InvalidEmailOrPasswordException(__('Invalid login or password.'));
        }
        if ($customer->getConfirmation() && $this->isConfirmationRequired($customer)) {
            throw new EmailNotConfirmedException(__('This account is not confirmed.'));
        }

        $customerModel = $this->customerFactory->create()->updateData($customer);
        $this->eventManager->dispatch(
            'customer_customer_authenticated',
            ['model' => $customerModel, 'password' => $passmobile]
        );

        $this->eventManager->dispatch('customer_data_object_login', ['customer' => $customer]);

        return $customer;
    }

login.php

if ($mobile && $passmobile) {
                try {
                    $accountManage = $this->accountManagement;
                    $customer_mobile      = $accountManage->authenticatemobile(
                        $mobile,
                        $passmobile
                    );
                    $activationStatus =CustomerStatus::PENDING;
                    if($customer_mobile->getCustomAttribute('activation_status') != NULL)
                        $activationStatus = $customer_mobile->getCustomAttribute('activation_status')->getValue();

                    if($activationStatus != CustomerStatus::APPROVED)
                    {
                         throw new \Exception(__('Your account is pending for moderation.'));
                    }
                    $this->customerSession->setCustomerDataAsLoggedIn($customer_mobile);
                    $this->customerSession->regenerateId();
                } catch (EmailNotConfirmedException $e) {
                    /*$value = $this->customerUrl->getEmailConfirmationUrl($username);
                    $message = __(
                        'This account is not confirmed. <a href="%1">Click here</a> to resend confirmation email.',
                        $value
                    );
                    $result['error']   = true;
                    $result['message'] = $message;*/

                }catch (UserLockedException $e) {
                    /*$message = __(
                        'The account is locked. Please wait and try again or contact %1.',
                        $this->getScopeConfig()->getValue('contact/email/recipient_email')
                    );*/
                    $message = __(
                        'The account is locked. Please wait and try again.'
                    );
                     $result['error']   = true;
                    $result['message'] = $message;
                } catch (AuthenticationException $e) {
                     $result['error']   = true;
                    $result['message'] = $e->getMessage();
                } catch (\Exception $e) {
                    $result['error']   = true;
                    $result['message'] = $e->getMessage();

                }
                if (!isset($result['error'])) {
                    $result['success'] = true;
                    $result['message'] = __('Login successfully. Please wait ...');
                }
            } else {
                $result['error']   = true;
                $result['message'] = __(
                    'Please enter a mobile and password.sarvesh');
            }
4
  • i can login mobile with password if customer register with email. but if customer registered without mail than i can not login with mobile and password. Jun 21, 2017 at 7:07
  • Sarvesh, have you got any solution for this ? Sep 6, 2017 at 5:30
  • Hi Pushpendra i got solution but right now i am very busy i will post answer later Sep 6, 2017 at 6:27
  • Checkout this, but magento considers email as main magecomp.com/magento-2-mobile-login.html Oct 4, 2017 at 14:20

1 Answer 1

3

There are lots of Magento validation function on customer email, you have to set a dummy email on the customer even you don't need it.

For example it will send out email , isEmailAvailable in

vendor/magento/module-customer/Model/AccountManagement.php

Your Answer

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

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