What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

Hi Team, I'm trying to enable users to log in with a mobile number on YVES, for t

U04F4JUC0UT
U04F4JUC0UT Posts: 35 🧑🏻‍🚀 - Cadet
edited January 2023 in Help

Hi Team,

I'm trying to enable users to log in with a mobile number on YVES, for that I have already updated the registration form and now the mobile number is getting stored in the DB. Thanks, @UNGMX0012 for helping me out.

Now to override the login module I have extended the tryAuthorizeCustomerByEmailAndPassword
From here \vendor\spryker\customer\src\Spryker\Zed\Customer\Business\Customer\Customer.php

At \src\Pyz\Zed\Customer\Business\Customer\Customer.php

And CustomerQueryContainer from here \vendor\spryker\customer\src\Spryker\Zed\Customer\Persistence\CustomerQueryContainer.php
At \src\Pyz\Zed\Customer\Persistence\CustomerQueryContainer.php

And I have also extended the customerBusinessFactory.

But it's not working.

Can you please check and let me know what I have done wrong here.

Thanks

Comments

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,084 ⚖️ - Guardians (admin)

    Hey, “But it’s not working.” does not really give a lot of information what fails 😕

    Have you debugged with xdebug? - Is the phone-number and pw properly received by your overriden files?

  • U04F4JUC0UT
    U04F4JUC0UT Posts: 35 🧑🏻‍🚀 - Cadet

    what I did is I have added die() in the vendor file as well, then also its not failing, so I'm not sure whether its a correct method or not

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,084 ⚖️ - Guardians (admin)

    Please setup xdebug with your IDE to test and trace properly

  • U04F4JUC0UT
    U04F4JUC0UT Posts: 35 🧑🏻‍🚀 - Cadet

    Here is the code for customer.php

    <?php
    
    /**
     * Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
     * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
     */
    
    namespace Pyz\Zed\Customer\Business\Customer;
    
    use Spryker\Zed\Customer\Business\Customer\Customer as SprykerCustomer;
    use Generated\Shared\Transfer\CustomerTransfer;
    
    class Customer extends SprykerCustomer
    {
    
        /**
         * @var \Spryker\Zed\Customer\Persistence\CustomerQueryContainerInterface
         */
        protected $queryContainer;
    
        /**
         * @param \Generated\Shared\Transfer\CustomerTransfer $customerTransfer
         *
         * @return bool
         */
        public function tryAuthorizeCustomerByEmailAndPassword(CustomerTransfer $customerTransfer)
        {
            $customerEntity = $this->queryContainer->queryCustomerByEmailOrMobileNumber($customerTransfer)
                ->findOne();
    
            if (!$customerEntity) {
    
                return false;
            }
    
            if (!parent::isValidPassword($customerEntity->getPassword(), $customerTransfer->getPassword())) {
                return false;
            }
    
            if ($this->customerConfig->isDoubleOptInEnabled() && !$customerEntity->getRegistered()) {
                return false;
            }
    
            return true;
        }
    }
    

    CustomerQueryContainer

    <?php
    
    /**
     * Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
     * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
     */
    
    namespace Pyz\Zed\Customer\Persistence;
    
    use Spryker\Zed\Customer\Persistence\CustomerQueryContainer as SprykerCustomerQueryContainer;
    
    /**
     * @method \Spryker\Zed\Customer\Persistence\CustomerPersistenceFactory getFactory()
     */
    class CustomerQueryContainer extends SprykerCustomerQueryContainer
    {
        /**
         * @api
         *
         * @inheritDoc
         */
        public function queryCustomerByEmailOrMobileNumber($customer)
        {
            $query = parent::queryCustomers();
    
            $query->filterByEmail($customer->getEmail())
            ->_or()
            ->filterByMobileNumber($customer->getEmail());
    
            return $query;
        }
    }
    
  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,084 ⚖️ - Guardians (admin)
    edited January 2023

    Have you also updated the BusinessFactory to use your new file (Customer)?

  • U04F4JUC0UT
    U04F4JUC0UT Posts: 35 🧑🏻‍🚀 - Cadet

    I did that when I'm running it in debug more then also its not stopping at breakpoints which I have added

  • U04F4JUC0UT
    U04F4JUC0UT Posts: 35 🧑🏻‍🚀 - Cadet

    Yes Here is that file

    <?php
    
    /**
     * Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
     * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
     */
    
    namespace Pyz\Zed\Customer\Business;
    
    use Spryker\Zed\Customer\Business\CustomerBusinessFactory as SprykerCustomerBusinessFactory;
    use Pyz\Zed\Customer\Business\Customer\Customer;
    
    /**
     * @method \Spryker\Zed\Customer\CustomerConfig getConfig()
     * @method \Pyz\Zed\Customer\Persistence\CustomerQueryContainer getQueryContainer()
     * @method \Spryker\Zed\Customer\Persistence\CustomerEntityManagerInterface getEntityManager()
     * @method \Spryker\Zed\Customer\Persistence\CustomerRepositoryInterface getRepository()
     */
    class CustomerBusinessFactory extends SprykerCustomerBusinessFactory
    {
        /**
         * @return \Spryker\Zed\Customer\Business\Customer\CustomerInterface
         */
        public function createCustomer()
        {
            $config = $this->getConfig();
            $customer = new Customer(
                $this->getQueryContainer(),
                $this->createCustomerReferenceGenerator(),
                $config,
                $this->createEmailValidator(),
                $this->getMailFacade(),
                $this->getLocaleQueryContainer(),
                $this->getLocaleFacade(),
                $this->createCustomerExpander(),
                $this->createCustomerPasswordPolicyValidator(),
                $this->getPostCustomerRegistrationPlugins(),
            );
    
            return $customer;
        }
    }
    
  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,084 ⚖️ - Guardians (admin)

    and that one is called?

  • U04F4JUC0UT
    U04F4JUC0UT Posts: 35 🧑🏻‍🚀 - Cadet

    Yes when I add died here in this mrthod that time login request failed

  • sebastian.larisch
    sebastian.larisch Spryker Customer Posts: 143 🧑🏻‍🚀 - Cadet

    Did u delete class resolver cache as well?

  • U04F4JUC0UT
    U04F4JUC0UT Posts: 35 🧑🏻‍🚀 - Cadet

    Yes I have used this command for that

    docker/sdk console cache:class-resolver:build
    
  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,084 ⚖️ - Guardians (admin)

    i foggy remember that this method is not directly used by yves login.

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,084 ⚖️ - Guardians (admin)

    Have a look at vendor/spryker-shop/customer-page/src/SprykerShop/Yves/CustomerPage/Plugin/Provider/CustomerUserProvider.php

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,084 ⚖️ - Guardians (admin)

    loadUserByUsername() is a method used by symfony security module - your username is the phone number

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,084 ⚖️ - Guardians (admin)

    set a breakpoint there and check if you receive the phone number there. And from that point you can start to follow the methods

  • U04F4JUC0UT
    U04F4JUC0UT Posts: 35 🧑🏻‍🚀 - Cadet

    Sure thanks for the reply, will check that