예제 #1
0
def register():
    data = request.get_json()
    if 'phone' not in data or 'password' not in data:
        return "信息缺失"

    phone = data['phone']
    password = data['password']

    # 判断电话号码是否为空
    if phone is None:
        return "The phone number is empty!"

    # 判断密码是否为空
    if password is None:
        return "The password is empty!"

    # 检测手机是否已经使用
    phone_is_used = verify_phone(phone)
    if phone_is_used:
        result = return_status(-1)  # 手机号码被使用
        return jsonify(result)

    # 检测手机格式是否正确
    phone_format_false = verify_phone_format(phone)
    if phone_format_false:
        result = return_status(-2)  # 手机格式不正确
        return jsonify(result)

    user = User()
    user.set_phone(phone)
    user.set_password(password)

    try:
        user_dao = UserDAO()
        user_dao.add(user)
        result = return_status(0)
        return jsonify(result)  # 注册成功
    except:
        return "Server failure!"
예제 #2
0
def api_add_user():
    id = UserDAO.add(request.json)

    return jsonify({"id": str(id)})