65 lines
1.5 KiB
Plaintext
Executable File
65 lines
1.5 KiB
Plaintext
Executable File
local dl = require("dirtylarry.dirtylarry")
|
|
|
|
local lines = {}
|
|
local function log(msg, ...)
|
|
msg = msg:format(...)
|
|
print(msg)
|
|
|
|
table.insert(lines, 1, msg)
|
|
table.remove(lines, 10)
|
|
gui.set_text(gui.get_node("test_text"), table.concat(lines, "\n"))
|
|
end
|
|
|
|
local function get_credential_state(self, id)
|
|
log("get_credential_state %s", id)
|
|
siwa.get_credential_state(id, function(self, data)
|
|
for k,v in pairs(data) do
|
|
log("%s: %s", k, tostring(v))
|
|
end
|
|
end)
|
|
end
|
|
|
|
local function authenticate(self)
|
|
log("authenticate")
|
|
siwa.authenticate(function(self, data)
|
|
self.user_id = data.user_id
|
|
for k,v in pairs(data) do
|
|
log("%s: %s", k, tostring(v))
|
|
end
|
|
end)
|
|
end
|
|
|
|
local function is_siwa_supported()
|
|
return siwa and siwa.is_supported()
|
|
end
|
|
|
|
function init(self)
|
|
msg.post(".", "acquire_input_focus")
|
|
|
|
if is_siwa_supported() then
|
|
log("SIWA supported!")
|
|
else
|
|
log("SIWA not supported...")
|
|
end
|
|
end
|
|
|
|
function on_input(self, action_id, action)
|
|
if is_siwa_supported() then
|
|
dl:button("check", action_id, action, function()
|
|
if self.user_id then
|
|
get_credential_state(self, self.user_id)
|
|
else
|
|
log("No user id. Login first")
|
|
end
|
|
end)
|
|
|
|
dl:button("check_fail", action_id, action, function()
|
|
check_credentials_status(self, "foobar")
|
|
end)
|
|
|
|
dl:button("login", action_id, action, function()
|
|
authenticate(self)
|
|
end)
|
|
end
|
|
end
|