Skip to content

Instantly share code, notes, and snippets.

@rfos
Created February 17, 2015 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rfos/b5a705ada498b8c1f4a4 to your computer and use it in GitHub Desktop.
Save rfos/b5a705ada498b8c1f4a4 to your computer and use it in GitHub Desktop.
Validação Link
//UserController.php
public function validarSenha($id, $token) {
$this->autoRender = false;
if (empty($id) || empty($token))
throw new NotFoundException;
if ($user = $this->User->passReset($id, $token)) {
$this->Auth->login($user['User']);
$this->redirect(array('controller' => 'perfil', 'action' => 'troca-senha' . '/' . $id));
} else {
$this->Session->setFlash('O link informado já foi utilizado ou está incorreto', 'flash/error');
$this->redirect(array('controller' => 'inicio', 'action' => 'login'));
}
}
// Model User.php
//Ativação do usuário
public function passReset($id, $token)
{
//Checa se existe o usuário informado com o respectivo código
if ($this->hasAny(array("{$this->alias}.id" => $id, "{$this->alias}.token" => $token))) {
return $this->read(array('id', 'nome', 'email', 'token', 'group_id'), $id);
}
// Se nao encontra valores, retorna false para Controller validaEmail
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment