Get forgot password link in magento2

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
1
down vote

favorite












I am trying to get forgot password link in my controller with below code



 class CreatePost extends MagentoFrameworkAppActionAction
{
protected $_messageManager;
protected $customerForgotUrl;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkMessageManagerInterface $messageManager,
MagentoCustomerModelUrl $customerForgotUrl
)
$this->_messageManager = $messageManager;
$this->_customerForgotUrl = $customerForgotUrl;
parent::__construct($context);

try
$user->save();
catch (MagentoFrameworkExceptionAlreadyExistsException $e)
$url = $this->_customerForgotUrl->getForgotPasswordUrl();
$message = $this->__('There is already an account with this emails address. If you are sure that it is your email address, <a href="%s">click here</a> to get the password and access your account.', $url);
$this->_messageManager()->addError($message);



Its not working. Please anyone suggest on this.







share|improve this question






















  • Seems to me like you are not using execute method. Can you check the updated answer. I have added die.
    – LAW
    Aug 14 at 7:23
















up vote
1
down vote

favorite












I am trying to get forgot password link in my controller with below code



 class CreatePost extends MagentoFrameworkAppActionAction
{
protected $_messageManager;
protected $customerForgotUrl;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkMessageManagerInterface $messageManager,
MagentoCustomerModelUrl $customerForgotUrl
)
$this->_messageManager = $messageManager;
$this->_customerForgotUrl = $customerForgotUrl;
parent::__construct($context);

try
$user->save();
catch (MagentoFrameworkExceptionAlreadyExistsException $e)
$url = $this->_customerForgotUrl->getForgotPasswordUrl();
$message = $this->__('There is already an account with this emails address. If you are sure that it is your email address, <a href="%s">click here</a> to get the password and access your account.', $url);
$this->_messageManager()->addError($message);



Its not working. Please anyone suggest on this.







share|improve this question






















  • Seems to me like you are not using execute method. Can you check the updated answer. I have added die.
    – LAW
    Aug 14 at 7:23












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I am trying to get forgot password link in my controller with below code



 class CreatePost extends MagentoFrameworkAppActionAction
{
protected $_messageManager;
protected $customerForgotUrl;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkMessageManagerInterface $messageManager,
MagentoCustomerModelUrl $customerForgotUrl
)
$this->_messageManager = $messageManager;
$this->_customerForgotUrl = $customerForgotUrl;
parent::__construct($context);

try
$user->save();
catch (MagentoFrameworkExceptionAlreadyExistsException $e)
$url = $this->_customerForgotUrl->getForgotPasswordUrl();
$message = $this->__('There is already an account with this emails address. If you are sure that it is your email address, <a href="%s">click here</a> to get the password and access your account.', $url);
$this->_messageManager()->addError($message);



Its not working. Please anyone suggest on this.







share|improve this question














I am trying to get forgot password link in my controller with below code



 class CreatePost extends MagentoFrameworkAppActionAction
{
protected $_messageManager;
protected $customerForgotUrl;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkMessageManagerInterface $messageManager,
MagentoCustomerModelUrl $customerForgotUrl
)
$this->_messageManager = $messageManager;
$this->_customerForgotUrl = $customerForgotUrl;
parent::__construct($context);

try
$user->save();
catch (MagentoFrameworkExceptionAlreadyExistsException $e)
$url = $this->_customerForgotUrl->getForgotPasswordUrl();
$message = $this->__('There is already an account with this emails address. If you are sure that it is your email address, <a href="%s">click here</a> to get the password and access your account.', $url);
$this->_messageManager()->addError($message);



Its not working. Please anyone suggest on this.









share|improve this question













share|improve this question




share|improve this question








edited Aug 14 at 10:08

























asked Aug 14 at 6:44









jafar pinjar

357110




357110











  • Seems to me like you are not using execute method. Can you check the updated answer. I have added die.
    – LAW
    Aug 14 at 7:23
















  • Seems to me like you are not using execute method. Can you check the updated answer. I have added die.
    – LAW
    Aug 14 at 7:23















Seems to me like you are not using execute method. Can you check the updated answer. I have added die.
– LAW
Aug 14 at 7:23




Seems to me like you are not using execute method. Can you check the updated answer. I have added die.
– LAW
Aug 14 at 7:23










2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










Try this:



class CreatePost extends MagentoFrameworkAppActionAction 

public function __construct(
MagentoFrameworkAppActionContext $context
)
parent::__construct($context);


public function execute()
try
$user->save();
catch (MagentoFrameworkExceptionAlreadyExistsException $e)

$url = $this->_url->getUrl('customer/account/forgotpassword');
$message = $this->__('There is already an account with this emails address. If you are sure that it is your email address, <a href="%s">click here</a> to get the password and access your account.', $url);
$this->messageManager->addErrorMessage($message);









share|improve this answer






















  • Anything i need to construct to use _url? Directly can i use above code?
    – jafar pinjar
    Aug 14 at 6:56











  • No, in the controller it does not need to add anything in __construct because __construct method already in MagentoFrameworkAppActionAction.
    – kunj
    Aug 14 at 6:58










  • I used your code , its not working
    – jafar pinjar
    Aug 14 at 7:02










  • @jafar, May I have your controller code?
    – kunj
    Aug 14 at 7:03











  • Updated my code, please take a look.
    – jafar pinjar
    Aug 14 at 7:07

















up vote
1
down vote













EDIT - Based on your code



class CreatePost extends MagentoFrameworkAppActionAction 
protected $_messageManager;
protected $customerForgotUrl;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkMessageManagerInterface $messageManager,
MagentoCustomerModelUrl $customerForgotUrl
)
$this->_messageManager = $messageManager;
$this->_customerForgotUrl = $customerForgotUrl;
parent::__construct($context);


public function execute()
try
$user->save();
catch (MagentoFrameworkExceptionAlreadyExistsException $e)
echo $url1 = $this->_customerForgotUrl->getForgotPasswordUrl();

echo $url2 = $this->_url->getUrl('customer/account/forgotpassword');
die();
$message = $this->__('There is already an account with this emails address. If you are sure that it is your email address, <a href="%s">click here</a> to get the password and access your account.', $url);
$this->_messageManager()->addError($message);









share|improve this answer






















  • Tried this also, Its not working
    – jafar pinjar
    Aug 14 at 7:09










  • I used this code getting error like this, PHP Fatal error: Uncaught Error: Call to undefined method at line $url1 = $this->_customerForgotUrl->getForgotPasswordUrl();
    – jafar pinjar
    Aug 14 at 7:51










  • I believe that will not be needed for you. The link will work using $url2. That I wrote just for you to check. You can comment that out.
    – LAW
    Aug 14 at 7:53











  • so injecting _customerForgotUrl is not required?
    – jafar pinjar
    Aug 14 at 7:58










  • Yes should not be needed, I have updated my answer, the issue with your code was with execute function
    – LAW
    Aug 14 at 8:00










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',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
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%2f238276%2fget-forgot-password-link-in-magento2%23new-answer', 'question_page');

);

Post as a guest






























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










Try this:



class CreatePost extends MagentoFrameworkAppActionAction 

public function __construct(
MagentoFrameworkAppActionContext $context
)
parent::__construct($context);


public function execute()
try
$user->save();
catch (MagentoFrameworkExceptionAlreadyExistsException $e)

$url = $this->_url->getUrl('customer/account/forgotpassword');
$message = $this->__('There is already an account with this emails address. If you are sure that it is your email address, <a href="%s">click here</a> to get the password and access your account.', $url);
$this->messageManager->addErrorMessage($message);









share|improve this answer






















  • Anything i need to construct to use _url? Directly can i use above code?
    – jafar pinjar
    Aug 14 at 6:56











  • No, in the controller it does not need to add anything in __construct because __construct method already in MagentoFrameworkAppActionAction.
    – kunj
    Aug 14 at 6:58










  • I used your code , its not working
    – jafar pinjar
    Aug 14 at 7:02










  • @jafar, May I have your controller code?
    – kunj
    Aug 14 at 7:03











  • Updated my code, please take a look.
    – jafar pinjar
    Aug 14 at 7:07














up vote
1
down vote



accepted










Try this:



class CreatePost extends MagentoFrameworkAppActionAction 

public function __construct(
MagentoFrameworkAppActionContext $context
)
parent::__construct($context);


public function execute()
try
$user->save();
catch (MagentoFrameworkExceptionAlreadyExistsException $e)

$url = $this->_url->getUrl('customer/account/forgotpassword');
$message = $this->__('There is already an account with this emails address. If you are sure that it is your email address, <a href="%s">click here</a> to get the password and access your account.', $url);
$this->messageManager->addErrorMessage($message);









share|improve this answer






















  • Anything i need to construct to use _url? Directly can i use above code?
    – jafar pinjar
    Aug 14 at 6:56











  • No, in the controller it does not need to add anything in __construct because __construct method already in MagentoFrameworkAppActionAction.
    – kunj
    Aug 14 at 6:58










  • I used your code , its not working
    – jafar pinjar
    Aug 14 at 7:02










  • @jafar, May I have your controller code?
    – kunj
    Aug 14 at 7:03











  • Updated my code, please take a look.
    – jafar pinjar
    Aug 14 at 7:07












up vote
1
down vote



accepted







up vote
1
down vote



accepted






Try this:



class CreatePost extends MagentoFrameworkAppActionAction 

public function __construct(
MagentoFrameworkAppActionContext $context
)
parent::__construct($context);


public function execute()
try
$user->save();
catch (MagentoFrameworkExceptionAlreadyExistsException $e)

$url = $this->_url->getUrl('customer/account/forgotpassword');
$message = $this->__('There is already an account with this emails address. If you are sure that it is your email address, <a href="%s">click here</a> to get the password and access your account.', $url);
$this->messageManager->addErrorMessage($message);









share|improve this answer














Try this:



class CreatePost extends MagentoFrameworkAppActionAction 

public function __construct(
MagentoFrameworkAppActionContext $context
)
parent::__construct($context);


public function execute()
try
$user->save();
catch (MagentoFrameworkExceptionAlreadyExistsException $e)

$url = $this->_url->getUrl('customer/account/forgotpassword');
$message = $this->__('There is already an account with this emails address. If you are sure that it is your email address, <a href="%s">click here</a> to get the password and access your account.', $url);
$this->messageManager->addErrorMessage($message);










share|improve this answer














share|improve this answer



share|improve this answer








edited Aug 14 at 8:13

























answered Aug 14 at 6:52









kunj

2,3672420




2,3672420











  • Anything i need to construct to use _url? Directly can i use above code?
    – jafar pinjar
    Aug 14 at 6:56











  • No, in the controller it does not need to add anything in __construct because __construct method already in MagentoFrameworkAppActionAction.
    – kunj
    Aug 14 at 6:58










  • I used your code , its not working
    – jafar pinjar
    Aug 14 at 7:02










  • @jafar, May I have your controller code?
    – kunj
    Aug 14 at 7:03











  • Updated my code, please take a look.
    – jafar pinjar
    Aug 14 at 7:07
















  • Anything i need to construct to use _url? Directly can i use above code?
    – jafar pinjar
    Aug 14 at 6:56











  • No, in the controller it does not need to add anything in __construct because __construct method already in MagentoFrameworkAppActionAction.
    – kunj
    Aug 14 at 6:58










  • I used your code , its not working
    – jafar pinjar
    Aug 14 at 7:02










  • @jafar, May I have your controller code?
    – kunj
    Aug 14 at 7:03











  • Updated my code, please take a look.
    – jafar pinjar
    Aug 14 at 7:07















Anything i need to construct to use _url? Directly can i use above code?
– jafar pinjar
Aug 14 at 6:56





Anything i need to construct to use _url? Directly can i use above code?
– jafar pinjar
Aug 14 at 6:56













No, in the controller it does not need to add anything in __construct because __construct method already in MagentoFrameworkAppActionAction.
– kunj
Aug 14 at 6:58




No, in the controller it does not need to add anything in __construct because __construct method already in MagentoFrameworkAppActionAction.
– kunj
Aug 14 at 6:58












I used your code , its not working
– jafar pinjar
Aug 14 at 7:02




I used your code , its not working
– jafar pinjar
Aug 14 at 7:02












@jafar, May I have your controller code?
– kunj
Aug 14 at 7:03





@jafar, May I have your controller code?
– kunj
Aug 14 at 7:03













Updated my code, please take a look.
– jafar pinjar
Aug 14 at 7:07




Updated my code, please take a look.
– jafar pinjar
Aug 14 at 7:07












up vote
1
down vote













EDIT - Based on your code



class CreatePost extends MagentoFrameworkAppActionAction 
protected $_messageManager;
protected $customerForgotUrl;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkMessageManagerInterface $messageManager,
MagentoCustomerModelUrl $customerForgotUrl
)
$this->_messageManager = $messageManager;
$this->_customerForgotUrl = $customerForgotUrl;
parent::__construct($context);


public function execute()
try
$user->save();
catch (MagentoFrameworkExceptionAlreadyExistsException $e)
echo $url1 = $this->_customerForgotUrl->getForgotPasswordUrl();

echo $url2 = $this->_url->getUrl('customer/account/forgotpassword');
die();
$message = $this->__('There is already an account with this emails address. If you are sure that it is your email address, <a href="%s">click here</a> to get the password and access your account.', $url);
$this->_messageManager()->addError($message);









share|improve this answer






















  • Tried this also, Its not working
    – jafar pinjar
    Aug 14 at 7:09










  • I used this code getting error like this, PHP Fatal error: Uncaught Error: Call to undefined method at line $url1 = $this->_customerForgotUrl->getForgotPasswordUrl();
    – jafar pinjar
    Aug 14 at 7:51










  • I believe that will not be needed for you. The link will work using $url2. That I wrote just for you to check. You can comment that out.
    – LAW
    Aug 14 at 7:53











  • so injecting _customerForgotUrl is not required?
    – jafar pinjar
    Aug 14 at 7:58










  • Yes should not be needed, I have updated my answer, the issue with your code was with execute function
    – LAW
    Aug 14 at 8:00














up vote
1
down vote













EDIT - Based on your code



class CreatePost extends MagentoFrameworkAppActionAction 
protected $_messageManager;
protected $customerForgotUrl;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkMessageManagerInterface $messageManager,
MagentoCustomerModelUrl $customerForgotUrl
)
$this->_messageManager = $messageManager;
$this->_customerForgotUrl = $customerForgotUrl;
parent::__construct($context);


public function execute()
try
$user->save();
catch (MagentoFrameworkExceptionAlreadyExistsException $e)
echo $url1 = $this->_customerForgotUrl->getForgotPasswordUrl();

echo $url2 = $this->_url->getUrl('customer/account/forgotpassword');
die();
$message = $this->__('There is already an account with this emails address. If you are sure that it is your email address, <a href="%s">click here</a> to get the password and access your account.', $url);
$this->_messageManager()->addError($message);









share|improve this answer






















  • Tried this also, Its not working
    – jafar pinjar
    Aug 14 at 7:09










  • I used this code getting error like this, PHP Fatal error: Uncaught Error: Call to undefined method at line $url1 = $this->_customerForgotUrl->getForgotPasswordUrl();
    – jafar pinjar
    Aug 14 at 7:51










  • I believe that will not be needed for you. The link will work using $url2. That I wrote just for you to check. You can comment that out.
    – LAW
    Aug 14 at 7:53











  • so injecting _customerForgotUrl is not required?
    – jafar pinjar
    Aug 14 at 7:58










  • Yes should not be needed, I have updated my answer, the issue with your code was with execute function
    – LAW
    Aug 14 at 8:00












up vote
1
down vote










up vote
1
down vote









EDIT - Based on your code



class CreatePost extends MagentoFrameworkAppActionAction 
protected $_messageManager;
protected $customerForgotUrl;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkMessageManagerInterface $messageManager,
MagentoCustomerModelUrl $customerForgotUrl
)
$this->_messageManager = $messageManager;
$this->_customerForgotUrl = $customerForgotUrl;
parent::__construct($context);


public function execute()
try
$user->save();
catch (MagentoFrameworkExceptionAlreadyExistsException $e)
echo $url1 = $this->_customerForgotUrl->getForgotPasswordUrl();

echo $url2 = $this->_url->getUrl('customer/account/forgotpassword');
die();
$message = $this->__('There is already an account with this emails address. If you are sure that it is your email address, <a href="%s">click here</a> to get the password and access your account.', $url);
$this->_messageManager()->addError($message);









share|improve this answer














EDIT - Based on your code



class CreatePost extends MagentoFrameworkAppActionAction 
protected $_messageManager;
protected $customerForgotUrl;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkMessageManagerInterface $messageManager,
MagentoCustomerModelUrl $customerForgotUrl
)
$this->_messageManager = $messageManager;
$this->_customerForgotUrl = $customerForgotUrl;
parent::__construct($context);


public function execute()
try
$user->save();
catch (MagentoFrameworkExceptionAlreadyExistsException $e)
echo $url1 = $this->_customerForgotUrl->getForgotPasswordUrl();

echo $url2 = $this->_url->getUrl('customer/account/forgotpassword');
die();
$message = $this->__('There is already an account with this emails address. If you are sure that it is your email address, <a href="%s">click here</a> to get the password and access your account.', $url);
$this->_messageManager()->addError($message);










share|improve this answer














share|improve this answer



share|improve this answer








edited Aug 14 at 8:00

























answered Aug 14 at 6:56









LAW

623416




623416











  • Tried this also, Its not working
    – jafar pinjar
    Aug 14 at 7:09










  • I used this code getting error like this, PHP Fatal error: Uncaught Error: Call to undefined method at line $url1 = $this->_customerForgotUrl->getForgotPasswordUrl();
    – jafar pinjar
    Aug 14 at 7:51










  • I believe that will not be needed for you. The link will work using $url2. That I wrote just for you to check. You can comment that out.
    – LAW
    Aug 14 at 7:53











  • so injecting _customerForgotUrl is not required?
    – jafar pinjar
    Aug 14 at 7:58










  • Yes should not be needed, I have updated my answer, the issue with your code was with execute function
    – LAW
    Aug 14 at 8:00
















  • Tried this also, Its not working
    – jafar pinjar
    Aug 14 at 7:09










  • I used this code getting error like this, PHP Fatal error: Uncaught Error: Call to undefined method at line $url1 = $this->_customerForgotUrl->getForgotPasswordUrl();
    – jafar pinjar
    Aug 14 at 7:51










  • I believe that will not be needed for you. The link will work using $url2. That I wrote just for you to check. You can comment that out.
    – LAW
    Aug 14 at 7:53











  • so injecting _customerForgotUrl is not required?
    – jafar pinjar
    Aug 14 at 7:58










  • Yes should not be needed, I have updated my answer, the issue with your code was with execute function
    – LAW
    Aug 14 at 8:00















Tried this also, Its not working
– jafar pinjar
Aug 14 at 7:09




Tried this also, Its not working
– jafar pinjar
Aug 14 at 7:09












I used this code getting error like this, PHP Fatal error: Uncaught Error: Call to undefined method at line $url1 = $this->_customerForgotUrl->getForgotPasswordUrl();
– jafar pinjar
Aug 14 at 7:51




I used this code getting error like this, PHP Fatal error: Uncaught Error: Call to undefined method at line $url1 = $this->_customerForgotUrl->getForgotPasswordUrl();
– jafar pinjar
Aug 14 at 7:51












I believe that will not be needed for you. The link will work using $url2. That I wrote just for you to check. You can comment that out.
– LAW
Aug 14 at 7:53





I believe that will not be needed for you. The link will work using $url2. That I wrote just for you to check. You can comment that out.
– LAW
Aug 14 at 7:53













so injecting _customerForgotUrl is not required?
– jafar pinjar
Aug 14 at 7:58




so injecting _customerForgotUrl is not required?
– jafar pinjar
Aug 14 at 7:58












Yes should not be needed, I have updated my answer, the issue with your code was with execute function
– LAW
Aug 14 at 8:00




Yes should not be needed, I have updated my answer, the issue with your code was with execute function
– LAW
Aug 14 at 8:00

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f238276%2fget-forgot-password-link-in-magento2%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

Long meetings (6-7 hours a day): Being “babysat” by supervisor

Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

Confectionery