码迷,mamicode.com
首页 > 其他好文 > 详细

绑定微博用户接口

时间:2020-10-13 16:49:14      阅读:20      评论:0      收藏:0      [点我收藏+]

标签:sse   mis   ret   成功   bin   oauth   open   color   use   

1.微博绑定用户接口

1.1 oauth/urls.py中添加路由

urlpatterns=[
    

    path(weibo/binduser/, views.OauthWeiboBindUser.as_view()), # /oauth/weibo/callback/ 
]

 

1.2 oauth/views.py中添加试图函数

技术图片
class OauthWeiboBindUser(APIView):
    permission_classes = (AllowAny,)

    def post(self,request):
        username=request.data.get(username)
        password=request.data.get(password)
        weibo_uid=request.data.get(weibo_uid)
        if not all([username,password,weibo_uid]):
            return Response({code:999,msg:参数不全})
        try:
            user=User.objects.get(username=username)
        except Exception as e:
            user=None

        if user:
            if user.check_password(password):
                ou=OauthUser(uid=weibo_uid,user=user,oauth_type=1)

                ou.save()
                payload=jwt_payload_handler(user)
                token=jwt_encode_handler(payload)
                data=jwt_response_payload_handler(token,user)
                data[type]=0
                return Response({code:0,msg:登录成功,data:data})
            else:
                return Response({code:999,msg:密码错误})
        else:
            user=User(username=username)
            user.set_password(password)
            user.save()
            ou=OauthUser(uid=weibo_uid,user=user,oauth_type=1)
            ou.save()
            payload=jwt_payload_handler(user)
            token=jwt_encode_handler(payload)
            data=jwt_response_payload_handler(token,user)

            data[type]=0
            return Response({code:0,msg:登录成功,data:data})
oauth/views.py

 

绑定微博用户接口

标签:sse   mis   ret   成功   bin   oauth   open   color   use   

原文地址:https://www.cnblogs.com/xiaoxiamiaichiyu/p/13797797.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!