Example #1
0
 def update(self, instance, validated_data):
     print(validated_data)
     email = validated_data['email']
     instance.email = email
     instance.save()
     #生成验证链接
     verify_url = instance.generate_verify_email_url()
     #发送验证邮件
     send_email.delay(email, verify_url)
     return instance
Example #2
0
 def update(self, instance, validated_data):
     user = self.context['request'].user
     # 加密用户信息
     tjs = TJS(settings.SECRET_KEY, 300)
     token = tjs.dumps({'username': instance.username}).decode()
     to_email = validated_data['email']  # 发送给谁
     verify_url = 'http://www.meiduo.site:8080/success_verify_email.html?token=' + token  # 验证连接
     # 发送邮件
     send_email.delay(to_email, verify_url)
     instance.email = validated_data['email']
     instance.save()
     return instance
Example #3
0
    def update(self, instance, validated_data):
        # 收件人
        to_email = validated_data['email']

        tjs = TJS(settings.SECRET_KEY, 300)

        token = tjs.dumps({'username': instance.username}).decode()

        send_email.delay(token, to_email)

        instance.email = validated_data['email']
        instance.save()
        return instance
Example #4
0
    def update(self, instance, validated_data):
        if not instance.id:
            print(instance)
            raise serializers.ValidationError('验证失败')
        target_email = validated_data.get('email')
        token_package = instance.generate_email_token()

        send_email.delay(token_package, target_email)

        instance.email = target_email
        instance.save()

        return validated_data
Example #5
0
 def update(self, instance, validated_data):
     # 更新邮箱
     instance.email = validated_data['email']
     instance.save()
     #加密用户信息
     tjs = TJS(settings.SECRET_KEY, 300)
     token = tjs.dumps({
         'user_id': instance.id,
         'email': validated_data['email']
     }).decode()
     to_email = validated_data['email']
     #异步发送邮件
     send_email.delay(validated_data['email'], token)
     return instance
Example #6
0
    def update(self, instance, validated_data):
        """

        :param instance: user对象
        :param validated_data:  被校验的数据
        :return:
        """
        email = validated_data['email']
        instance.email = email
        instance.save()
        # 发送邮件
        url = instance.get_email_url()
        send_email.delay(email, url)

        return instance
Example #7
0
def SendEmail(request):
    if request.method == 'PUT':
        json_dict = json.loads(request.body.decode())
        email = json_dict.get('email')
        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': '邮箱格式错误'})
        user = request.user
        if user.email != email:
            user.email = email
            user.save()
        token = token_confirm.generate_validate_token(user.id)
        verify_url = EMAIL_VERIFY_URL + '?token=' + token
        # 使用celery异步发送邮件
        send_email.delay(email, verify_url)
        return JsonResponse({'code': RETCODE.OK, 'errmsg': '添加邮箱成功'})
    return redirect('user:info')
Example #8
0
    def put(self, request):
        data = json.loads(request.body)
        to_email = data.get('email')
        if not to_email:
            return JsonResponse({'code': 400, 'errmsg': '缺少email参数'})
        if not re.match(r'^[a-z0-9][\w\.\-]*@[a-z0-9\-]+(\.[a-z]{2,5}){1,2}$',
                        to_email):
            return JsonResponse({'code': 400, 'errmsg': '参数email有误'})
        try:
            request.user.email = to_email
            request.user.save()
        except Exception as e:
            return JsonResponse({'code': 400, 'errmsg': '数据写入失败'})
        token = request.user.generate_token()
        verify_url = settings.EMAIL_VERIFY_URL + token
        send_email.delay(to_email, verify_url)

        return JsonResponse({'code': 200, 'errmsg': 'ok'})
Example #9
0
    def update(self, instance, validated_data):

        instance.email = validated_data["email"]
        instance.save()

        # 加密用户数据
        data = {"name": instance.username}
        tjs = TJS(settings.SECRET_KEY, 300)
        token = tjs.dumps(data).decode()
        # verify_url = "http://www.meiduo.site:8080/success_verify_email.html?token="+token
        # subject="美多商城验证邮箱"
        # html_message='<p>尊敬的用户您好!</p>' \
        #                '<p>感谢您使用美多商城。</p>' \
        #              '<p>您的邮箱为:%s 。请点击此链接激活您的邮箱:</p>' \
        #              '<p><a href="%s">%s<a></p>' % (validated_data['email'], verify_url, verify_url)

        # send_mail(subject,'',settings.EMAIL_FROM,[validated_data["email"]],html_message=html_message)
        # 发送短信
        send_email.delay(token, validated_data["email"])
        return instance