|
@@ -89,6 +89,8 @@ def Request(ctx):
|
|
|
res = Ruleclass(_conn, ctx)
|
|
res = Ruleclass(_conn, ctx)
|
|
|
elif ctx["function"] == "RecycleCard":
|
|
elif ctx["function"] == "RecycleCard":
|
|
|
res = RecycleCard(_conn, ctx)
|
|
res = RecycleCard(_conn, ctx)
|
|
|
|
|
+ elif ctx["function"] == "AddCardBlock":
|
|
|
|
|
+ res = AddCardBlock(_conn, ctx)
|
|
|
|
|
|
|
|
_conn.close()
|
|
_conn.close()
|
|
|
|
|
|
|
@@ -814,6 +816,91 @@ def RecycleCard(db, ctx):
|
|
|
|
|
|
|
|
return res
|
|
return res
|
|
|
|
|
|
|
|
|
|
+## _ _ _ _ _ _
|
|
|
|
|
+## __ _ __| | __| | ___ __ _ _ __ __| | | |__ | | ___ ___| | __
|
|
|
|
|
+## / _` |/ _` |/ _` | / __/ _` | '__/ _` | | '_ \| |/ _ \ / __| |/ /
|
|
|
|
|
+## | (_| | (_| | (_| | | (_| (_| | | | (_| | | |_) | | (_) | (__| <
|
|
|
|
|
+## \__,_|\__,_|\__,_| \___\__,_|_| \__,_| |_.__/|_|\___/ \___|_|\_\
|
|
|
|
|
+##
|
|
|
|
|
+
|
|
|
|
|
+def AddCardBlock(db, ctx):
|
|
|
|
|
+ res = {"result":"fail"}
|
|
|
|
|
+ cursor = db.cursor()
|
|
|
|
|
+
|
|
|
|
|
+ fields = ["mag_token", "rfid_token", "group_id",
|
|
|
|
|
+ "rule", "nday_orig", "nrides_remain", "nrides_orig",
|
|
|
|
|
+ "count",
|
|
|
|
|
+ "pass_rule", "pass_nrides_remain", "pass_nrides_orig",
|
|
|
|
|
+ "pass_nday_orig", "pass_class"]
|
|
|
|
|
+
|
|
|
|
|
+ val = {}
|
|
|
|
|
+ for f in fields:
|
|
|
|
|
+ if f in ctx:
|
|
|
|
|
+ if ctx[f] and len(ctx[f]) > 0:
|
|
|
|
|
+ val[f] = ctx[f]
|
|
|
|
|
+
|
|
|
|
|
+ if not ("count" in val):
|
|
|
|
|
+ res["result"] = "fail"
|
|
|
|
|
+ res["api_comment"] = "count must be positive"
|
|
|
|
|
+ return res
|
|
|
|
|
+
|
|
|
|
|
+ if ((not ("mag_token" in val)) and
|
|
|
|
|
+ (not ("rfid_token" in val))):
|
|
|
|
|
+ res["result"] = "fail"
|
|
|
|
|
+ res["api_comment"] = "mag_token and/or rfid_token must be specified"
|
|
|
|
|
+ return res
|
|
|
|
|
+
|
|
|
|
|
+ use_mag = False
|
|
|
|
|
+ use_rfid = False
|
|
|
|
|
+ if "mag_token" in val:
|
|
|
|
|
+ use_mag = True
|
|
|
|
|
+ pfx_mag_cred = val["mag_token"].split(":")[0]
|
|
|
|
|
+ base_mag_cred = int(val["mag_token"].split(":")[-1])
|
|
|
|
|
+
|
|
|
|
|
+ if "rfid_token" in val:
|
|
|
|
|
+ use_rfid = True
|
|
|
|
|
+ pfx_rfid_cred = ":".join(val["rfid_token"].split(":")[0:2])
|
|
|
|
|
+ base_rfid_cred = int(val["rfid_token"].split(":")[-1])
|
|
|
|
|
+
|
|
|
|
|
+ logical_card_ids = []
|
|
|
|
|
+ for idx in range(int(val["count"])):
|
|
|
|
|
+
|
|
|
|
|
+ card_info = {"action":"add", "group_id":val["group_id"], "active":1}
|
|
|
|
|
+ if "mag_token" in val: card_info["mag_token"] = val["mag_token"]
|
|
|
|
|
+ if "rfid_token" in val: card_info["rfid_token"] = val["rfid_token"]
|
|
|
|
|
+
|
|
|
|
|
+ if use_mag:
|
|
|
|
|
+ card_info["mag_token"] = pfx_mag_cred + ":" + str(base_mag_cred + idx)
|
|
|
|
|
+ if use_rfid:
|
|
|
|
|
+ card_info["rfid_token"] = pfx_rfid_cred + ":" + str(base_rfid_cred + idx)
|
|
|
|
|
+
|
|
|
|
|
+ card_res = Card(db, card_info)
|
|
|
|
|
+ if card_res["result"] != "success":
|
|
|
|
|
+ res["result"] = "fail"
|
|
|
|
|
+ res["api_comment"] = "failed to add card"
|
|
|
|
|
+ return res
|
|
|
|
|
+ logical_card_id = card_res["logical_card_id"]
|
|
|
|
|
+
|
|
|
|
|
+ if "pass_rule" in val:
|
|
|
|
|
+ pass_info = {"action":"add", "logical_card_id":logical_card_id, "active":1,
|
|
|
|
|
+ "rule" : val["pass_rule"] }
|
|
|
|
|
+ if val["pass_class"] == "OTHER":
|
|
|
|
|
+ pass
|
|
|
|
|
+ elif val["pass_class"] == "NRIDE":
|
|
|
|
|
+ pass_info["nrides_remain"] = val["pass_nrides_remain"]
|
|
|
|
|
+ pass_info["nrides_orig"] = val["pass_nrides_orig"]
|
|
|
|
|
+ elif val["pass_class"] == "NDAY":
|
|
|
|
|
+ pass_info["nday_orig"] = val["pass_nday_orig"]
|
|
|
|
|
+ pass_res = Pass(db, pass_info)
|
|
|
|
|
+
|
|
|
|
|
+ logical_card_ids.append(logical_card_id)
|
|
|
|
|
+
|
|
|
|
|
+ res["result"] = "success"
|
|
|
|
|
+ res["logical_card_ids"] = logical_card_ids
|
|
|
|
|
+
|
|
|
|
|
+ return res
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
## _
|
|
## _
|
|
|
## _ __ ___ __ _(_)_ __
|
|
## _ __ ___ __ _(_)_ __
|
|
|
## | '_ ` _ \ / _` | | '_ \
|
|
## | '_ ` _ \ / _` | | '_ \
|