Вы можете легко сгенерировать хеш-код, такой как токен в PHP, и проверить его продолжительность с помощью TimeStamp.Для электронной почты просто используйте компонент электронной почты, как это.Если вы хотите использовать Auth Component, убедитесь, что в вашей форме указан правильный хэш для пароля.
function register() {
$error = false;
$error_captcha = null;
if(isset($this->data)){
App::import('Component','Generate');
App::import('Component', 'Converter');
App::import('Component','Email');
if(empty($this->data['User']['password'])||strlen($this->data['User']['password'])<5){
$this->User->invalidate("password");
$error = TRUE;
}
if($this->data['User']['password']<>$this->data['Temp']['password']){
$this->User->invalidate("seotitle");
$error = TRUE;
}
$captcha_respuesta = recaptcha_check_answer ($this->captcha_privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if ($captcha_respuesta->is_valid && !$error) {
$this->data['User']['coderegistration'] = $this->generate->getUserCode();
$this->data['User']['displayname'] = $this->data['User']['firstname'] . " " . $this->data['User']['lastname'];
$this->data['User']['seotitle'] = $this->converter->seotitle($this->data['User']['username']);
$this->data['User']['password'] = md5($this->data['User']['username'].$this->data['User']['password']);
$this->User->id = NULL;
if($this->User->save($this->data)){
/*
=========================
send email notification
=========================
*/
$email = $this->data['User']['email'];
$content = sprintf('<a href="%s/%s">here</div>', $this->url, $this->data['User']['coderegistration']);
$this->email->to = $email;
$this->email->subject = 'you have been registered, please confirm';
$this->email->replyTo = 'mail@mail.com';
$this->email->from = "name <mail@mail.com>";
$this->email->template = 'notification';
$this->email->sendAs = 'html';
$this->set('value', $content);
if($this->email->send()){
// OK
}else{
trigger_error("error Mail");
}
}
}else{
$error_captcha = $captcha_respuesta->error;
$this->set('error_email',true);
}
}
$this->setTitlePage();
$this->layout = "home";
$this->set('backurl', '/');
$this->set('posturl','');
$this->set('captcha_publickey',$this->captcha_publickey);
}