65 lines
2.3 KiB
Lua
65 lines
2.3 KiB
Lua
local S = minetest.get_translator("site_connect")
|
|
site_connect = {}
|
|
site_connect.modpath = minetest.get_modpath("site_connect")
|
|
dofile(site_connect.modpath.."/hash.lua")
|
|
|
|
local pass = {}
|
|
|
|
--[[
|
|
formspec_version[6]
|
|
size[8,5]
|
|
button[4.4,3.7;3,0.8;save;Сохранить]
|
|
field[0.5,2.2;5,0.8;pass;Пароль;]
|
|
label[0.5,1.2;Введите пароль\, для авторизации на сайте]
|
|
label[0.5,0.6;Внимание! Сайт в процесе разработки]
|
|
label[0.5,3.4;Сообщение]
|
|
]]
|
|
local function get_formspec_main(name)
|
|
local formspec = {
|
|
"size[8,5]",
|
|
"label[0.2,0.4;".. S("Attention! The site is under development.") .."]",
|
|
"label[0.2,1;" .. S("Enter your password to log in to the site") .. "]",
|
|
"field[0.5,2.2;5,0.8;pass;".. S("Password") ..";]",
|
|
"button[4.3,3.4;3,0.8;save;".. S("Save") .."]",
|
|
}
|
|
if pass[name] == 'empty' then
|
|
table.insert(formspec, 'label[0.2,3.4;'.. S("The password field must not be empty.") ..']')
|
|
end
|
|
if pass[name] == 'success' then
|
|
table.insert(formspec, 'label[0.2,3.4;'.. S("Password saved") ..']')
|
|
end
|
|
|
|
return table.concat(formspec, "")
|
|
end
|
|
|
|
minetest.register_chatcommand("set_site_pass", {
|
|
description = S("Setting up an authorization password for the site"),
|
|
privs = { interact = true },
|
|
func = function(name)
|
|
minetest.show_formspec(name, "site_connect:set_password", get_formspec_main(name))
|
|
end
|
|
})
|
|
|
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|
local name = player:get_player_name()
|
|
|
|
if formname ~= "site_connect:set_password" then
|
|
return
|
|
end
|
|
|
|
if fields.save then
|
|
local fpass = string.gsub(fields.pass, "%s+", "")
|
|
|
|
if fpass == '' then
|
|
--minetest.chat_send_all('Поле пароля не должно быть пустым')
|
|
pass[name] = 'empty'
|
|
minetest.show_formspec(name, "site_connect:set_password", get_formspec_main(name))
|
|
return
|
|
end
|
|
pass[name] = 'success'
|
|
local save_meta = player:get_meta()
|
|
save_meta:set_string("site_connect:password", sha256(fpass))
|
|
minetest.show_formspec(name, "site_connect:set_password", get_formspec_main(name))
|
|
--minetest.chat_send_all(sha256(fields.pass))
|
|
end
|
|
end) |