Jump to content

[SOLVED] Allow users to set Forgot Password


Recommended Posts

Hi guys,

 

The current default Prestashop Forgot Password flow is:

 

1. User clicks "Forgot your password?" link

2. User inputs their email address

3. User receives and email with a link and clicks

4. User receives another email with new password

5. User logs in with new password and change their password in "My Account"

 

Is it possible to reduce the 4th step so that when the user clicks the link in the first email they received, they would be able to change their password immediately instead of having to receive another email?

 

Thanks and all help is appreciated.

Edited by hideaki (see edit history)
Link to comment
Share on other sites

Solved my own question. Here's the small hack should anyone require this feature in future:

 

In password.tpl, look for line (around 34):

 

{if isset($confirmation) && $confirmation == 1}

 

And insert after:

 

 <form method="post" class="std">
 <fieldset>
  <p class="password">
   <label for="passwd">{l s='New Password'}</label>
   <input type="password" name="passwd" id="passwd" />
  </p>
  <p class="password">
   <label for="confirmation">{l s='Confirmation'}</label>
   <input type="password" name="confirmation" id="confirmation" />
  </p>
  <p class="submit">
   <input type="submit" class="button" name="submitPass" value="{l s='Save'}" />
  </p>
 </fieldset>
</form>

 

 

In PasswordController.php, look for line (around 76):

 

if ($email)

 

Replace code inbetween (lines 78 - 101) with:

 

self::$smarty->assign(array('confirmation' => 1, 'token' => $token, 'id_customer' => $id_customer));

 

Again in PasswordController.php, look for line (around 41):

 

parent::process();

 

And insert after:

 

  if (Tools::isSubmit('submitPass'))
 {
  $token = Tools::getValue('token');
  $id_customer = Tools::getValue('id_customer');
  $email = Db::getInstance()->getValue('SELECT `email` FROM '._DB_PREFIX_.'customer c WHERE c.`secure_key` = "'.pSQL($token).'" AND c.id_customer='.(int)($id_customer));
  if ($email)
  {
   $customer = new Customer();
   $customer->getByemail($email);

   if ($_POST['passwd'] != $_POST['confirmation'])
   {
 $this->errors[] = Tools::displayError('Password and confirmation do not match');
   }
   else
   {
 $customer->passwd = Tools::encrypt($password = $_POST['passwd']);
 $customer->last_passwd_gen = date('Y-m-d H:i:s', time());
 if ($customer->update())
 {
  Tools::redirect('authentication.php');
 }
 else
 {
  $this->errors[] = Tools::displayError('An error occurred with your account and your new password cannot be changed. Please report your problem using the contact form.');
 }
   }
  }
  else
  {
   $this->errors[] = Tools::displayError('You cannot change your password with the data submitted');
  }
 }

 

Good luck to anyone trying this out!

Link to comment
Share on other sites

  • 2 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...