From 0e7678d3d143bc49da160bf4827222848f53c594 Mon Sep 17 00:00:00 2001 From: Angelo Date: Wed, 11 May 2022 13:45:39 +0800 Subject: [PATCH] fix(dictionary): dictionary data init & user password reset --- backend/dvadmin/system/init_data.py | 73 ++++++--- backend/dvadmin/system/initialize.py | 4 +- backend/dvadmin/system/urls.py | 9 +- backend/dvadmin/system/views/user.py | 20 +-- web/src/views/system/login/base.vue | 214 +++++++++++++-------------- web/src/views/system/login/page.vue | 56 ++++--- web/src/views/system/user/api.js | 8 + web/src/views/system/user/crud.js | 17 ++- web/src/views/system/user/index.vue | 11 +- 9 files changed, 231 insertions(+), 181 deletions(-) diff --git a/backend/dvadmin/system/init_data.py b/backend/dvadmin/system/init_data.py index 5a41f94..4f3edb5 100644 --- a/backend/dvadmin/system/init_data.py +++ b/backend/dvadmin/system/init_data.py @@ -148,10 +148,21 @@ button_data = [ "dept_belong_id": 1, "update_datetime": datetime.datetime.now(), "create_datetime": datetime.datetime.now(), - "name": "重置密码", + "name": "重设密码", "value": "ResetPassword", "creator_id": 1, }, + { + "id": 10, + "description": None, + "modifier": "1", + "dept_belong_id": 1, + "update_datetime": datetime.datetime.now(), + "create_datetime": datetime.datetime.now(), + "name": "重置密码", + "value": "DefaultPassword", + "creator_id": 1, + }, ] menu_data = [ @@ -1250,7 +1261,7 @@ menu_button_data = [ "dept_belong_id": 1, "update_datetime": datetime.datetime.now(), "create_datetime": datetime.datetime.now(), - "name": "重置密码", + "name": "重设密码", "value": "ResetPassword", "api": "/api/system/user/reset_password/{id}/", "method": 2, @@ -1261,6 +1272,20 @@ menu_button_data = [ "id": 54, "description": None, "modifier": "1", + "dept_belong_id": 1, + "update_datetime": datetime.datetime.now(), + "create_datetime": datetime.datetime.now(), + "name": "重置密码", + "value": "DefaultPassword", + "api": "/api/system/user/reset_to_default_password/{id}/", + "method": 2, + "creator_id": 1, + "menu_id": 3, + }, + { + "id": 55, + "description": None, + "modifier": "1", "dept_belong_id": "1", "update_datetime": datetime.datetime.now(), "create_datetime": datetime.datetime.now(), @@ -1272,7 +1297,7 @@ menu_button_data = [ "menu_id": 20, }, { - "id": 55, + "id": 56, "description": None, "modifier": "1", "dept_belong_id": "1", @@ -1286,7 +1311,7 @@ menu_button_data = [ "menu_id": 20, }, { - "id": 56, + "id": 57, "description": None, "modifier": "1", "dept_belong_id": 1, @@ -1388,7 +1413,7 @@ dictionary_data = [ "creator_id": 1, "parent_id": None, "is_value": 0, - "type": 0 + "type": 0, }, { "id": 2, @@ -1405,7 +1430,7 @@ dictionary_data = [ "creator_id": 1, "parent_id": 1, "is_value": 1, - "type": 6 + "type": 6, }, { "id": 5, @@ -1422,7 +1447,7 @@ dictionary_data = [ "creator_id": 1, "parent_id": None, "is_value": 0, - "type": 0 + "type": 0, }, { "id": 6, @@ -1439,7 +1464,7 @@ dictionary_data = [ "creator_id": 1, "parent_id": 1, "is_value": 1, - "type": 6 + "type": 6, }, { "id": 7, @@ -1456,7 +1481,7 @@ dictionary_data = [ "creator_id": 1, "parent_id": None, "is_value": 0, - "type": 0 + "type": 0, }, { "id": 8, @@ -1473,7 +1498,7 @@ dictionary_data = [ "creator_id": 1, "parent_id": 7, "is_value": 1, - "type": 1 + "type": 1, }, { "id": 9, @@ -1490,7 +1515,7 @@ dictionary_data = [ "creator_id": 1, "parent_id": 7, "is_value": 1, - "type": 1 + "type": 1, }, { "id": 10, @@ -1507,7 +1532,7 @@ dictionary_data = [ "creator_id": 1, "parent_id": None, "is_value": 0, - "type": 0 + "type": 0, }, { "id": 11, @@ -1524,7 +1549,7 @@ dictionary_data = [ "creator_id": 1, "parent_id": 5, "is_value": 1, - "type": 6 + "type": 6, }, { "id": 12, @@ -1541,7 +1566,7 @@ dictionary_data = [ "creator_id": 1, "parent_id": 5, "is_value": 1, - "type": 6 + "type": 6, }, { "id": 13, @@ -1558,7 +1583,7 @@ dictionary_data = [ "creator_id": 1, "parent_id": 10, "is_value": 1, - "type": 1 + "type": 1, }, { "id": 14, @@ -1575,7 +1600,7 @@ dictionary_data = [ "creator_id": 1, "parent_id": 10, "is_value": 1, - "type": 1 + "type": 1, }, { "id": 15, @@ -1592,7 +1617,7 @@ dictionary_data = [ "creator_id": 1, "parent_id": None, "is_value": 0, - "type": 0 + "type": 0, }, { "id": 16, @@ -1609,7 +1634,7 @@ dictionary_data = [ "creator_id": 1, "parent_id": 15, "is_value": 1, - "type": 1 + "type": 1, }, { "id": 17, @@ -1626,7 +1651,7 @@ dictionary_data = [ "creator_id": 1, "parent_id": 15, "is_value": 1, - "type": 1 + "type": 1, }, { "id": 18, @@ -1643,7 +1668,7 @@ dictionary_data = [ "creator_id": 1, "parent_id": None, "is_value": 0, - "type": 0 + "type": 0, }, { "id": 19, @@ -1660,7 +1685,7 @@ dictionary_data = [ "creator_id": 1, "parent_id": 18, "is_value": 1, - "type": 1 + "type": 1, }, { "id": 20, @@ -1677,7 +1702,7 @@ dictionary_data = [ "creator_id": 1, "parent_id": 18, "is_value": 1, - "type": 1 + "type": 1, }, { "id": 21, @@ -1694,6 +1719,6 @@ dictionary_data = [ "creator_id": 1, "parent_id": 18, "is_value": 1, - "type": 1 - } + "type": 1, + }, ] diff --git a/backend/dvadmin/system/initialize.py b/backend/dvadmin/system/initialize.py index 789b7f4..46326da 100644 --- a/backend/dvadmin/system/initialize.py +++ b/backend/dvadmin/system/initialize.py @@ -15,6 +15,7 @@ from dvadmin.system.models import ( MenuButton, Role, Users, + Dictionary, ) from .init_data import ( @@ -78,7 +79,7 @@ class Initialize(CoreInitialize): 初始化字典表 """ data = dictionary_data - self.save(Users, data, "字典表", no_reset=False) + self.save(Dictionary, data, "字典表", no_reset=False) def run(self): self.init_dept() @@ -87,6 +88,7 @@ class Initialize(CoreInitialize): self.init_menu_button() self.init_role() self.init_users() + self.init_dictionary() # 项目init 初始化,默认会执行 main 方法进行初始化 diff --git a/backend/dvadmin/system/urls.py b/backend/dvadmin/system/urls.py index 5ed359d..5f80a9b 100644 --- a/backend/dvadmin/system/urls.py +++ b/backend/dvadmin/system/urls.py @@ -1,11 +1,3 @@ -# -*- coding: utf-8 -*- - -""" -@author: 猿小天 -@contact: QQ:1638245306 -@Created on: 2021/6/1 001 23:05 -@Remark: 系统管理的路由文件 -""" from django.urls import path from rest_framework import routers @@ -42,6 +34,7 @@ urlpatterns = [ path('menu/web_router/', MenuViewSet.as_view({'get': 'web_router'})), path('user/user_info/', UserViewSet.as_view({'get': 'user_info', 'put': 'update_user_info'})), path('user/change_password//', UserViewSet.as_view({'put': 'change_password'})), + path('user/reset_to_default_password//', UserViewSet.as_view({'put': 'reset_to_default_password'})), path('user/reset_password//', UserViewSet.as_view({'put': 'reset_password'})), path('user/export/', UserViewSet.as_view({'post': 'export_data', })), path('user/import/', UserViewSet.as_view({'get': 'import_data', 'post': 'import_data'})), diff --git a/backend/dvadmin/system/views/user.py b/backend/dvadmin/system/views/user.py index d947d7f..e8bcd37 100644 --- a/backend/dvadmin/system/views/user.py +++ b/backend/dvadmin/system/views/user.py @@ -241,16 +241,16 @@ class UserViewSet(CustomModelViewSet): else: return ErrorResponse(msg="未获取到用户") - # @action(methods=["PUT"], detail=True, permission_classes=[IsAuthenticated]) - # def reset_password(self, request, *args, **kwargs): - # """重置密码""" - # instance = Users.objects.filter(id=kwargs.get("pk")).first() - # if instance: - # instance.set_password(settings.DEFAULT_PASSWORD) - # instance.save() - # return DetailResponse(data=None, msg="密码重置成功") - # else: - # return ErrorResponse(msg="未获取到用户") + @action(methods=["PUT"], detail=True, permission_classes=[IsAuthenticated]) + def reset_to_default_password(self, request, *args, **kwargs): + """恢复默认密码""" + instance = Users.objects.filter(id=kwargs.get("pk")).first() + if instance: + instance.set_password(settings.DEFAULT_PASSWORD) + instance.save() + return DetailResponse(data=None, msg="密码重置成功") + else: + return ErrorResponse(msg="未获取到用户") @action(methods=["PUT"], detail=True) def reset_password(self, request, pk): diff --git a/web/src/views/system/login/base.vue b/web/src/views/system/login/base.vue index 70df33d..8f11655 100644 --- a/web/src/views/system/login/base.vue +++ b/web/src/views/system/login/base.vue @@ -1,7 +1,5 @@ diff --git a/web/src/views/system/login/page.vue b/web/src/views/system/login/page.vue index 5789b14..f683eb6 100644 --- a/web/src/views/system/login/page.vue +++ b/web/src/views/system/login/page.vue @@ -1,18 +1,28 @@