标签: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})
标签:sse mis ret 成功 bin oauth open color use
原文地址:https://www.cnblogs.com/xiaoxiamiaichiyu/p/13797797.html