From 54dcfbf0fa3c0fdf2d4e003223bfe3e404671dca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=BC=BA?= <1206709430@qq.com> Date: Sat, 14 May 2022 00:34:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=8F=98=E5=8C=96:=20?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E4=BC=98=E5=8C=96=E5=8F=8A=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/application/settings.py | 1 - backend/application/urls.py | 2 -- backend/dvadmin/system/views/login.py | 19 +++++-------------- backend/dvadmin/system/views/user.py | 5 +---- web/src/views/system/login/base.vue | 8 +------- web/src/views/system/login/page.vue | 1 + web/src/views/system/user/api.js | 10 +--------- web/src/views/system/user/crud.js | 25 ++++++++++--------------- web/src/views/system/user/index.vue | 9 ++------- 9 files changed, 21 insertions(+), 59 deletions(-) diff --git a/backend/application/settings.py b/backend/application/settings.py index c2dfc73..684640e 100644 --- a/backend/application/settings.py +++ b/backend/application/settings.py @@ -321,7 +321,6 @@ SWAGGER_SETTINGS = { # ================================================= # # **************** 验证码配置 ******************* # # ================================================= # -CAPTCHA_STATE = locals().get("CAPTCHA_STATE", False) CAPTCHA_IMAGE_SIZE = (160, 60) # 设置 captcha 图片大小 CAPTCHA_LENGTH = 4 # 字符个数 CAPTCHA_TIMEOUT = 1 # 超时(minutes) diff --git a/backend/application/urls.py b/backend/application/urls.py index 10ab524..3e090e2 100644 --- a/backend/application/urls.py +++ b/backend/application/urls.py @@ -81,8 +81,6 @@ urlpatterns = ( path("api/init/dictionary/", InitDictionaryViewSet.as_view()), path("api/init/settings/", InitSettingsViewSet.as_view()), path("apiLogin/", ApiLogin.as_view()), - re_path(r'api/upgrade_center_backend/', include('dvadmin_upgrade_center.urls')), - re_path(r'api/dvadmin_upgrade_center/', include('dvadmin_upgrade_center.urls')), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + static(settings.STATIC_URL, document_root=settings.STATIC_URL) diff --git a/backend/dvadmin/system/views/login.py b/backend/dvadmin/system/views/login.py index 2573185..8835c84 100644 --- a/backend/dvadmin/system/views/login.py +++ b/backend/dvadmin/system/views/login.py @@ -14,7 +14,7 @@ from rest_framework.views import APIView from rest_framework_simplejwt.serializers import TokenObtainPairSerializer from rest_framework_simplejwt.views import TokenObtainPairView -from application import settings +from django.conf import settings from dvadmin.system.models import Users from dvadmin.utils.json_response import ErrorResponse, DetailResponse from dvadmin.utils.request_util import save_login_log @@ -34,7 +34,7 @@ class CaptchaView(APIView): ) def get(self, request): data = {} - if settings.CAPTCHA_STATE: + if settings.SYSTEM_CONFIG.get("base.captcha_state"): hashkey = CaptchaStore.generate_key() id = CaptchaStore.objects.filter(hashkey=hashkey).first().id imgage = captcha_image(request, hashkey) @@ -47,15 +47,6 @@ class CaptchaView(APIView): return DetailResponse(data=data) -class CaptchaStatusView(APIView): - - authentication_classes = [] - permission_classes = [] - - def get(self, request): - return DetailResponse(data={"status": settings.CAPTCHA_STATE}) - - class LoginSerializer(TokenObtainPairSerializer): """ 登录的序列化器: @@ -75,7 +66,7 @@ class LoginSerializer(TokenObtainPairSerializer): def validate(self, attrs): captcha = self.initial_data.get("captcha", None) - if settings.CAPTCHA_STATE: + if settings.SYSTEM_CONFIG.get("base.captcha_state"): if captcha is None: raise CustomValidationError("验证码不能为空") self.image_code = CaptchaStore.objects.filter( @@ -87,8 +78,8 @@ class LoginSerializer(TokenObtainPairSerializer): raise CustomValidationError("验证码过期") else: if self.image_code and ( - self.image_code.response == captcha - or self.image_code.challenge == captcha + self.image_code.response == captcha + or self.image_code.challenge == captcha ): self.image_code and self.image_code.delete() else: diff --git a/backend/dvadmin/system/views/user.py b/backend/dvadmin/system/views/user.py index 3b43454..2fcd505 100644 --- a/backend/dvadmin/system/views/user.py +++ b/backend/dvadmin/system/views/user.py @@ -40,9 +40,6 @@ class UserCreateSerializer(CustomModelSerializer): ) password = serializers.CharField( required=False, - default=make_password( - hashlib.md5(settings.DEFAULT_PASSWORD.encode(encoding="UTF-8")).hexdigest() - ), ) def validate_password(self, value): @@ -255,7 +252,7 @@ class UserViewSet(CustomModelViewSet): """恢复默认密码""" instance = Users.objects.filter(id=kwargs.get("pk")).first() if instance: - instance.set_password(settings.DEFAULT_PASSWORD) + instance.set_password(settings.SYSTEM_CONFIG.get("base.default_password")) instance.save() return DetailResponse(data=None, msg="密码重置成功") else: diff --git a/web/src/views/system/login/base.vue b/web/src/views/system/login/base.vue index d49077d..c74e0fc 100644 --- a/web/src/views/system/login/base.vue +++ b/web/src/views/system/login/base.vue @@ -23,7 +23,7 @@ export default { helpUrl: this.systemConfig('login.help_url'), // 帮助 privacyUrl: this.systemConfig('login.privacy_url'), // 隐私 clauseUrl: this.systemConfig('login.clause_url'), // 条款 - captchaState: this.systemConfig('login.captcha_state'), // 验证码 + captchaState: this.systemConfig('base.captcha_state'), // 验证码 processTitle: process.env.VUE_APP_TITLE || 'D2Admin', backgroundImage: 'url(' + this.loginBackground + ')', // 表单 @@ -68,12 +68,6 @@ export default { } }, mounted () { - document.onkeydown = () => { - var key = window.event.keyCode - if (key === 13) { - this.submit() - } - } }, beforeDestroy () { }, diff --git a/web/src/views/system/login/page.vue b/web/src/views/system/login/page.vue index 7490ade..2ace6fe 100644 --- a/web/src/views/system/login/page.vue +++ b/web/src/views/system/login/page.vue @@ -39,6 +39,7 @@ prefix-icon="el-icon-s-promotion" show-password placeholder="密码" + @keyup.enter.native="submit" > diff --git a/web/src/views/system/user/api.js b/web/src/views/system/user/api.js index 6fdf4f0..8a705a3 100644 --- a/web/src/views/system/user/api.js +++ b/web/src/views/system/user/api.js @@ -44,7 +44,7 @@ export function DelObj (id) { /** * 重置密码 - * @param id + * @param obj * @returns {*} * @constructor */ @@ -55,11 +55,3 @@ export function ResetPwd (obj) { data: obj }) } - -export function ResetPwd2Default (obj) { - return request({ - url: urlPrefix + 'reset_to_default_password/' + obj.id + '/', - method: 'put', - data: obj - }) -} diff --git a/web/src/views/system/user/crud.js b/web/src/views/system/user/crud.js index 3b72cf9..e68ab65 100644 --- a/web/src/views/system/user/crud.js +++ b/web/src/views/system/user/crud.js @@ -12,7 +12,7 @@ export const crudOptions = (vm) => { rowKey: true // 必须设置,true or false }, rowHandle: { - width: 270, + width: 240, fixed: 'right', view: { thin: true, @@ -38,7 +38,7 @@ export const crudOptions = (vm) => { custom: [ { thin: true, - text: '', + text: '密码重置', size: 'small', type: 'warning', icon: 'el-icon-refresh-left', @@ -46,18 +46,6 @@ export const crudOptions = (vm) => { return vm.hasPermissions('ResetPassword') }, emit: 'resetPassword' - }, - { - show () { - return vm.hasPermissions('DefaultPassword') - }, - disabled () { - return !vm.hasPermissions('DefaultPassword') - }, - text: '重置密码', - type: 'warning', - size: 'small', - emit: 'defaultPassword' } ] }, @@ -128,11 +116,18 @@ export const crudOptions = (vm) => { minWidth: 90, type: 'input', form: { + rules: [ // 表单校验规则 + { + required: true, + message: '密码必填项' + } + ], component: { span: 12, showPassword: true, - placeholder: '不填则默认为:admin123456' + placeholder: '请输入密码' }, + value: vm.systemConfig('base.default_password'), itemProps: { class: { yxtInput: true } } diff --git a/web/src/views/system/user/index.vue b/web/src/views/system/user/index.vue index 93103a6..087e2bf 100644 --- a/web/src/views/system/user/index.vue +++ b/web/src/views/system/user/index.vue @@ -5,7 +5,6 @@ v-bind="_crudProps" v-on="_crudListeners" @resetPassword="resetPassword" - @defaultPassword="defaultPassword" >