本文整理汇总了Python中tools.Tools.getData方法的典型用法代码示例。如果您正苦于以下问题:Python Tools.getData方法的具体用法?Python Tools.getData怎么用?Python Tools.getData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tools.Tools
的用法示例。
在下文中一共展示了Tools.getData方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: site_getDevices
# 需要导入模块: from tools import Tools [as 别名]
# 或者: from tools.Tools import getData [as 别名]
def site_getDevices():
if not g.user:
return jsonify({"error": "not loggued"}), 403
r = get_db()
obj = Tools.getData(r, "user_" + g.user)
if len(obj) == 0:
return jsonify({"error": "internal error, user object is empty"}), 500
devices = {}
if "devices" in obj:
for k in obj["devices"]:
devices[k] = Tools.getData(r, "device_" + k)
return jsonify({"devices": devices})
示例2: site_removeDevices
# 需要导入模块: from tools import Tools [as 别名]
# 或者: from tools.Tools import getData [as 别名]
def site_removeDevices():
if not g.user:
return jsonify({"error": "not loggued"}), 403
r = get_db()
obj = Tools.getData(r, "user_" + g.user)
if len(obj) == 0:
return jsonify({"error": "internal error, user object is empty"}), 500
if not "id" in request.form:
return jsonify({"error": "id not present"}), 400
_id = request.form['id']
device = Tools.getData(r, "device_" + _id)
if len(device) == 0:
return jsonify({"error": "internal error, device object is empty"}), 500
if "owner" in device:
device.pop("owner", None)
Tools.setData(r, "device_" + _id, device)
if "devices" in obj:
if obj["devices"].count(_id) > 0:
obj["devices"].remove(_id)
Tools.setData(r, "user_" + g.user, obj)
return jsonify({"removed": "true", "id": _id})
示例3: site_addDevices
# 需要导入模块: from tools import Tools [as 别名]
# 或者: from tools.Tools import getData [as 别名]
def site_addDevices():
if not g.user:
return jsonify({"error": "not loggued"}), 403
r = get_db()
obj = Tools.getData(r, "user_" + g.user)
if len(obj) == 0:
return jsonify({"error": "internal error, user object is empty"}), 500
if not "code" in request.form:
return jsonify({"error": "code not present"}), 400
_6digits = request.form['code']
if not r.hexists("waiting_devices", _6digits):
return jsonify({"error": "device not known"}), 404
_id = r.hget("waiting_devices", _6digits)
device = Tools.getData(r, "device_" + _id)
if len(device) == 0:
return jsonify({"error": "internal error, device object is empty"}), 500
if not "devices" in obj:
obj["devices"] = []
obj["devices"].append(_id)
device["owner"] = obj["email"]
Tools.setData(r, "device_" + _id, device)
Tools.setData(r, "user_" + g.user, obj)
return jsonify({"added": "true", "id": _id})
示例4: site_subscribe
# 需要导入模块: from tools import Tools [as 别名]
# 或者: from tools.Tools import getData [as 别名]
def site_subscribe():
if g.user:
return jsonify({"error": "already loggued"}), 403
if not "email" in request.form and len(request.form["email"]) > 0:
return jsonify({"error": "email not present"}), 400
email = request.form["email"]
if not "password" in request.form and len(request.form["password"]) > 0:
return jsonify({"error": "password not present"}), 400
password = request.form["password"]
r = get_db()
if len(Tools.getData(r, "user_" + email)) > 0:
return jsonify({"error": "user already exists"}), 400
Tools.setData(r, "user_" + email, {"email": email, "password": hashlib.sha1(password).hexdigest()})
return jsonify({"subscribed": "true"})
示例5: site_getCoordinates
# 需要导入模块: from tools import Tools [as 别名]
# 或者: from tools.Tools import getData [as 别名]
def site_getCoordinates():
if not g.user:
return jsonify({"error": "not loggued"}), 403
r = get_db()
obj = Tools.getData(r, "user_" + g.user)
if len(obj) == 0:
return jsonify({"error": "internal error, user object is empty"}), 500
_id = request.args.get('id', None)
if not "devices" in obj or _id not in obj["devices"]:
return jsonify({"error": "you are not the owner of the device"}), 403
_from = int(request.args.get("from", "100"))
_count = int(request.args.get("count", "100"))
if _count > 500:
return jsonify({"error": "range too big"}), 400
coordinates = r.lrange("coordinates_" + _id, -1 * _from, _count)
return jsonify({"id": _id, "coordinates": coordinates})
示例6: site_login
# 需要导入模块: from tools import Tools [as 别名]
# 或者: from tools.Tools import getData [as 别名]
def site_login():
if g.user:
return jsonify({"error": "already loggued"}), 403
if not "email" in request.form and len(request.form["email"]) > 0:
return jsonify({"error": "email not present"}), 400
email = request.form["email"]
if not "password" in request.form and len(request.form["password"]) > 0:
return jsonify({"error": "password not present"}), 400
password = request.form["password"]
r = get_db()
obj = Tools.getData(r, "user_" + email)
if len(obj) == 0:
return jsonify({"error": "user doesn't exist"}), 404
if obj["password"] != hashlib.sha1(password).hexdigest():
return jsonify({"error": "incorrect password"}), 403
session["user_id"] = email
return jsonify({"loggued": "true"})
示例7: phone_post_coordinates
# 需要导入模块: from tools import Tools [as 别名]
# 或者: from tools.Tools import getData [as 别名]
def phone_post_coordinates():
if not "id" in request.form:
return jsonify({"error": "id not present"}), 400
if not "signature" in request.form:
return jsonify({"error": "signature not present"}), 400
if not "long" in request.form or not "lat" in request.form:
return jsonify({"error": "position not present"}), 400
r = get_db()
_signature = request.form['signature']
_id = request.form['id']
_long = float(request.form['long'])
_lat = float(request.form['lat'])
obj = Tools.getData(r, "device_" + _id)
if not "secret" in obj:
return jsonify({"error": "secret not present"}), 400
if not Tools.checkSignature(_id, obj["secret"], _signature):
return jsonify({"error": "wrong signature"}), 400
r.lpush("coordinates_" + _id, str(_lat) + ", " + str(_long))
return jsonify({"saved": "true"})
示例8: phone_registered
# 需要导入模块: from tools import Tools [as 别名]
# 或者: from tools.Tools import getData [as 别名]
def phone_registered():
r = get_db()
if not "code" in request.form:
return jsonify({"error": "code not present"}), 400
if not "signature" in request.form:
return jsonify({"error": "signature not present"}), 400
_6digits = request.form['code']
_signature = request.form['signature']
if not r.hexists("waiting_devices", _6digits):
return jsonify({"error": "device not known"}), 404
_id = r.hget("waiting_devices", _6digits)
obj = Tools.getData(r, "device_" + _id)
print("registered: device_" + _id + ", obj: " + str(obj) + ", 6digits" + _6digits + ", signature: " + _signature)
if not "secret" in obj:
return jsonify({"error": "secret not present"}), 404
if not Tools.checkSignature(_id, obj["secret"], _signature):
return jsonify({"error": "wrong signature"}), 400
if not "owner" in obj:
return jsonify({"registered": "false"})
return jsonify({"registered": "true", "owner": obj["owner"]})