Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.50 KB | None | 0 0
  1.  public function redefinirSenha($token = null) {
  2.         if ($token) {
  3.             $query = $this->Usuarios->find('all', ['conditions' => ['token' => $token, 'token_timeout >' => time()]]);
  4.             $user = $query->first();
  5.             if ($user) {
  6.        
  7.                 if (!empty($this->request->data)) {
  8.                     echo "<pre>";
  9.                     $this->request->data['token'] = null;
  10.                     $this->request->data['token_timeout'] = null;
  11.  
  12.                    
  13.                     //print_r($this->request->getData());
  14.                     //Exibe:
  15.                     /*
  16. Array
  17. (
  18.     [password] => 123456
  19.     [password_confirm] => 123456
  20.     [token] =>
  21.     [token_timeout] =>
  22. )
  23. */
  24.                     $user = $this->Usuarios->patchEntity($user, $this->request->getData());
  25.                    
  26.                     if ($this->Usuarios->save($user)) {
  27.                         $this->Flash->set(__('Sua senha foi atualizada com sucesso.'));
  28.                         return $this->redirect(array('action' => 'login'));
  29.                     } else {
  30.                         $this->Flash->error(__('Não foi possível atualizar sua senha. Tente novamente.'));
  31.                     }
  32.                 }
  33.             } else {
  34.                 $this->Flash->error('O link acessado não é mais válido. Verifique seu email ou tente novamente');
  35.                 $this->redirect(['action' => 'password']);
  36.             }
  37.             unset($user->password);
  38.             $this->set(compact('user'));
  39.         } else {
  40.            
  41.             $this->redirect('/');
  42.         }
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement