From 9599ff5366fe76a74223d997bb72767e44853ba7 Mon Sep 17 00:00:00 2001 From: HuYang Date: Mon, 28 Dec 2020 18:27:27 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9API=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E6=96=B9=E5=BC=8F=E3=80=81=E5=9B=BE=E6=A0=87?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E5=90=8E=E5=85=B3=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app_api/views.py | 20 ++++++++------ template/app_api/api404.html | 26 +++++++++++++++++++ .../manage/manage_project_options.html | 1 + template/app_doc/pro_list.html | 1 + 4 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 template/app_api/api404.html diff --git a/app_api/views.py b/app_api/views.py index e18b580..67f0736 100644 --- a/app_api/views.py +++ b/app_api/views.py @@ -38,19 +38,19 @@ def oauth0(request): # 1 、验证timestamp的时效性 nowtime = int (time.time()) # 时间戳失效时间,默认为3600,可以改短,如30,严格点5秒,如果使用5秒,请求前,需要通过get_timestamp获取服务器时间戳,否则因为和服务器时间差导致无法验证通过 - if (nowtime - int(timestamp)) > 3600 : - return JsonResponse({'status':False,'data':nowtime,'errormsg':"out of time"}) + if (nowtime - int(timestamp)) > 3600 : + raise ValueError('链接已失效,请从合法路径访问,或联系管理员!') # 2、获取userid的Token user = User.objects.get(username=username) if user is None: - return JsonResponse({'status':False,'data':nowtime,'errormsg':'user error!'}) + raise ValueError('请求用户出错!') ID = user.id State = user.is_active if State == 1 and ID is not None: usertoken = UserToken.objects.get(user_id=ID) token = usertoken.token else: - return JsonResponse({'status':False,'data':nowtime,'errormsg':'user deny!'}) + raise ValueError('非法用户!') # 3、 验证hash的正确性 final_str = str(randstr) + str(timestamp) + str(username) + token @@ -61,12 +61,16 @@ def oauth0(request): from urllib.parse import unquote newurl = unquote(redirecturl) return redirect(newurl) - else: - return JsonResponse({'status':False,'data':nowtime,'errmsg':'hash error!'}) + else: + raise ValueError('验证失败,可能是用户名或Token不正确!详情请联系管理员!') else: - return JsonResponse({'status':False,'data':'Some keywords is empty!'}) + raise ValueError('关键字验证失败,请联系管理员!部分关键字为空') + except ValueError as e: + errormsg = e + return render(request, 'app_api/api404.html', locals()) except : - return JsonResponse({'status':False,'data':'Something wrong here!!'}) + errormsg = "API接口运行出错!" + return render(request, 'app_api/api404.html', locals()) else: return JsonResponse({'status':False,'data':'Nothing Here'}) diff --git a/template/app_api/api404.html b/template/app_api/api404.html new file mode 100644 index 0000000..6848696 --- /dev/null +++ b/template/app_api/api404.html @@ -0,0 +1,26 @@ +{% load static %} +{% load i18n %} + + + + + {% trans "页面未找到" %} - {% if site_name != None %}{{site_name}} {% else %}{% trans "觅道文档MrDoc" %}{% endif %} + + + + + + +{% include 'app_doc/head_base.html' %} + +
+
+


{{errormsg }}




+

{% trans "返回首页" %}

+
+
+ + + + + \ No newline at end of file diff --git a/template/app_doc/manage/manage_project_options.html b/template/app_doc/manage/manage_project_options.html index 489404e..17e80eb 100644 --- a/template/app_doc/manage/manage_project_options.html +++ b/template/app_doc/manage/manage_project_options.html @@ -247,6 +247,7 @@ console.log(selected_icon) $("#project-icon-select").html(selected_icon_svg) $("#picon").val(selected_icon) + $("#project-icon-select-box").toggleClass("hide-project-icon-list") }) //修改文集基础信息 modifyProject = function(pro_id,pro_name,pro_intro){ diff --git a/template/app_doc/pro_list.html b/template/app_doc/pro_list.html index ea48564..dc01a28 100644 --- a/template/app_doc/pro_list.html +++ b/template/app_doc/pro_list.html @@ -301,6 +301,7 @@ console.log(selected_icon) $("#project-icon-select").html(selected_icon_svg) $("#picon").val(selected_icon) + $("#project-icon-select-box").toggleClass("hide-project-icon-list") }) From 3d728518e4d22df6889403651d8394c02d900e90 Mon Sep 17 00:00:00 2001 From: HuYang Date: Wed, 30 Dec 2020 10:56:32 +0800 Subject: [PATCH 2/3] =?UTF-8?q?Revert=20"=E4=BF=AE=E6=94=B9API=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=8A=A5=E9=94=99=E6=96=B9=E5=BC=8F=E3=80=81=E5=9B=BE?= =?UTF-8?q?=E6=A0=87=E9=80=89=E6=8B=A9=E5=90=8E=E5=85=B3=E9=97=AD"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 9599ff5366fe76a74223d997bb72767e44853ba7. --- app_api/views.py | 20 ++++++-------- template/app_api/api404.html | 26 ------------------- .../manage/manage_project_options.html | 1 - template/app_doc/pro_list.html | 1 - 4 files changed, 8 insertions(+), 40 deletions(-) delete mode 100644 template/app_api/api404.html diff --git a/app_api/views.py b/app_api/views.py index 67f0736..e18b580 100644 --- a/app_api/views.py +++ b/app_api/views.py @@ -38,19 +38,19 @@ def oauth0(request): # 1 、验证timestamp的时效性 nowtime = int (time.time()) # 时间戳失效时间,默认为3600,可以改短,如30,严格点5秒,如果使用5秒,请求前,需要通过get_timestamp获取服务器时间戳,否则因为和服务器时间差导致无法验证通过 - if (nowtime - int(timestamp)) > 3600 : - raise ValueError('链接已失效,请从合法路径访问,或联系管理员!') + if (nowtime - int(timestamp)) > 3600 : + return JsonResponse({'status':False,'data':nowtime,'errormsg':"out of time"}) # 2、获取userid的Token user = User.objects.get(username=username) if user is None: - raise ValueError('请求用户出错!') + return JsonResponse({'status':False,'data':nowtime,'errormsg':'user error!'}) ID = user.id State = user.is_active if State == 1 and ID is not None: usertoken = UserToken.objects.get(user_id=ID) token = usertoken.token else: - raise ValueError('非法用户!') + return JsonResponse({'status':False,'data':nowtime,'errormsg':'user deny!'}) # 3、 验证hash的正确性 final_str = str(randstr) + str(timestamp) + str(username) + token @@ -61,16 +61,12 @@ def oauth0(request): from urllib.parse import unquote newurl = unquote(redirecturl) return redirect(newurl) - else: - raise ValueError('验证失败,可能是用户名或Token不正确!详情请联系管理员!') + else: + return JsonResponse({'status':False,'data':nowtime,'errmsg':'hash error!'}) else: - raise ValueError('关键字验证失败,请联系管理员!部分关键字为空') - except ValueError as e: - errormsg = e - return render(request, 'app_api/api404.html', locals()) + return JsonResponse({'status':False,'data':'Some keywords is empty!'}) except : - errormsg = "API接口运行出错!" - return render(request, 'app_api/api404.html', locals()) + return JsonResponse({'status':False,'data':'Something wrong here!!'}) else: return JsonResponse({'status':False,'data':'Nothing Here'}) diff --git a/template/app_api/api404.html b/template/app_api/api404.html deleted file mode 100644 index 6848696..0000000 --- a/template/app_api/api404.html +++ /dev/null @@ -1,26 +0,0 @@ -{% load static %} -{% load i18n %} - - - - - {% trans "页面未找到" %} - {% if site_name != None %}{{site_name}} {% else %}{% trans "觅道文档MrDoc" %}{% endif %} - - - - - - -{% include 'app_doc/head_base.html' %} - -
-
-


{{errormsg }}




-

{% trans "返回首页" %}

-
-
- - - - - \ No newline at end of file diff --git a/template/app_doc/manage/manage_project_options.html b/template/app_doc/manage/manage_project_options.html index 17e80eb..489404e 100644 --- a/template/app_doc/manage/manage_project_options.html +++ b/template/app_doc/manage/manage_project_options.html @@ -247,7 +247,6 @@ console.log(selected_icon) $("#project-icon-select").html(selected_icon_svg) $("#picon").val(selected_icon) - $("#project-icon-select-box").toggleClass("hide-project-icon-list") }) //修改文集基础信息 modifyProject = function(pro_id,pro_name,pro_intro){ diff --git a/template/app_doc/pro_list.html b/template/app_doc/pro_list.html index dc01a28..ea48564 100644 --- a/template/app_doc/pro_list.html +++ b/template/app_doc/pro_list.html @@ -301,7 +301,6 @@ console.log(selected_icon) $("#project-icon-select").html(selected_icon_svg) $("#picon").val(selected_icon) - $("#project-icon-select-box").toggleClass("hide-project-icon-list") }) From 8230b3879a04368275fc3f260f04040bef4666ed Mon Sep 17 00:00:00 2001 From: HuYang Date: Wed, 30 Dec 2020 11:12:24 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E8=B0=83=E6=95=B4API=E8=B7=B3=E8=BD=AC?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E7=9A=84=E9=94=99=E8=AF=AF=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=E5=B9=B6=E6=B7=BB=E5=8A=A0=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app_api/views.py | 23 ++++++++++++++--------- template/app_api/api404.html | 28 ++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 template/app_api/api404.html diff --git a/app_api/views.py b/app_api/views.py index e18b580..3cb8098 100644 --- a/app_api/views.py +++ b/app_api/views.py @@ -17,6 +17,7 @@ from django.shortcuts import render,redirect # MrDoc 基于用户的Token访问API模块 # 用户通过该url获取服务器时间戳,便于接口访问 +# url范例:http://127.0.0.1:8000/api/get_timestamp/ def get_timestamp(request): now_time = str(int(time.time())) return JsonResponse({'status':True,'data':now_time}) @@ -38,19 +39,19 @@ def oauth0(request): # 1 、验证timestamp的时效性 nowtime = int (time.time()) # 时间戳失效时间,默认为3600,可以改短,如30,严格点5秒,如果使用5秒,请求前,需要通过get_timestamp获取服务器时间戳,否则因为和服务器时间差导致无法验证通过 - if (nowtime - int(timestamp)) > 3600 : - return JsonResponse({'status':False,'data':nowtime,'errormsg':"out of time"}) + if (nowtime - int(timestamp)) > 3600 : + raise ValueError('链接已失效,请从合法路径访问,或联系管理员!') # 2、获取userid的Token user = User.objects.get(username=username) if user is None: - return JsonResponse({'status':False,'data':nowtime,'errormsg':'user error!'}) + raise ValueError('请求用户出错!') ID = user.id State = user.is_active if State == 1 and ID is not None: usertoken = UserToken.objects.get(user_id=ID) token = usertoken.token else: - return JsonResponse({'status':False,'data':nowtime,'errormsg':'user deny!'}) + raise ValueError('非法用户!') # 3、 验证hash的正确性 final_str = str(randstr) + str(timestamp) + str(username) + token @@ -61,14 +62,18 @@ def oauth0(request): from urllib.parse import unquote newurl = unquote(redirecturl) return redirect(newurl) - else: - return JsonResponse({'status':False,'data':nowtime,'errmsg':'hash error!'}) + else: + raise ValueError('验证失败,可能是用户名或Token不正确!详情请联系管理员!') else: - return JsonResponse({'status':False,'data':'Some keywords is empty!'}) + raise ValueError('关键字验证失败,请联系管理员!部分关键字为空') + except ValueError as e: + errormsg = e + return render(request, 'app_api/api404.html', locals()) except : - return JsonResponse({'status':False,'data':'Something wrong here!!'}) + errormsg = "API接口运行出错!" + return render(request, 'app_api/api404.html', locals()) else: - return JsonResponse({'status':False,'data':'Nothing Here'}) + return JsonResponse({'status':False,'data':'Nothing Here'}) diff --git a/template/app_api/api404.html b/template/app_api/api404.html new file mode 100644 index 0000000..4d25e52 --- /dev/null +++ b/template/app_api/api404.html @@ -0,0 +1,28 @@ +{% load static %} +{% load i18n %} + + + + + {% trans "页面未找到" %} - {% if site_name != None %}{{site_name}} {% else %}{% trans "觅道文档MrDoc" %}{% endif %} + + + + + + +{% include 'app_doc/head_base.html' %} + +
+
+


+ {{ errormsg }} +





+

{% trans "返回首页" %}

+
+
+ + + + + \ No newline at end of file