繁体   English   中英

如何进行会员注册确认?

[英]How can I do member registration confirmation?

我如何在CakePHP注册?

注册后,它将发送电子邮件进行确认。

如果我点击链接进行确认,则会确认该帐户。

我怎样才能做到这一点?

Auth有没有这样做的功能?

或者我是否必须手动发送邮件以确认注册?

如果我必须手动发送电子邮件以确认注册,那么如何生成注册令牌,以及如何设置时间成为有效令牌?

有人能举例说明吗?

检查Cake Development Corporations用户插件的来源,它可用于CakepPHP 1.3和2.0。 https://github.com/cakedc/users它已经完成了你所要求的一切 - 以适当的MVC和CakePHP方式。 只需使用插件或采取一些代码。

用户表:

CREATE TABLE IF NOT EXISTS `users` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `username` varchar(255) COLLATE utf8_persian_ci NOT NULL,
  `password` varchar(255) COLLATE utf8_persian_ci NOT NULL,
  `email` varchar(100) COLLATE utf8_persian_ci NOT NULL,
  `created` datetime NOT NULL,
  `status` tinyint(1) NOT NULL,
  `activation_code` varchar(255) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_persian_ci AUTO_INCREMENT=4 ;

当用户注册时,你可以在activation_code字段中设置一个唯一的字符串(sample:md5(time())或任何东西...)。 现在发送像这个网址的电子邮件给用户:

http://test/controller/action/activation_code

现在你必须检查你的行动,这个activation_code是否在用户表中。

如果是那么状态=禁用或不....

您可以在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);

    }

发送电子邮件也加载电子邮件组件。 给出的寄存器功能很好,您应该使用它。

基本上概念是添加用户,然后创建一个令牌(使用时间戳ro),并将其保存到数据库,然后发送带有该令牌链接的电子邮件。

然后,当用户单击指向令牌的链接时,您将设置user = active,现在他们已注册并可以登录。

因此,您的Auth的一个很好的提示是向Auth添加“范围”(检查1.3的cakephp文档)。 使这个范围成为active = 1的条件。这样他们就需要从电子邮件链接中确认,并且在完成之前永远不能登录。 简单!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM