mirror of
https://git.phreedom.club/localhost_frssoft/fediauth.git
synced 2024-11-25 09:21:29 +00:00
qr formspec
This commit is contained in:
parent
10e82093b6
commit
14464395b5
|
@ -141,16 +141,13 @@ function otp.generate_totp(key, unix_time)
|
||||||
end
|
end
|
||||||
|
|
||||||
function otp.create_qr_png(data)
|
function otp.create_qr_png(data)
|
||||||
local pixel_size = 3
|
local height = #data
|
||||||
local height = pixel_size * #data
|
|
||||||
local width = height
|
local width = height
|
||||||
|
|
||||||
local png_data = {}
|
local png_data = {}
|
||||||
for _, row in ipairs(data) do
|
for _, row in ipairs(data) do
|
||||||
assert(#row == #data)
|
assert(#row == #data)
|
||||||
for _=1,pixel_size do
|
|
||||||
for _, v in ipairs(row) do
|
for _, v in ipairs(row) do
|
||||||
for _=1,pixel_size do
|
|
||||||
if v > 0 then
|
if v > 0 then
|
||||||
table.insert(png_data, 0xFF000000)
|
table.insert(png_data, 0xFF000000)
|
||||||
else
|
else
|
||||||
|
@ -158,8 +155,6 @@ function otp.create_qr_png(data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
assert(#png_data == width*height)
|
assert(#png_data == width*height)
|
||||||
|
|
||||||
return minetest.encode_png(width, height, png_data, 2)
|
return minetest.encode_png(width, height, png_data, 2)
|
||||||
|
|
15
init.lua
15
init.lua
|
@ -16,3 +16,18 @@ dofile(MP.."/functions.lua")
|
||||||
if minetest.get_modpath("mtt") and mtt.enabled then
|
if minetest.get_modpath("mtt") and mtt.enabled then
|
||||||
dofile(MP.."/functions.spec.lua")
|
dofile(MP.."/functions.spec.lua")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
minetest.register_chatcommand("test", {
|
||||||
|
func = function(name)
|
||||||
|
local url = "otpauth://totp/abc:myaccount?algorithm=SHA1&digits=6&issuer=abc&period=30&"
|
||||||
|
.. "secret=N6JGKMEKU2E6HQMLLNMJKBRRGVQ2ZKV7"
|
||||||
|
|
||||||
|
local ok, code = otp.qrcode(url)
|
||||||
|
assert(ok)
|
||||||
|
local png = otp.create_qr_png(code)
|
||||||
|
local formspec = "size[10,10]" ..
|
||||||
|
"image[1,0.6;5,5;^[png:" .. minetest.encode_base64(png) .. "]"
|
||||||
|
|
||||||
|
minetest.show_formspec(name, "TEST", formspec)
|
||||||
|
end
|
||||||
|
})
|
Loading…
Reference in a new issue