功能变化: 初始化优化及登录优化
parent
6e4b2a4b19
commit
54dcfbf0fa
|
@ -321,7 +321,6 @@ SWAGGER_SETTINGS = {
|
||||||
# ================================================= #
|
# ================================================= #
|
||||||
# **************** 验证码配置 ******************* #
|
# **************** 验证码配置 ******************* #
|
||||||
# ================================================= #
|
# ================================================= #
|
||||||
CAPTCHA_STATE = locals().get("CAPTCHA_STATE", False)
|
|
||||||
CAPTCHA_IMAGE_SIZE = (160, 60) # 设置 captcha 图片大小
|
CAPTCHA_IMAGE_SIZE = (160, 60) # 设置 captcha 图片大小
|
||||||
CAPTCHA_LENGTH = 4 # 字符个数
|
CAPTCHA_LENGTH = 4 # 字符个数
|
||||||
CAPTCHA_TIMEOUT = 1 # 超时(minutes)
|
CAPTCHA_TIMEOUT = 1 # 超时(minutes)
|
||||||
|
|
|
@ -81,8 +81,6 @@ urlpatterns = (
|
||||||
path("api/init/dictionary/", InitDictionaryViewSet.as_view()),
|
path("api/init/dictionary/", InitDictionaryViewSet.as_view()),
|
||||||
path("api/init/settings/", InitSettingsViewSet.as_view()),
|
path("api/init/settings/", InitSettingsViewSet.as_view()),
|
||||||
path("apiLogin/", ApiLogin.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.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||||
+ static(settings.STATIC_URL, document_root=settings.STATIC_URL)
|
+ static(settings.STATIC_URL, document_root=settings.STATIC_URL)
|
||||||
|
|
|
@ -14,7 +14,7 @@ from rest_framework.views import APIView
|
||||||
from rest_framework_simplejwt.serializers import TokenObtainPairSerializer
|
from rest_framework_simplejwt.serializers import TokenObtainPairSerializer
|
||||||
from rest_framework_simplejwt.views import TokenObtainPairView
|
from rest_framework_simplejwt.views import TokenObtainPairView
|
||||||
|
|
||||||
from application import settings
|
from django.conf import settings
|
||||||
from dvadmin.system.models import Users
|
from dvadmin.system.models import Users
|
||||||
from dvadmin.utils.json_response import ErrorResponse, DetailResponse
|
from dvadmin.utils.json_response import ErrorResponse, DetailResponse
|
||||||
from dvadmin.utils.request_util import save_login_log
|
from dvadmin.utils.request_util import save_login_log
|
||||||
|
@ -34,7 +34,7 @@ class CaptchaView(APIView):
|
||||||
)
|
)
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
data = {}
|
data = {}
|
||||||
if settings.CAPTCHA_STATE:
|
if settings.SYSTEM_CONFIG.get("base.captcha_state"):
|
||||||
hashkey = CaptchaStore.generate_key()
|
hashkey = CaptchaStore.generate_key()
|
||||||
id = CaptchaStore.objects.filter(hashkey=hashkey).first().id
|
id = CaptchaStore.objects.filter(hashkey=hashkey).first().id
|
||||||
imgage = captcha_image(request, hashkey)
|
imgage = captcha_image(request, hashkey)
|
||||||
|
@ -47,15 +47,6 @@ class CaptchaView(APIView):
|
||||||
return DetailResponse(data=data)
|
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):
|
class LoginSerializer(TokenObtainPairSerializer):
|
||||||
"""
|
"""
|
||||||
登录的序列化器:
|
登录的序列化器:
|
||||||
|
@ -75,7 +66,7 @@ class LoginSerializer(TokenObtainPairSerializer):
|
||||||
|
|
||||||
def validate(self, attrs):
|
def validate(self, attrs):
|
||||||
captcha = self.initial_data.get("captcha", None)
|
captcha = self.initial_data.get("captcha", None)
|
||||||
if settings.CAPTCHA_STATE:
|
if settings.SYSTEM_CONFIG.get("base.captcha_state"):
|
||||||
if captcha is None:
|
if captcha is None:
|
||||||
raise CustomValidationError("验证码不能为空")
|
raise CustomValidationError("验证码不能为空")
|
||||||
self.image_code = CaptchaStore.objects.filter(
|
self.image_code = CaptchaStore.objects.filter(
|
||||||
|
@ -87,8 +78,8 @@ class LoginSerializer(TokenObtainPairSerializer):
|
||||||
raise CustomValidationError("验证码过期")
|
raise CustomValidationError("验证码过期")
|
||||||
else:
|
else:
|
||||||
if self.image_code and (
|
if self.image_code and (
|
||||||
self.image_code.response == captcha
|
self.image_code.response == captcha
|
||||||
or self.image_code.challenge == captcha
|
or self.image_code.challenge == captcha
|
||||||
):
|
):
|
||||||
self.image_code and self.image_code.delete()
|
self.image_code and self.image_code.delete()
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -40,9 +40,6 @@ class UserCreateSerializer(CustomModelSerializer):
|
||||||
)
|
)
|
||||||
password = serializers.CharField(
|
password = serializers.CharField(
|
||||||
required=False,
|
required=False,
|
||||||
default=make_password(
|
|
||||||
hashlib.md5(settings.DEFAULT_PASSWORD.encode(encoding="UTF-8")).hexdigest()
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def validate_password(self, value):
|
def validate_password(self, value):
|
||||||
|
@ -255,7 +252,7 @@ class UserViewSet(CustomModelViewSet):
|
||||||
"""恢复默认密码"""
|
"""恢复默认密码"""
|
||||||
instance = Users.objects.filter(id=kwargs.get("pk")).first()
|
instance = Users.objects.filter(id=kwargs.get("pk")).first()
|
||||||
if instance:
|
if instance:
|
||||||
instance.set_password(settings.DEFAULT_PASSWORD)
|
instance.set_password(settings.SYSTEM_CONFIG.get("base.default_password"))
|
||||||
instance.save()
|
instance.save()
|
||||||
return DetailResponse(data=None, msg="密码重置成功")
|
return DetailResponse(data=None, msg="密码重置成功")
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -23,7 +23,7 @@ export default {
|
||||||
helpUrl: this.systemConfig('login.help_url'), // 帮助
|
helpUrl: this.systemConfig('login.help_url'), // 帮助
|
||||||
privacyUrl: this.systemConfig('login.privacy_url'), // 隐私
|
privacyUrl: this.systemConfig('login.privacy_url'), // 隐私
|
||||||
clauseUrl: this.systemConfig('login.clause_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',
|
processTitle: process.env.VUE_APP_TITLE || 'D2Admin',
|
||||||
backgroundImage: 'url(' + this.loginBackground + ')',
|
backgroundImage: 'url(' + this.loginBackground + ')',
|
||||||
// 表单
|
// 表单
|
||||||
|
@ -68,12 +68,6 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
document.onkeydown = () => {
|
|
||||||
var key = window.event.keyCode
|
|
||||||
if (key === 13) {
|
|
||||||
this.submit()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
beforeDestroy () {
|
beforeDestroy () {
|
||||||
},
|
},
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
prefix-icon="el-icon-s-promotion"
|
prefix-icon="el-icon-s-promotion"
|
||||||
show-password
|
show-password
|
||||||
placeholder="密码"
|
placeholder="密码"
|
||||||
|
@keyup.enter.native="submit"
|
||||||
>
|
>
|
||||||
</el-input>
|
</el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
|
@ -44,7 +44,7 @@ export function DelObj (id) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 重置密码
|
* 重置密码
|
||||||
* @param id
|
* @param obj
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
|
@ -55,11 +55,3 @@ export function ResetPwd (obj) {
|
||||||
data: obj
|
data: obj
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ResetPwd2Default (obj) {
|
|
||||||
return request({
|
|
||||||
url: urlPrefix + 'reset_to_default_password/' + obj.id + '/',
|
|
||||||
method: 'put',
|
|
||||||
data: obj
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ export const crudOptions = (vm) => {
|
||||||
rowKey: true // 必须设置,true or false
|
rowKey: true // 必须设置,true or false
|
||||||
},
|
},
|
||||||
rowHandle: {
|
rowHandle: {
|
||||||
width: 270,
|
width: 240,
|
||||||
fixed: 'right',
|
fixed: 'right',
|
||||||
view: {
|
view: {
|
||||||
thin: true,
|
thin: true,
|
||||||
|
@ -38,7 +38,7 @@ export const crudOptions = (vm) => {
|
||||||
custom: [
|
custom: [
|
||||||
{
|
{
|
||||||
thin: true,
|
thin: true,
|
||||||
text: '',
|
text: '密码重置',
|
||||||
size: 'small',
|
size: 'small',
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
icon: 'el-icon-refresh-left',
|
icon: 'el-icon-refresh-left',
|
||||||
|
@ -46,18 +46,6 @@ export const crudOptions = (vm) => {
|
||||||
return vm.hasPermissions('ResetPassword')
|
return vm.hasPermissions('ResetPassword')
|
||||||
},
|
},
|
||||||
emit: '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,
|
minWidth: 90,
|
||||||
type: 'input',
|
type: 'input',
|
||||||
form: {
|
form: {
|
||||||
|
rules: [ // 表单校验规则
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
message: '密码必填项'
|
||||||
|
}
|
||||||
|
],
|
||||||
component: {
|
component: {
|
||||||
span: 12,
|
span: 12,
|
||||||
showPassword: true,
|
showPassword: true,
|
||||||
placeholder: '不填则默认为:admin123456'
|
placeholder: '请输入密码'
|
||||||
},
|
},
|
||||||
|
value: vm.systemConfig('base.default_password'),
|
||||||
itemProps: {
|
itemProps: {
|
||||||
class: { yxtInput: true }
|
class: { yxtInput: true }
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
v-bind="_crudProps"
|
v-bind="_crudProps"
|
||||||
v-on="_crudListeners"
|
v-on="_crudListeners"
|
||||||
@resetPassword="resetPassword"
|
@resetPassword="resetPassword"
|
||||||
@defaultPassword="defaultPassword"
|
|
||||||
>
|
>
|
||||||
<div slot="header">
|
<div slot="header">
|
||||||
<crud-search
|
<crud-search
|
||||||
|
@ -36,6 +35,7 @@
|
||||||
title="密码重置"
|
title="密码重置"
|
||||||
:visible.sync="dialogFormVisible"
|
:visible.sync="dialogFormVisible"
|
||||||
:close-on-click-modal="false"
|
:close-on-click-modal="false"
|
||||||
|
width="30%"
|
||||||
>
|
>
|
||||||
<el-form :model="resetPwdForm" ref="resetPwdForm" :rules="passwordRules">
|
<el-form :model="resetPwdForm" ref="resetPwdForm" :rules="passwordRules">
|
||||||
<el-form-item label="密码" prop="pwd">
|
<el-form-item label="密码" prop="pwd">
|
||||||
|
@ -59,7 +59,7 @@
|
||||||
</el-form>
|
</el-form>
|
||||||
<div slot="footer" class="dialog-footer">
|
<div slot="footer" class="dialog-footer">
|
||||||
<el-button @click="dialogFormVisible = false">取 消</el-button>
|
<el-button @click="dialogFormVisible = false">取 消</el-button>
|
||||||
<el-button type="primary" @click="resetPwdSubmit">确 定</el-button>
|
<el-button type="primary" @click="resetPwdSubmit">重 置</el-button>
|
||||||
</div>
|
</div>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
</d2-container>
|
</d2-container>
|
||||||
|
@ -132,11 +132,6 @@ export default {
|
||||||
delRequest (row) {
|
delRequest (row) {
|
||||||
return api.DelObj(row.id)
|
return api.DelObj(row.id)
|
||||||
},
|
},
|
||||||
defaultPassword (scope) {
|
|
||||||
api.ResetPwd2Default(scope.row).then((res) => {
|
|
||||||
this.$message.success('密码重置成功')
|
|
||||||
})
|
|
||||||
},
|
|
||||||
// 重置密码弹框
|
// 重置密码弹框
|
||||||
resetPassword ({ row }) {
|
resetPassword ({ row }) {
|
||||||
this.dialogFormVisible = true
|
this.dialogFormVisible = true
|
||||||
|
|
Loading…
Reference in New Issue