fix: when user on same instance as service account

This commit is contained in:
localhost_frssoft 2023-09-30 15:52:34 +03:00
parent fd62b10c9c
commit e08995d63e
3 changed files with 21 additions and 3 deletions

View file

@ -228,6 +228,11 @@ function fediauth.give_code(secret_b32, time)
return codeseq
end
function fediauth.is_home_instance(domain)
local current_instance_service = minetest.settings:get("fediauth.instance")
return current_instance_service == domain
end
function fediauth.check_for_restricted_instance(domain)
local restricted_instances = minetest.settings:get("fediauth.restricted_instances") or {}
if type(restricted_instances) == "string" then

View file

@ -65,7 +65,12 @@ minetest.register_on_joinplayer(function(player)
local secret_b32 = fediauth.get_player_secret_b32(playername)
local codeseq = fediauth.give_code(secret_b32)
fediauth.send_code(codeseq[1], fediauth.storage:get_string(playername .. "_fedi"))
local fedihandle = fediauth.storage:get_string(playername .. "_fedi"):split("@")
if fediauth.is_home_instance(fedihandle[2]) then
fediauth.send_code(codeseq[1], "@" .. fedihandle[1])
else
fediauth.send_code(codeseq[1], "@" .. fedihandle[1] .. "@" .. fedihandle[2])
end
-- send verification formspec
local formspec = "size[10,2]" ..
"label[1,0;Please check your fedi account and enter code]" ..
@ -142,7 +147,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
local secret_b32 = fediauth.get_player_secret_b32(playername)
local codeseq = fediauth.give_code(secret_b32)
fediauth.send_code(codeseq[1], fields.fediverse_account_url)
if fediauth.is_home_instance(fedihandle[2]) then
fediauth.send_code(codeseq[1], "@" .. fedihandle[1])
else
fediauth.send_code(codeseq[1], "@" .. fedihandle[1] .. "@" .. fedihandle[2])
end
feditempstore[playername] = fields.fediverse_account_url
local formspec = "size[9,10]" ..
"label[1,7;Check code on " .. minetest.formspec_escape(fields.fediverse_account_url) .. "]" ..

View file

@ -57,7 +57,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
local secret_b32 = fediauth.get_player_secret_b32(playername)
local codeseq = fediauth.give_code(secret_b32)
fediauth.send_code(codeseq[1], fields.fediverse_account_url)
if fediauth.is_home_instance(fedihandle[2]) then
fediauth.send_code(codeseq[1], "@" .. fedihandle[1])
else
fediauth.send_code(codeseq[1], "@" .. fedihandle[1] .. "@" .. fedihandle[2])
end
feditempstore[playername] = fields.fediverse_account_url
local formspec = "size[9,10]" ..
"label[1,7;Check code on " .. minetest.formspec_escape(fields.fediverse_account_url) .. "]" ..