接口测试 测试平台登录注册实现

菜鸟 · June 03, 2020 · Last by 菜鸟 replied at June 04, 2020 · 1580 hits

前言

目前基本上架子已经成型了,然后接下去开始做下接口测试部分,慢慢撸。

效果展示


部分代码

# 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)
                }
            },

ChangeLog:

  1. 后台登录注册功能
  2. 前端登录注册页面,个人中心页面,svg-icon 集成

下期功能

  1. 个人中心后端实现
  2. 接口配置功能实现以及部分配置模块
共收到 3 条回复 时间 点赞
菜鸟 · #1 · June 03, 2020 Author
Author only

这么简洁的吗?

菜鸟 #3 · June 04, 2020 Author
徐汪成 回复

哈哈哈不怎么会写帖子

菜鸟 关闭了讨论 10 Jun 09:39
需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up