Example #1
0
def check_bind(app, openid, gen_token=False):
	if frappe.request.method != "POST" and frappe.request.method != "PUT":
		throw(_("Request Method Must be POST!"))

	from iot.user_api import valid_auth_code
	valid_auth_code()

	frappe.logger(__name__).info(_("check_bind {0}").format(openid))

	user = frappe.get_value('Wechat Binding', {'app': app, 'openid': openid}, 'user')
	if not user:
		if frappe.get_value('Wechat App', app, 'name'):
			throw(_("There is no user bind with this openid!"))
		else:
			throw(_('Wechat application name does not exists!'))

	token = frappe.get_value("IOT User Api", user, 'authorization_code')

	if not token and gen_token is not False:
		doc = frappe.get_doc({
			"doctype": "IOT User Api",
			"user": user,
			"authorization_code": str(uuid.uuid1()).upper()
		}).insert()

		token = doc.authorization_code

	return {
		"user": user,
		"fullname": get_fullname(user),
		"token": token,
		"creation": frappe.get_value('Wechat Binding', {'app': app, 'openid': openid}, 'creation')
	}
Example #2
0
def app_conf_detail(name, fields=app_conf_fields):
    valid_auth_code()
    result = frappe.get_all("IOT Application Conf",
                            fields=fields,
                            filters={"name": name})
    if len(result) == 1:
        return add_more_info(result[0])
    return None
Example #3
0
def upload_conf_version(conf, version, data, comment=None):
    valid_auth_code()
    version_data = {
        "doctype": "IOT Application Conf Version",
        "conf": conf,
        "version": version,
        "comment": comment,
        "data": data
    }
    doc = frappe.get_doc(version_data).insert()
    return True
Example #4
0
def modify_app_conf(name, conf_name=None, description=None, public=1):
    valid_auth_code()
    doc = frappe.get_doc('IOT Application Conf', name)
    if conf_name:
        doc.set("conf_name", conf_name)
    if description:
        doc.set("description", description)
    if description:
        doc.set("description", description)
    if public:
        doc.set("public", public)
    doc.save()
    return _("Done!")
Example #5
0
def upload_device_conf(conf=None):
    valid_auth_code()
    conf = conf or get_post_json_data()

    ts = datetime.datetime.utcfromtimestamp(int(conf.get("timestamp")))
    ts = convert_utc_to_user_timezone(ts).replace(tzinfo=None)
    dev_conf = {
        "doctype": "IOT Device Conf",
        "device": conf.get("sn"),
        "timestamp": ts,
        "data": conf.get("data"),
        "hashing": conf.get("md5")
    }
    doc = frappe.get_doc(dev_conf).insert(ignore_permissions=True)
    return True
Example #6
0
def list_app_conf(app,
                  filters=None,
                  fields=app_conf_fields,
                  order_by="modified desc",
                  start=0,
                  limit=40):
    valid_auth_code()
    filters = filters or {}
    filters.update({
        "app": app,
        "developer": ["!=", 'Administrator'],
        "public": 1,
    })

    result = frappe.get_all("IOT Application Conf",
                            fields=fields,
                            filters=filters,
                            order_by=order_by,
                            start=start,
                            limit=limit)

    return [add_more_info(d) for d in result]
Example #7
0
def create_app_conf(app,
                    conf_name,
                    description,
                    type='Template',
                    company=None,
                    public=1):
    valid_auth_code()

    if public is True:
        public = 1

    conf_data = {
        "doctype": "IOT Application Conf",
        "app": app,
        "conf_name": conf_name,
        "description": description,
        "type": type,
        "developer": frappe.session.user,
        "company": company,
        "public": public
    }
    doc = frappe.get_doc(conf_data).insert()
    return doc.name
Example #8
0
def device_conf_list(sn):
    valid_auth_code()
    return frappe.get_all("IOT Device Conf", {"device": sn},
                          ["name", "timestamp", "data", "hashing"])
Example #9
0
def delete_app_conf(name):
    valid_auth_code()
    frappe.delete_doc("IOT Application Conf", name)
    return _("Deleted!")