Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Update</strong> </p> <blockquote> <p>Add resetkey field in usertable. </p> </blockquote> <p>in <strong>UserModel</strong> create <code>beforeSave</code> action and add this line in that action</p> <pre><code>public function beforeSave($options = array()) { parent::beforeSave($options = array()); if (isset($this-&gt;data['User']['password'])) { $this-&gt;data['User']['password'] = AuthComponent::password($this-&gt;data['User']['password']); } $this-&gt;data['User']['resetkey'] = Security::hash(mt_rand(),'md5',true); return true; } </code></pre> <p>When user apply for forgot passowrd, send this resetkey to his email. <strong>SomeController</strong> <strong>this is hint of forgot action</strong></p> <pre><code>if($this-&gt;request-&gt;is('post')) { $this-&gt;loadModel('User'); $mail = $this-&gt;request-&gt;data['User']['mail']; $data = $this-&gt;User-&gt;findByMail($mail); $key = $data['User']['resetkey']; if(!$data) { $message = __('No Such E-mail address registerd with us '); $this-&gt;Session-&gt;setFlash($message,'flash',array('alert'=&gt;'error')); } else { $key = $data['User']['resetkey']; $id = $data['User']['id']; $mail = $data['User']['email']; $email = new CakeEmail('smtp'); $email-&gt;to($mail); $email-&gt;from("service@localhost.com"); $email-&gt;emailFormat('html'); $email-&gt;subject('Password reset instructions from'); $email-&gt;viewVars(array('key'=&gt;$key,'id'=&gt;$id,'rand'=&gt; mt_rand())); $email-&gt;template('reset'); if($email-&gt;send('reset')) { $message = __('Please check your email for reset instructions.'); $this-&gt;Session-&gt;setFlash($message,'flash',array('alert'=&gt;'success')); } else { $message = __('Something went wrong with activation mail. Please try later.'); $this-&gt;Session-&gt;setFlash($message,'flash',array('alert'=&gt;'error')); } } $this-&gt;redirect('/'); } </code></pre> <p>Send that reset key to user so when User will change password, <code>Auth</code> will call <code>beforSave</code> save action and will update reset key. so no one can access rest password page using same key.<br> <strong>Email Template</strong></p> <blockquote> <p><code>App/View/Emails/reset.ctp</code></p> </blockquote> <pre><code>&lt;p&gt;Please click on the link below to reset your password.&lt;/p&gt; &lt;a href="http://&lt;?= $_SERVER['HTTP_HOST']; ?&gt;/reset/&lt;?= $key .'BXX'.$rand.'XXB'. $id ?&gt;/"&gt;Click here to reset your account password&lt;/a&gt; &lt;hr /&gt; &lt;p&gt;Alternatively, you can also copy paste the below link into your browser: &lt;/p&gt; &lt;p&gt;http://&lt;?= $_SERVER['HTTP_HOST']; ?&gt;/reset/&lt;?= $key .'BXX'.$rand.'XXB'. $id ?&gt;/&lt;/p&gt; &lt;p&gt;This email was sent by &lt;?= APPNAME ?&gt;.&lt;/p&gt; </code></pre> <p>You can define <code>APPNAME</code> in <strong><code>App/Config/bootstrap.php</code></strong> By adding following code</p> <blockquote> <p><code>define('APPNAME','FooBar');</code><br> <strong>this is hint of reset action</strong></p> </blockquote> <pre><code>$this-&gt;loadModel('User'); $a = func_get_args(); $keyPair = $a[0]; $key = explode('BXX', $keyPair); $pair = explode('XXB',$key[1]); $key = $key[0]; $pair = $pair[1]; $password = $this-&gt;request-&gt;data['User']['password']; unset($this-&gt;request-&gt;data['User']['password']); $uArr = $this-&gt;User-&gt;findById($pair); if($uArr['User']['resetkey'] == $key) { $this-&gt;User-&gt;read(null, $pair); $this-&gt;User-&gt;set('password', $password); if($this-&gt;User-&gt;save()) { $message = __('Your password has been reset'); $this-&gt;Session-&gt;setFlash($message,'flash',array('alert'=&gt;'success')); } else { $message = __('Something has gone wrong. Please try later or &lt;b&gt;sign up again&lt;/b&gt;'); $this-&gt;Session-&gt;setFlash($message,'flash',array('alert'=&gt;'alert')); } } else { $message = __('&lt;b&gt;Please check your reset link&lt;/b&gt;'); $this-&gt;Session-&gt;setFlash($message, 'flash', array('alert'=&gt; 'error')); } </code></pre> <p><strong>In Routs</strong></p> <blockquote> <p><code>Router::connect('/reset/*',array('controller'=&gt;'Home','action'=&gt;'reset'));</code><br> And your forgot password function is ready</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload