Exemplo n.º 1
0
    def put(self, request):
        # 1,获取参数
        dict_data = json.loads(request.body.decode())
        email = dict_data.get("email")
        print('email:', email)

        # 2,校验参数
        # 2.1 为空校验
        if not email:
            return http.HttpResponseForbidden("参数不全")

        # 2.2 格式校验
        if not re.match(r'^[a-z0-9][\w\.\-]*@[a-z0-9\-]+(\.[a-z]{2,5}){1,2}$', email):
            return http.HttpResponseForbidden("邮件格式有误")

        # 3,发送邮件
        verify_url = generate_verify_url(request.user)
        # send_mail(subject='美多商城邮箱激活',
        #           message='xx',
        #           from_email=settings.EMAIL_FROM,
        #           recipient_list=[email])
        send_verify_url.delay(verify_url, email)  # celery发送邮件

        # 4,数据入库
        request.user.email = email
        request.user.save()

        # 5,返回响应
        return http.JsonResponse({"code": RET.OK, "errmsg": "ok"})
Exemplo n.º 2
0
    def put(self, request):
        #1,获取参数
        dict_data = json.loads(request.body.decode())
        email = dict_data.get("email")

        #2,校验参数,为空校验
        if not email:
            return http.HttpResponseForbidden("邮箱不能为空")

        #3,数据入库(发送,入库)
        #3,1 获取验证链接
        verify_url = generate_verify_url(request.user)

        #3,2发送邮件
        # send_mail(subject='美多商城,激活链接',
        #           message=verify_url,
        #           from_email=settings.EMAIL_FROM,
        #           recipient_list=[email])

        from celery_tasks.email.tasks import send_verify_url
        send_verify_url.delay(verify_url, email)

        #3,3入库
        request.user.email = email
        request.user.save()

        #4,返回响应
        return http.JsonResponse({"code": RET.OK})
Exemplo n.º 3
0
    def put(self, request):  #参考 user_center_info.js
        # 1,获取邮箱
        dict_data = json.loads(request.body.decode())
        email = dict_data.get("email")
        # 2,校验参数
        # 2.1 为空校验
        if not email:
            return http.HttpResponseForbidden("参数不全")
        # 2.2 格式校验
        if not re.match(r'^[a-z0-9][\w\.\-]*@[a-z0-9\-]+(\.[a-z]{2,5}){1,2}$',
                        email):
            return http.HttpResponseForbidden("邮件格式有误")
        # 3,发送邮件    [email protected]
        # test send emil
        # send_mail(subject='你好',
        #           message='树林',
        #           from_email=settings.EMAIL_FROM,
        #           recipient_list=[email])

        # 3,发送邮件
        from meiduo_mall.utils.email import generate_verify_url
        from celery_tasks.email.tasks import sendEmail
        #调用加密
        verify_url = generate_verify_url(request.user)
        print(verify_url)
        # #调用celery队列发送
        sendEmail.delay(verify_url, email)  # celery发送邮件

        #普通发送
        # send_mail(subject='美多商城邮箱激活',
        #           message=verify_url,
        #           from_email=settings.EMAIL_FROM,
        #           recipient_list=[email])
        print('already send email')

        # 4,数据入库
        request.user.email = email
        request.user.save()

        # 5,返回响应
        return http.JsonResponse({"code": 0, "errmsg": "ok"})