コード例 #1
0
def detail_house_info(house_id):
    user_id = session.get("user_id", -1)

    try:
        house_dict = redis_store.get(("house_detail_%d" % house_id))
        if house_dict:
            return jsonify(errno=RET.OK, errmsg="ok", data={"user_id": user_id, "house": eval(house_dict)})
    except Exception as e:
        current_app.logger.error(e)

    try:
        house = House.query.get(house_id)
    except Exception as e:
        current_app.logger.error(e)
        return jsonify(errno=RET.DBERR, errmsg="获取数据失败")
    if not house:
        return jsonify(errno=RET.PARAMERR, errmsg="参数错误")
    house_dict = house.to_full_dict()

    try:
        redis_store.set(("house_detail_%d" % house_id), house_dict, HOUSE_DETAIL_REDIS_EXPIRE_SECOND)
    except Exception as e:
        current_app.logger.error(e)

    return jsonify(errno=RET.OK, errmsg="0", data={"house": house_dict, "user_id": user_id})
コード例 #2
0
def release_areas():
    # 城区信息缓存到redis中
    try:
        areas_dict = redis_store.get('area_info')
    except Exception as e:
        current_app.logger.error(e)
    if areas_dict:
        return jsonify(errno=RET.OK, errmsg="获取成功", data=eval(areas_dict))

    try:
        areas = Area.query.all()
    except Exception as e:
        current_app.logger.error(e)
        return jsonify(errno=RET.DBERR, errmsg="获取数据失败")

    areas_dict = []
    for area in areas:
        areas_dict.append(area.to_dict())

    # 数据保存到redis中
    try:
        redis_store.set('area_info', areas_dict, AREA_INFO_REDIS_EXPIRES)
    except Exception as e:
        current_app.logger.error(e)

    return jsonify(errno=RET.OK, errmsg="获取成功", data=areas_dict)
コード例 #3
0
ファイル: verify.py プロジェクト: Despairvip/Flask
def get_sms_code():
    # 获取手机号.图片验证编码,图片验证码内容
    json_data = request.data
    data = json.loads(json_data)
    mobile = data.get("mobile")
    image_id = data.get("image_code_id")
    image_content = data.get("image_code")

    # 检验内容是否正确
    if not all([mobile, image_content, image_id]):
        return jsonify(errno=RET.PARAMERR, errmsg="参数不全")

    if not re.match("^1[3578][0-9]{9}$", mobile):
        return jsonify(errno=RET.PARAMERR, errmsg="手机号码格式错误")

    try:
        redis_image_content = redis_store.get("Image_code" + image_id)
        if redis_image_content:
            redis_store.delete("Image_code" + image_id)
    except Exception as e:
        current_app.logger.error(e)
        return jsonify(errno=RET.DBERR, errmsg="获取验证码错误")
    if not redis_image_content:
        return jsonify(errno=RET.PARAMERR, errmsg="验证码已过期")

    # 对比redis中的验证码内容
    if image_content.lower() != redis_image_content.lower():
        return jsonify(errno=RET.PARAMERR, errmsg="验证码错误")

    # 查询是否已经注册
    try:
        user = User.query.filter_by(mobile=mobile).first()
    except Exception as e:
        current_app.logger.error(e)
        user = None
    if user:
        return jsonify(errno=RET.DATAERR, errmsg="手机号码已经注册")

    # 生成短信验证码
    result = random.randint(0, 9999)
    sms_code = "%06d" % result
    current_app.logger.debug("短信验证码的内容是:%s" % sms_code)
    # 保存短信验证码内容
    try:
        redis_store.set("SMS_" + mobile, sms_code, constants.SMS_CODE_REDIS_EXPIRES)
    except Exception as e:
        current_app.logger.error(e)
        return jsonify(errno=RET.DBERR, errmsg="保存短信验证码失败")
    # 返回结果
    return jsonify(errno=RET.OK, errmsg="OK")
コード例 #4
0
ファイル: verify.py プロジェクト: Despairvip/Flask
def get_image_code():
    # 获取前端传入的验证码编号
    args = request.args
    cur = args.get("cur")
    pre = args.get("pre")
    # 判断传入的参数是否有值
    if not cur:
        abort(403)

    # 生成图片验证码
    _, text, image = captcha.generate_captcha()
    current_app.logger.debug(text)
    # 吧图片验证码和编码存到redis中
    try:
        redis_store.delete("Image_code" + pre)
        redis_store.set("Image_code" + cur, text, constants.IMAGE_CODE_REDIS_EXPIRES)
    except Exception as e:
        current_app.logger.error(e)
        return jsonify(errno=RET.DBERR, errmsg="存入数据库出错")
    # 返回验证码图片
    response = make_response(image)
    response.headers["Content-Type"] = "image/jpg"
    return response
コード例 #5
0
def get_index():
    try:
        house_dict = redis_store.get("house_info")
        if house_dict:
            return jsonify(errno=RET.OK, errmsg="OK", data={"houses": eval(house_dict)})
    except Exception as e:
        current_app.logger.error(e)

    try:
        houses = House.query.order_by(House.order_count.desc()).limit(HOME_PAGE_MAX_HOUSES)
    except Exception as e:
        current_app.logger.error(e)
        return jsonify(errno=RET.DBERR, errmsg="获取数据失败")

    house_dict = []
    for house in houses:
        house_dict.append(house.to_basic_dict())

    try:
        redis_store.set("houses_info", house_dict, HOME_PAGE_DATA_REDIS_EXPIRES)
    except Exception as e:
        current_app.logger.error(e)

    return jsonify(errno=RET.OK, errmsg="OK", data={"houses": house_dict})