Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Reset Password link code in cakephp

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 199
    Comment on it

    Hello Readers! Here is a cakephp code to reset your password.

    Create a view reset.ctp and paste the below code to it:

    <?php echo $this->Session->flash(); ?>
    <div class="container">
        <div class="midBlock clearfix">
          <div class="col-md-12">
            <h1 class="text-center">Enter your credentials below to <p>Login</p></h1>
              <?php echo $this->Form->create('User',array('controller'=>'users','inputDefaults' => array('label' => false,'div' => false))) ;?>
                <ul class="login">
                  <li>
                    <?php echo $this->Form->password('password',array('placeholder'=>"Enter Password")); ?>
                  </li>
                  <li>
                    <?php echo $this->Form->password("confirm",array('placeholder'=>"Confirm Password")); ?>
                  </li>
                  <li>
                    <?php echo $this->Form->submit('Reset',array('class'=>'btnNew')); ?>
                  </li>
                </ul>
              </form>
          </div>
        </div>
      </div>

     

    Next create the reset function in  UserController.php:

    public function reset($id=null){
           if(!empty($id) && isset($id))
           {
                $result= $this->User->find('first',array('conditions'=>array('User.hexkey'=>$id)));
    
           }
     
            if ($this->request->is('post')) {
                // print_r($result);
                $this->request->data['User']['id'] = $result['User']['id'];
                // print_r($this->request->data);die;
                if ($this->User->save($this->request->data)) {
                    $this->Session->setFlash("Password Changed successfully!!");
                    $this->redirect(array('controller'=>'Users','action'=>'login'));
                }else{
                    $this->Session->setFlash("Something went Wrong!!");
                }
            }
        }

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: