bitExpert / magento2-force-login

Force Customer Login Module for Magento 2
https://marketplace.magento.com/bitexpert-magento2-force-customer-login.html
Apache License 2.0
166 stars 73 forks source link

Customers get whoops.... after registering #180

Closed mastrip2 closed 4 years ago

mastrip2 commented 4 years ago

Has anyone had any issues with customers getting the "whoops, our bad..." page not found error after registering for a account? It seems like the redirect that is done by default from magento isnt executing when the extension is enabled. If I turn it off the registering works.

Magento ver. 2.3.3 CE Force Login Module Version : 4.0.2 Third party modules : Magezon_PageBuilder Mageplaza_CustomerApproval

Steps to reproduce

  1. Go to account register page and register
  2. click register

Expected result

  1. To be redirected back to the customer login page ( customer/account/login )

Actual result

  1. Get error "whoops, our bad" error page image
beltoftandersen commented 4 years ago

Getting the same on 2.3.4, which the 4.0.2.

Skærmbillede 2020-03-14 kl  23 06 21

Error url: /customer/account/createpost/

mastrip2 commented 4 years ago

I had used the code from #178 as a reference of code to specifically target the registration url and ignore it. Its probably a better way of fixing this issue but I was under alot of pressure to quickly fix the issue. I'll try and find it and post it here as a fix

beltoftandersen commented 4 years ago

I had used the code from #178 as a reference of code to specifically target the registration url and ignore it. Its probably a better way of fixing this issue but I was under alot of pressure to quickly fix the issue. I'll try and find it and post it here as a fix

Can you provide a more detailed description/guide on how you solved the issue?

Much appreciated!

shochdoerfer commented 4 years ago

@mastrip2 can you provide us some code how to fix the issue?

mastrip2 commented 4 years ago

I downloaded the Batao.zip code from issue #178 . Then I browsed to the Plugin/Frontend/BitExpert/ForceCustomerLogin/Controller and edited the LoginCheck.php file. Inside the afterExcute function I added a way to check the current url and see if it was the url I observed to be for creating users. If it was I overrode the default way the extension redirected the user causing the error. Below is the code that im currently using. You just have to fix the namespace since I used a different one then the original.

`

<?php

namespace {New Name Space Here}\Register\Plugin\Frontend\BitExpert\ForceCustomerLogin\Controller;

use Magento\Framework\App\Action\Context;
use Magento\Framework\App\Response\Http as ResponseHttp;

/**
 * Class LoginCheck
 *
 * @package {New Name space Here}\Register\Plugin\Frontend\BitExpert\ForceCustomerLogin\Controller
 */
class LoginCheck
{
    /**
     * @var \Magento\Framework\UrlInterface
     */
    private $url;

    /**
     * @var ResponseHttp
     */
    private $response;
    private $request;

    public function __construct(
         \Psr\Log\LoggerInterface $logger,
         Context $context,
         ResponseHttp $response
        ) {
        $this->logger = $logger;
        $this->url = $context->getUrl();
        $this->response = $response;
        $this->request = $context->getRequest();
     }

    public function afterExecute(
        \BitExpert\ForceCustomerLogin\Controller\LoginCheck $subject,
        $result
    ) {
        $this->logger->info('scanning url');
        $url = $this->url->getCurrentUrl();

        $this->logger->info($url);
        if($this->request->isPost()){
            return false;
        }

        if (strpos($url, 'customer/account/createpost')!== false) {
            $this->logger->info('matched');
            $this->response->setNoCacheHeaders();
            $this->response->setRedirect('/customer/account');
            $this->response->sendResponse();
            return true;//it matched the register redirect
        }
        $this->logger->info('do nothing');
        return $result;//let it be
    }
}

Theres probably a better way of doing this but I kind of need a fix a bit quickly and I didnt see anything in the original code that explained what was causing this

der-workfloh commented 4 years ago

@shochdoerfer @mastrip2 I can add an extended solution as provided for the password reset handling we recently fixed (see https://github.com/bitExpert/magento2-force-login/blob/master/Controller/LoginCheck.php#L148 and https://github.com/bitExpert/magento2-force-login/blob/master/Controller/PasswordResetHelper.php). Maybe some hook / event to loosely couple the logic and allow customized logic to be attached.

shochdoerfer commented 4 years ago

@websharp sure, if you have the time to take a look, go ahead. Not sure if we need to make the logic customizable.

niekappartmedia commented 4 years ago

This issue is still a thing, after registration we get redirect to createpost url as a GET. Thats resulting in a 404. The fix above does not quite work how can we redirect back to the login and not de previous url.

mastrip2 commented 4 years ago

You could redirect to the customer/account/login just change the set redirect function (code above)

mustafaeyvazvaimo commented 4 years ago

This issue is still a thing, after registration we get redirect to createpost url as a GET. Thats resulting in a 404. The fix above does not quite work how can we redirect back to the login and not de previous url.

Same here

der-workfloh commented 4 years ago

@shochdoerfer Sorry for the delay, I provided the suggested fix in #186

davidwindell commented 4 years ago

master still 404's for us

der-workfloh commented 4 years ago

@mastrip2 @mustafaeyvazvaimo @davidwindell we added some fixes to the master, do you mind testing your issue, if everything works fine now or report any new issue occured?

mustafaeyvazvaimo commented 4 years ago

@mastrip2 @mustafaeyvazvaimo @davidwindell we added some fixes to the master, do you mind testing your issue, if everything works fine now or report any new issue occured?

Seems ok to me. Thanks for the update.

joeybab3 commented 3 years ago

I am still getting this issue in 4.1.0 unfortunately, any ideas why this may be?