thinphp5会员注册邮箱验证

1、首先完成邮箱发送http://www.cnblogs.com/jcydd/p/7299750.html

2、在完成会员新增后执行后置函数,在模型类当中
//注册后置函数
protected static function init()
{
    self::event('after_insert', function ($data) {
        $url="http://127.0.0.1/shop/public/index.php/index/user/check?id=".$data['mb_id']."&&token=".$data['mail_str'];
        $url2="<a href='".$url."'>点击激活</a>";
        sendMail($data['mb_email'],'亲爱的'.$data['mb_username'],$url2);

    });
}

3、在控制器当中定义验证函数

public function check(){
    $mb_id=input('param.id');
    $mail_str=input('param.token');
    $user=model('user');
    if($user->where('mb_id',$mb_id)->value('check_mail')==0) {
        $mailstr = $user->where('mb_id', $mb_id)->value('mail_str');
        if ($mail_str == $mailstr) {
            if ($user->where('mb_id', $mb_id)->update(['check_mail' => 1])) {
                $this->success('激活成功,请登录...', 'login');
            }
        } else {
            $this->error('无效链接');
        }
    }else{
        $this->error('已激活链接,请登录','login');
    }
}

 

posted @ 2017-08-07 16:25  坚持一点点  阅读(338)  评论(0)    收藏  举报