示例#1
0
def pair(code):
    device = DEVICES.get_unpaired_by_code(code)
    if device:
        user = get_user()
        if DEVICES.add_device(uuid=device.uuid, mail=user.mail):
            DEVICES.remove_unpaired(device.uuid)
            msg = Message("Device was paired", recipients=[user.mail])
            mail.send(msg)
            return True
    return False
示例#2
0
def pair(code, uuid, name, mail):
    # pair
    result = {"paired": False}
    device = DEVICES.get_unpaired_by_uuid(uuid)
    if device and device.code == code:
        user = DEVICES.get_user_by_mail(mail)
        # create user if it doesnt exist
        if not user:
            DEVICES.add_user(mail, name, "666")
        if DEVICES.add_device(uuid, mail=mail):
            DEVICES.remove_unpaired(uuid)
            result = {"paired": True}
    return nice_json(result)