Example #1
0
def create_client():
    form = ClientForm()
    form.validate_for_api()

    promise = {
        ClientTypeEnum.USER_EMAIL:__register_user_by_email
    }
    promise[form.type.data]()
    # 我们可以预知
    return Success()
Example #2
0
def create_client():
    data = request.json  # 获取json参数
    form = ClientForm(data=data)  # 在form中进行校验
    form.validate_for_api()  # 抛出验证错误
    promise = {
        ClientTypeEnum.USER_EMAIL: __register_user_by_email,
        ClientTypeEnum.USER_MOBILE: __register_user_by_mobile,
    }
    promise[form.type.data]()  # 执行邮箱注册逻辑
    return Success()
Example #3
0
def create_client():
    # request.json的数据隐藏在了ClientForm的基类中直接调用,简化调用
    form = ClientForm()
    form.validate_for_api()
    promise = {
        ClientTypeEnum.USER_EMAIL: __reister_user_by_email,
    }
    # 调用__reister_user_by_email方法,通过枚举类型拿到
    promise[form.type.data]()

    # return一个类本质是返回的一个HTTPException 实际上是一个html返回
    return Success()