Exemplo n.º 1
0
    def update(self, instance, validated_data):
        instance.email = validated_data.get('email')
        instance.save()

        verify_url = instance.generate_verify_url()
        send_verify_email.delay(instance.email, verify_url)

        return instance
Exemplo n.º 2
0
 def update(self, instance, validated_data):
     email = validated_data['email']
     instance.email = email
     instance.save()
     # 生成激活链接
     verify_url = instance.generate_email_verify_url()
     # 发送邮件
     send_verify_email.delay(email, verify_url)
     return instance
Exemplo n.º 3
0
    def update(self, instance, validated_data):
        email = validated_data['email']
        instance.email = email
        instance.save()

        # 生成邮件验证地址
        verify_url = instance.generate_email_verify_url()
        # 利用celery发送验证邮件
        send_verify_email.delay(email, verify_url)

        return instance
Exemplo n.º 4
0
    def update(self, instance: User, validated_data):
        # 序列化器只帮助保存邮箱,并不会为我们发送邮件,需要重写
        email = validated_data['email']
        instance.email = email
        instance.save()

        # 生成激活链接
        verify_url = instance.generate_email_verify_url()

        # 发送验证邮件
        send_verify_email.delay(email, verify_url)

        return instance
Exemplo n.º 5
0
    def update(self, instance, validated_data):
        # 为什么是 update 方法,而不是 create?
        """重新更新方法,添加发送邮件
        instance  == user
        """
        email = validated_data['email']
        instance.email = email
        instance.save()

        # 生成激活链接
        verify_url = instance.generate_email_verify_url()
        # 发送验证邮件,Celery 异步任务
        send_verify_email.delay(email, verify_url)
        return instance
Exemplo n.º 6
0
    def update(self, instance, validated_data):
        """
        重写更新方法,添加发送邮件
        :param instance: user
        :param validated_data:经过验证的数据
        :return: instance
        """
        email = validated_data['email']
        instance.email = email
        instance.save()

        # 生成激活链接
        verify_url = instance.generate_email_verify_url()
        # 发送验证邮件
        send_verify_email.delay(email, verify_url)

        return instance
Exemplo n.º 7
0
    def put(self, request):
        # 接收请求
        json_dict = json.loads(request.body.decode())
        email = json_dict.get("email")
        # 校验
        if not email:
            return JsonResponse({"code": RETCODE.EMAILERR, "errmsg": "缺少邮箱参数"})
        if not re.match(r"^[a-z0-9][\w\.\-]*@[a-z0-9\-]+(\.[a-z]{2,5}){1,2}$", email):
            return JsonResponse({"code": RETCODE.EMAILERR, "errmsg": "邮箱格式错误"})
        # 处理
        # 修改email的字段
        user = request.user

        User.objects.filter(username=user.username, email="").update(email=email)
        # 响应
        # 发激活邮件 celery
        # send_verify_email.delay(email, "www.baidu.com")
        # 加密邮件
        verify_url = email_active_url(user)
        send_verify_email.delay(email, verify_url)

        return JsonResponse({"code": RETCODE.OK, "errmsg": "设置邮箱成功"})