In this blog, We will discuss how to create a customer programmatically. How many ways to create a Magento 2 customer. We will discuss in both editions, Magento 2 enterprise edition and community edition.
If I have a customer Id(email_id) and I want to login without a password. So, what is the step to open my account dashboard?
Let's discuss !!!
As per my opinion, We can use the below possible way.
1. Get a password in your mailId using "Forgot Your Password?" Link
If I forgot the password, I can get the password using forgot password link. Click the sign-in link on the top-right header. After click on the forgot password link as per the below screenshot.
Now, Fill in the required information and reset your password. Reset Password link will come on your registered mail id. You can create a new password and after you can log in to your account.
We need to create one external script in Magento project root folder. I have created one external script "customer_login.php" as per the below screenshot.
Now, simply pest the below code on your external script and run it on your browser.
<?phpuse Magento\Framework\App\Bootstrap;require __DIR__ . '/app/bootstrap.php';$params = $_SERVER;$bootstrap = Bootstrap::create(BP, $params);$object = $bootstrap->getObjectManager();$statecall = $object->get('Magento\Framework\App\State');$statecall->setAreaCode('frontend');$websiteId = $object->get('Magento\Store\Model\StoreManagerInterface')->getStore()->getWebsiteId();$customerObj = $object->get('Magento\Customer\Model\Customer')->setWebsiteId($websiteId)->loadByEmail("bhavesh@trycoder.com");$customer = $object->get('Magento\Customer\Model\Session')->setCustomerAsLoggedIn($customerObj);echo "done";?>
I have run the script on my browser as per the below screenshot. It's successfully run without any errors.
Now, I log in automatically, without the required password As per the below screenshot.
Comments
Post a Comment
Please do not enter any spam link in the comment box.