本文整理汇总了Python中tools.Tools.setData方法的典型用法代码示例。如果您正苦于以下问题:Python Tools.setData方法的具体用法?Python Tools.setData怎么用?Python Tools.setData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tools.Tools
的用法示例。
在下文中一共展示了Tools.setData方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: site_subscribe
# 需要导入模块: from tools import Tools [as 别名]
# 或者: from tools.Tools import setData [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"})
示例2: phone_fetchcode
# 需要导入模块: from tools import Tools [as 别名]
# 或者: from tools.Tools import setData [as 别名]
def phone_fetchcode():
if not "id" in request.form:
return jsonify({"error": "id not present"}), 400
if not "key" in request.form:
return jsonify({"error": "key not present"}), 400
_id = request.form['id']
_key = request.form['key']
# + key pour signer WS
r = get_db()
key = Tools.generateSimpleHash()
while r.hexists("waiting_devices", key):
key = generateSimpleHash()
r.hset("waiting_devices", key, _id)
print("fetchcode: device_" + _id + ", secret: " + _key + ", 6digits" + key)
# rajouter un expire
Tools.setData(r, "device_" + _id, {"secret": _key, "6digits": key})
return jsonify({"hash": key})
示例3: site_removeDevices
# 需要导入模块: from tools import Tools [as 别名]
# 或者: from tools.Tools import setData [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})
示例4: site_addDevices
# 需要导入模块: from tools import Tools [as 别名]
# 或者: from tools.Tools import setData [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})