From 132432c7d55d2ef79faa10123ad672e6507a5a3f Mon Sep 17 00:00:00 2001 From: chenyang Date: Fri, 1 Jul 2022 07:30:07 +0800 Subject: [PATCH] update --- server/views/user.py | 7 +++++-- server_auth/lib/auth.py | 4 +--- static/html/dashboard.html | 17 ++++++++++------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/server/views/user.py b/server/views/user.py index e9604b5..c93c4f0 100644 --- a/server/views/user.py +++ b/server/views/user.py @@ -1,5 +1,7 @@ +from django.http.response import JsonResponse from rest_framework.views import APIView -from django.http import HttpResponse + +from server_auth.models import MindUser class MindUserView(APIView): @@ -12,4 +14,5 @@ class MindUserView(APIView): user_name = data_dict.get('userName') input_password = data_dict.get('inputPassword') print('userName:%s,inputPassword:%s' % (user_name, input_password)) - return HttpResponse("success") + MindUser.objects.create_user(username=user_name, password=input_password, email='') + return JsonResponse({"code": 0, "msg": "success"}) diff --git a/server_auth/lib/auth.py b/server_auth/lib/auth.py index 25ff9e3..880928d 100644 --- a/server_auth/lib/auth.py +++ b/server_auth/lib/auth.py @@ -3,6 +3,7 @@ from server_auth.models import MindUser from django.contrib.auth import authenticate, login, logout + class AuthBackend(ModelBackend): """ login 方法会调用该方法 @@ -14,12 +15,9 @@ class AuthBackend(ModelBackend): if user is not None and user.check_password(password): return user - # 登录方式有多种 # 1、用户名密码登录:直接匹配数据库的用户名密码 -def login(): - pass # 2、微信扫码登录:1、生成带标记的二维码 2、用户扫码 3、微信通知服务器端 4、服务器校验是否有注册,如果没有注册则新增用户 5、服务器通知前端界面 diff --git a/static/html/dashboard.html b/static/html/dashboard.html index 80177da..a8c88ab 100644 --- a/static/html/dashboard.html +++ b/static/html/dashboard.html @@ -24,16 +24,16 @@ $(function () { // 监听modal窗口事件 $('#exampleModal').on('show.bs.modal', function (event) { - console.log(qr_websocket) - console.log('打开'); + // console.log(qr_websocket) + // console.log('打开'); const ws = new WebSocket(`ws://${window.location.host}/ws/qr/?${qr_websocket.uuid}`) ws.onmessage = function (e) { - console.log(e.data) + console.log('接收到websocket消息:' + e.data) } qr_websocket.websocket = ws }); $('#exampleModal').on('hidden.bs.modal', function (event) { - console.log('关闭'); + // console.log('关闭'); qr_websocket.websocket.close() }); @@ -89,7 +89,10 @@ data: {userName: userName, inputPassword: inputPassword}, dataType: "json", success: function (data) { - console.log(data) + // 注册成功 + if (data.code === 0) { + + } }, async: false }); @@ -150,7 +153,7 @@