Magento 2 Logout after Registration












0















I need to logout a user after successful registration to login page.



I tried to redirect the user after registration by creating a observer customer_register_success but it dint work, When the observer is called the loggin action is not triggered so I added a redirection that will solve my problem but dint. its working as usual.



public function execute(Observer $observer)
{
$this->messageManager->addErrorMessage(__('Your account is not approved.'));
$this->_response->setRedirect($this->_urlFactory->create()->getUrl('customer/account/login'));

}


I tried with this link belo but it only works with login page and not in registration process.




Magento 2: Get Customer data after login with observer




How do I Logout the user.










share|improve this question



























    0















    I need to logout a user after successful registration to login page.



    I tried to redirect the user after registration by creating a observer customer_register_success but it dint work, When the observer is called the loggin action is not triggered so I added a redirection that will solve my problem but dint. its working as usual.



    public function execute(Observer $observer)
    {
    $this->messageManager->addErrorMessage(__('Your account is not approved.'));
    $this->_response->setRedirect($this->_urlFactory->create()->getUrl('customer/account/login'));

    }


    I tried with this link belo but it only works with login page and not in registration process.




    Magento 2: Get Customer data after login with observer




    How do I Logout the user.










    share|improve this question

























      0












      0








      0








      I need to logout a user after successful registration to login page.



      I tried to redirect the user after registration by creating a observer customer_register_success but it dint work, When the observer is called the loggin action is not triggered so I added a redirection that will solve my problem but dint. its working as usual.



      public function execute(Observer $observer)
      {
      $this->messageManager->addErrorMessage(__('Your account is not approved.'));
      $this->_response->setRedirect($this->_urlFactory->create()->getUrl('customer/account/login'));

      }


      I tried with this link belo but it only works with login page and not in registration process.




      Magento 2: Get Customer data after login with observer




      How do I Logout the user.










      share|improve this question














      I need to logout a user after successful registration to login page.



      I tried to redirect the user after registration by creating a observer customer_register_success but it dint work, When the observer is called the loggin action is not triggered so I added a redirection that will solve my problem but dint. its working as usual.



      public function execute(Observer $observer)
      {
      $this->messageManager->addErrorMessage(__('Your account is not approved.'));
      $this->_response->setRedirect($this->_urlFactory->create()->getUrl('customer/account/login'));

      }


      I tried with this link belo but it only works with login page and not in registration process.




      Magento 2: Get Customer data after login with observer




      How do I Logout the user.







      magento2 registration logout






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 29 '18 at 14:24









      fernandusfernandus

      758




      758






















          2 Answers
          2






          active

          oldest

          votes


















          0














          Try this



          di.xml add



          <?xml version="1.0"?>
          <!--
          /**
          * Copyright © 2016 Magento. All rights reserved.
          * See COPYING.txt for license details.
          */
          -->
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">

          <event name="customer_register_success">
          <observer name="custom_customer_created" instance="CustomModuleObserverCustomerEventCreatedObserver" />
          </event>

          </config>

          public function execute(Observer $observer)
          {
          $this->messageManager->addErrorMessage(__('Your account is not approved.'));
          $this->_response->setRedirect($this->_urlFactory->create()->getUrl('customer/account/logout'));

          }





          share|improve this answer
























          • Have the same set of coding its not working for me. facing the same issue. Its not redirecting it logs me in and takes me to home page.

            – fernandus
            Dec 31 '18 at 5:52





















          0














          I used this extension to trigger after Registration https://github.com/php-cuong/magento2-redirect-customer it used customer_login observer.



          I did my logic to logout and redirect.



          public function execute(Observer $observer)
          {
          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $customerSession = $objectManager->create('MagentoCustomerModelSession');
          $customerSession->logout();

          if($this->uri->isValid($particular_page)) {
          $resultRedirect = $this->responseFactory->create();
          $resultRedirect->setRedirect($particular_page)->sendResponse('200');
          exit();
          }
          }





          share|improve this answer























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "479"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f256159%2fmagento-2-logout-after-registration%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Try this



            di.xml add



            <?xml version="1.0"?>
            <!--
            /**
            * Copyright © 2016 Magento. All rights reserved.
            * See COPYING.txt for license details.
            */
            -->
            <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">

            <event name="customer_register_success">
            <observer name="custom_customer_created" instance="CustomModuleObserverCustomerEventCreatedObserver" />
            </event>

            </config>

            public function execute(Observer $observer)
            {
            $this->messageManager->addErrorMessage(__('Your account is not approved.'));
            $this->_response->setRedirect($this->_urlFactory->create()->getUrl('customer/account/logout'));

            }





            share|improve this answer
























            • Have the same set of coding its not working for me. facing the same issue. Its not redirecting it logs me in and takes me to home page.

              – fernandus
              Dec 31 '18 at 5:52


















            0














            Try this



            di.xml add



            <?xml version="1.0"?>
            <!--
            /**
            * Copyright © 2016 Magento. All rights reserved.
            * See COPYING.txt for license details.
            */
            -->
            <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">

            <event name="customer_register_success">
            <observer name="custom_customer_created" instance="CustomModuleObserverCustomerEventCreatedObserver" />
            </event>

            </config>

            public function execute(Observer $observer)
            {
            $this->messageManager->addErrorMessage(__('Your account is not approved.'));
            $this->_response->setRedirect($this->_urlFactory->create()->getUrl('customer/account/logout'));

            }





            share|improve this answer
























            • Have the same set of coding its not working for me. facing the same issue. Its not redirecting it logs me in and takes me to home page.

              – fernandus
              Dec 31 '18 at 5:52
















            0












            0








            0







            Try this



            di.xml add



            <?xml version="1.0"?>
            <!--
            /**
            * Copyright © 2016 Magento. All rights reserved.
            * See COPYING.txt for license details.
            */
            -->
            <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">

            <event name="customer_register_success">
            <observer name="custom_customer_created" instance="CustomModuleObserverCustomerEventCreatedObserver" />
            </event>

            </config>

            public function execute(Observer $observer)
            {
            $this->messageManager->addErrorMessage(__('Your account is not approved.'));
            $this->_response->setRedirect($this->_urlFactory->create()->getUrl('customer/account/logout'));

            }





            share|improve this answer













            Try this



            di.xml add



            <?xml version="1.0"?>
            <!--
            /**
            * Copyright © 2016 Magento. All rights reserved.
            * See COPYING.txt for license details.
            */
            -->
            <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">

            <event name="customer_register_success">
            <observer name="custom_customer_created" instance="CustomModuleObserverCustomerEventCreatedObserver" />
            </event>

            </config>

            public function execute(Observer $observer)
            {
            $this->messageManager->addErrorMessage(__('Your account is not approved.'));
            $this->_response->setRedirect($this->_urlFactory->create()->getUrl('customer/account/logout'));

            }






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Dec 29 '18 at 15:03









            Vijay-CyberLockerVijay-CyberLocker

            1376




            1376













            • Have the same set of coding its not working for me. facing the same issue. Its not redirecting it logs me in and takes me to home page.

              – fernandus
              Dec 31 '18 at 5:52





















            • Have the same set of coding its not working for me. facing the same issue. Its not redirecting it logs me in and takes me to home page.

              – fernandus
              Dec 31 '18 at 5:52



















            Have the same set of coding its not working for me. facing the same issue. Its not redirecting it logs me in and takes me to home page.

            – fernandus
            Dec 31 '18 at 5:52







            Have the same set of coding its not working for me. facing the same issue. Its not redirecting it logs me in and takes me to home page.

            – fernandus
            Dec 31 '18 at 5:52















            0














            I used this extension to trigger after Registration https://github.com/php-cuong/magento2-redirect-customer it used customer_login observer.



            I did my logic to logout and redirect.



            public function execute(Observer $observer)
            {
            $objectManager = MagentoFrameworkAppObjectManager::getInstance();
            $customerSession = $objectManager->create('MagentoCustomerModelSession');
            $customerSession->logout();

            if($this->uri->isValid($particular_page)) {
            $resultRedirect = $this->responseFactory->create();
            $resultRedirect->setRedirect($particular_page)->sendResponse('200');
            exit();
            }
            }





            share|improve this answer




























              0














              I used this extension to trigger after Registration https://github.com/php-cuong/magento2-redirect-customer it used customer_login observer.



              I did my logic to logout and redirect.



              public function execute(Observer $observer)
              {
              $objectManager = MagentoFrameworkAppObjectManager::getInstance();
              $customerSession = $objectManager->create('MagentoCustomerModelSession');
              $customerSession->logout();

              if($this->uri->isValid($particular_page)) {
              $resultRedirect = $this->responseFactory->create();
              $resultRedirect->setRedirect($particular_page)->sendResponse('200');
              exit();
              }
              }





              share|improve this answer


























                0












                0








                0







                I used this extension to trigger after Registration https://github.com/php-cuong/magento2-redirect-customer it used customer_login observer.



                I did my logic to logout and redirect.



                public function execute(Observer $observer)
                {
                $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                $customerSession = $objectManager->create('MagentoCustomerModelSession');
                $customerSession->logout();

                if($this->uri->isValid($particular_page)) {
                $resultRedirect = $this->responseFactory->create();
                $resultRedirect->setRedirect($particular_page)->sendResponse('200');
                exit();
                }
                }





                share|improve this answer













                I used this extension to trigger after Registration https://github.com/php-cuong/magento2-redirect-customer it used customer_login observer.



                I did my logic to logout and redirect.



                public function execute(Observer $observer)
                {
                $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                $customerSession = $objectManager->create('MagentoCustomerModelSession');
                $customerSession->logout();

                if($this->uri->isValid($particular_page)) {
                $resultRedirect = $this->responseFactory->create();
                $resultRedirect->setRedirect($particular_page)->sendResponse('200');
                exit();
                }
                }






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 18 at 13:40









                fernandusfernandus

                758




                758






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Magento Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f256159%2fmagento-2-logout-after-registration%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    An IMO inspired problem

                    Management

                    Investment