check if the secret is present before asking for a code

This commit is contained in:
BuckarooBanzay 2023-01-30 19:36:03 +01:00
parent 67ff44c51a
commit 4cf38c997d
2 changed files with 9 additions and 1 deletions

View file

@ -192,3 +192,11 @@ function otp.get_player_secret_b32(name)
end end
return secret_b32 return secret_b32
end end
-- returns true if the player is otp enabled _and_ set up properly
function otp.is_player_enabled(name)
local has_secret = otp.storage:get_string(name .. "_secret") ~= ""
local has_priv = minetest.check_player_privs(name, "otp_enabled")
return has_secret and has_priv
end

View file

@ -65,7 +65,7 @@ end
-- Code formspec on join for otp enabled players -- Code formspec on join for otp enabled players
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
local playername = player:get_player_name() local playername = player:get_player_name()
if minetest.check_player_privs(playername, "otp_enabled") then if otp.is_player_enabled(playername) then
minetest.log("action", "[otp] session start for player: '" .. playername .. "'") minetest.log("action", "[otp] session start for player: '" .. playername .. "'")
-- start otp session time -- start otp session time