微信绑定限制
This commit is contained in:
parent
c79e09d7cf
commit
e540b15b73
|
|
@ -0,0 +1,19 @@
|
|||
# Generated by Django 3.0.5 on 2021-04-30 03:56
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('system', '0017_userthird'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='userthird',
|
||||
name='openid',
|
||||
field=models.CharField(default='xx', max_length=200, unique=True, verbose_name='第三方账号'),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
||||
|
|
@ -229,4 +229,4 @@ class UserThird(models.Model):
|
|||
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='关联账户', related_name='third_user')
|
||||
type = models.CharField('类型', max_length=50, choices=type_choices, default='wx_mp')
|
||||
openid = models.CharField('第三方账号', null=True, blank=True, max_length=200)
|
||||
openid = models.CharField('第三方账号', max_length=200, unique=True)
|
||||
|
|
|
|||
|
|
@ -343,6 +343,11 @@ class UserViewSet(PageOrNot, ModelViewSet):
|
|||
code+'&grant_type=authorization_code').content.decode('utf-8')
|
||||
info = json.loads(info)
|
||||
openid = info['openid']
|
||||
if UserThird.objects.filter(openid=openid).exists():
|
||||
instance = UserThird.objects.get(openid=openid)
|
||||
instance.openid = openid
|
||||
instance.save()
|
||||
else:
|
||||
UserThird.objects.get_or_create(openid=openid, type='wx_mp', user=request.user, defaults={'openid':openid, 'user':request.user, 'type':'wx_mp'})
|
||||
return Response({'wxmp_openid':openid},status=status.HTTP_200_OK)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue