Pre Merge pull request !47 from zghmvp/main

pull/47/MERGE
zghmvp 2022-04-15 09:08:12 +00:00 committed by Gitee
commit 0aabfe6cf0
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 20 additions and 15 deletions

View File

@ -7,8 +7,11 @@ from application.settings import BASE_DIR
# ================================================= # # ================================================= #
# #
# 数据库 ENGINE ,默认演示使用 sqlite3 数据库,正式环境建议使用 mysql 数据库 # 数据库 ENGINE ,默认演示使用 sqlite3 数据库,正式环境建议使用 mysql 数据库
# Mysql 设置
# DATABASE_ENGINE = "django.db.backends.mysql"
# DATABASE_NAME = "django-vue-admin"
# sqlite3 设置
DATABASE_ENGINE = "django.db.backends.sqlite3" DATABASE_ENGINE = "django.db.backends.sqlite3"
# 数据库名
DATABASE_NAME = os.path.join(BASE_DIR, 'db.sqlite3') DATABASE_NAME = os.path.join(BASE_DIR, 'db.sqlite3')
# 使用mysql时改为此配置 # 使用mysql时改为此配置

View File

@ -11,6 +11,7 @@ import hashlib
from datetime import datetime, timedelta from datetime import datetime, timedelta
from captcha.views import CaptchaStore, captcha_image from captcha.views import CaptchaStore, captcha_image
from django.conf import settings
from django.contrib import auth from django.contrib import auth
from django.contrib.auth import login from django.contrib.auth import login
from django.shortcuts import redirect from django.shortcuts import redirect
@ -56,7 +57,7 @@ class LoginSerializer(TokenObtainPairSerializer):
登录的序列化器: 登录的序列化器:
重写djangorestframework-simplejwt的序列化器 重写djangorestframework-simplejwt的序列化器
""" """
captcha = serializers.CharField(max_length=6) captcha = serializers.CharField(max_length=6, required=False, allow_null=True)
class Meta: class Meta:
model = Users model = Users
@ -68,18 +69,19 @@ class LoginSerializer(TokenObtainPairSerializer):
} }
def validate_captcha(self, captcha): def validate_captcha(self, captcha):
self.image_code = CaptchaStore.objects.filter( if settings.CAPTCHA_STATE is True:
id=self.initial_data['captchaKey']).first() self.image_code = CaptchaStore.objects.filter(
five_minute_ago = datetime.now() - timedelta(hours=0, minutes=5, seconds=0) id=self.initial_data['captchaKey']).first()
if self.image_code and five_minute_ago > self.image_code.expiration: five_minute_ago = datetime.now() - timedelta(hours=0, minutes=5, seconds=0)
self.image_code and self.image_code.delete() if self.image_code and five_minute_ago > self.image_code.expiration:
raise CustomValidationError('验证码过期') self.image_code and self.image_code.delete()
else: raise CustomValidationError('验证码过期')
if self.image_code and (self.image_code.response == captcha or self.image_code.challenge == captcha): else:
self.image_code and self.image_code.delete() if self.image_code and (self.image_code.response == captcha or self.image_code.challenge == captcha):
else: self.image_code and self.image_code.delete()
self.image_code and self.image_code.delete() else:
raise CustomValidationError("图片验证码错误") self.image_code and self.image_code.delete()
raise CustomValidationError("图片验证码错误")
def validate(self, attrs): def validate(self, attrs):
data = super().validate(attrs) data = super().validate(attrs)

View File

@ -130,7 +130,7 @@ export const crudOptions = (vm) => {
type: 'cascader', type: 'cascader',
dict: { dict: {
url: menuPrefix + '?limit=999&status=1&is_catalog=1', url: menuPrefix + '?limit=999&status=1&is_catalog=1',
cache: false, // cache: false,
isTree: true, isTree: true,
value: 'id', // 数据字典中value字段的属性名 value: 'id', // 数据字典中value字段的属性名
label: 'name', // 数据字典中label字段的属性名 label: 'name', // 数据字典中label字段的属性名