目前基本上架子已经成型了,然后接下去开始做下接口测试部分,慢慢撸。
# DRF全局配置
REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 10,
'DEFAULT_VERSIONING_CLASS': 'rest_framework.versioning.URLPathVersioning',
'DEFAULT_VERSION': 'v1',
'ALLOWED_VERSIONS': ['v1', 'v2'],
'VERSION_PARAM': 'version',
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
'rest_framework.authentication.TokenAuthentication',
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
]
}
# ULR正则表达式
REGEX_URL_PATH = "(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]"
# 手机号码正则表达式
REGEX_MOBILE = "^1[358]\d{9}$|^147\d{8}$|^176\d{8}$"
# 服务端允许跨域
CORS_ORIGIN_ALLOW_ALL = True
# JWT
JWT_AUTH = {
'JWT_EXPIRATION_DELTA': datetime.timedelta(days=7), # or seconds=20
'JWT_AUTH_HEADER_PREFIX': 'JWT',
}
class UserRegisterViewSet(mixins.CreateModelMixin, viewsets.GenericViewSet):
serializer_class = UserRegisterSerializer
def create(self, request, *args, **kwargs):
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
user = self.perform_create(serializer)
headers = self.get_success_headers(serializer.data)
payload = jwt_payload_handler(user)
token = jwt_encode_handler(payload)
ret_data = {'username': user.username, 'userid': user.id, 'token': token}
ret_data.update(serializer.data)
return Response(ret_data, status=status.HTTP_201_CREATED, headers=headers)
def perform_create(self, serializer):
return serializer.save()
obtainCode() {
if (this.show && this.regParam.username !== '') {
const telephoneReg = /^1[3456789]\d{9}$/;
getVerifyCode({
account: this.regParam.username,
account_type: telephoneReg.test(this.regParam.username.trim()) ? 'mobile' : 'email'
}).then((response) => {
console.log(response);
this.show = false;
this.$message({message: '验证码已发送!', type: 'success'})
}).catch((error) => {
for (let key in error) {
let errorMsg = error[key];
for (let i = 0; i < errorMsg.length; i++) {
this.$message({message: errorMsg[i], type: 'error'})
}
}
})
} else {
this.$message({message: '请输入邮箱!!', type: 'error'})
}
const TIME_COUNT = 60;
if (!this.timer) {
this.count = TIME_COUNT;
this.timer = setInterval(() => {
if (this.count > 0 && this.count <= TIME_COUNT) {
this.count--;
} else {
this.show = true;
clearInterval(this.timer);
this.timer = null;
}
}, 1000)
}
},