Sufyan

Change Password [CakePHP]

Jan 5th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.69 KB | None | 0 0
  1.   public function change_pass()
  2.     {
  3.       $this->layout = 'base_layout';
  4.       if ($this->request->is('post','put'))
  5.       {
  6.           $old_pass = $this->request->data['User']['old_password'];
  7.           $new_pass = $this->request->data['User']['new_password'];
  8.           $con_pass = $this->request->data['User']['confirm_password'];
  9.  
  10.           if($con_pass == $new_pass)
  11.           {
  12.  
  13.  
  14.           //    pr($this->request->data);
  15.             $params =
  16.               array(
  17.                 'conditions' => array(
  18.                       'username' => $_SESSION['username'],
  19.                       'password' => $old_pass//$this->request->data['User']['old_password']
  20.                 )
  21.               );
  22.             $result = $this->User->find('all', $params);
  23.               if($result != null)
  24.               {
  25.                   $this->User->id = $result[0]['User']['id'];
  26.  
  27.                   $this->User->set(array('password'=>$new_pass));
  28.  
  29.                     if($this->User->save())
  30.                     {
  31.                         $this->Flash->success(__('Success! Password successfully changed! '));
  32.                     }
  33.                     else {
  34.                       # code...
  35.                      $this->Flash->error(
  36.                           __('Oops! Something went wrong!')
  37.                       );
  38.                     }
  39.  
  40.               }
  41.               else {
  42.                 $this->Flash->error(
  43.                     __('Oops! Sorry your current password is invalid!')
  44.                 );
  45.               }
  46.           }
  47.           else {
  48.             $this->Flash->error(
  49.                 __('Oops! Sorry your Passwords are not matched!')
  50.             );
  51.           }
  52.       }
  53.     }
Add Comment
Please, Sign In to add comment