Magento 2 Logout after Registration
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
add a comment |
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
add a comment |
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
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
magento2 registration logout
asked Dec 29 '18 at 14:24
fernandusfernandus
758
758
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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'));
}
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
add a comment |
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();
}
}
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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'));
}
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
add a comment |
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'));
}
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
add a comment |
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'));
}
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'));
}
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
add a comment |
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
add a comment |
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();
}
}
add a comment |
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();
}
}
add a comment |
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();
}
}
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();
}
}
answered Jan 18 at 13:40
fernandusfernandus
758
758
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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