code tidy / update to new responses
parent
ea867c1293
commit
eab60b1cdb
28
auth.lua
28
auth.lua
|
@ -8,20 +8,20 @@ local has_xban2_mod = minetest.get_modpath("xban2")
|
|||
-- auth request
|
||||
local function auth_handler(auth)
|
||||
local handler = minetest.get_auth_handler()
|
||||
minetest.log("action", "[auth_proxy] auth: " .. auth.name)
|
||||
minetest.log("action", "[auth_proxy] auth: " .. auth.username)
|
||||
|
||||
local success = false
|
||||
local banned = false
|
||||
local message = ""
|
||||
|
||||
local custom_auth_success, custom_msg = auth_proxy.custom_handler(auth.name)
|
||||
local custom_auth_success, custom_msg = auth_proxy.custom_handler(auth.username)
|
||||
if not custom_auth_success and custom_msg then
|
||||
message = custom_msg
|
||||
end
|
||||
|
||||
if auth_proxy.disallow_banned_players and has_xban2_mod then
|
||||
-- check xban db
|
||||
local xbanentry = xban.find_entry(auth.name)
|
||||
local xbanentry = xban.find_entry(auth.username)
|
||||
if xbanentry and xbanentry.banned then
|
||||
banned = true
|
||||
message = "Banned!"
|
||||
|
@ -30,37 +30,29 @@ local function auth_handler(auth)
|
|||
|
||||
if not banned and custom_auth_success then
|
||||
-- check tan
|
||||
local tan = auth_proxy.tan[auth.name]
|
||||
local tan = auth_proxy.tan[auth.username]
|
||||
if tan ~= nil then
|
||||
success = tan == auth.password
|
||||
end
|
||||
|
||||
-- check auth
|
||||
if not success then
|
||||
local entry = handler.get_auth(auth.name)
|
||||
if entry and minetest.check_password_entry(auth.name, entry.password, auth.password) then
|
||||
local entry = handler.get_auth(auth.username)
|
||||
if entry and minetest.check_password_entry(auth.username, entry.password, auth.password) then
|
||||
success = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
channel.send({
|
||||
type = "auth",
|
||||
data = {
|
||||
name = auth.name,
|
||||
success = success,
|
||||
message = message
|
||||
}
|
||||
name = auth.username,
|
||||
success = success,
|
||||
message = message
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
function auth_proxy.http_init(http, url)
|
||||
channel = Channel(http, url .. "/api/minetest/channel")
|
||||
|
||||
channel.receive(function(data)
|
||||
if data.type == "auth" then
|
||||
auth_handler(data.data)
|
||||
end
|
||||
end)
|
||||
channel.receive(auth_handler)
|
||||
end
|
||||
|
|
2
init.lua
2
init.lua
|
@ -1,6 +1,6 @@
|
|||
auth_proxy = {
|
||||
disallow_banned_players = true,
|
||||
url = minetest.settings:get("auth_proxy.url"),
|
||||
url = minetest.settings:get("auth_proxy.url") or "http://127.0.0.1:8080",
|
||||
tan = {},
|
||||
custom_handler = function()
|
||||
return true
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
# The url to the auth proxy app
|
||||
auth_proxy.url (Auth proxy url) string http://127.0.0.1:8080
|
|
@ -34,7 +34,7 @@ local function Channel(http, url, cfg)
|
|||
local data = minetest.parse_json(res.data)
|
||||
|
||||
if debug then
|
||||
minetest.log("action", "[webmail-rx] " .. dump(data))
|
||||
minetest.log("action", "[channel-rx] " .. dump(data))
|
||||
end
|
||||
|
||||
if data then
|
||||
|
@ -57,7 +57,7 @@ local function Channel(http, url, cfg)
|
|||
-- POST
|
||||
|
||||
if debug then
|
||||
minetest.log("action", "[webmail-tx] " .. dump(data))
|
||||
minetest.log("action", "[channel-tx] " .. dump(data))
|
||||
end
|
||||
|
||||
http.fetch({
|
||||
|
|
Loading…
Reference in New Issue