Add delete_auth function

This commit is contained in:
Dorian Wouters 2016-08-23 11:59:19 +02:00
parent 5cebbaf03c
commit 4a322bb91d
No known key found for this signature in database
GPG Key ID: 6E9DA8063322434B
1 changed files with 23 additions and 0 deletions

View File

@ -217,6 +217,12 @@ do
S.privs_type, S.lastlogin_type})
thismod.create_auth_params = create_auth_params
local delete_auth_stmt = conn:prepare('DELETE FROM ' .. tables.auths.name .. ' WHERE ' ..
S.username .. '=?')
thismod.delete_auth_stmt = delete_auth_stmt
local delete_auth_params = delete_auth_stmt:bind_params({S.username_type})
thismod.delete_auth_params = delete_auth_params
local set_password_stmt = conn:prepare('UPDATE ' .. tables.auths.name .. ' SET ' .. S.password ..
'=? WHERE ' .. S.username .. '=?')
thismod.set_password_stmt = set_password_stmt
@ -237,6 +243,7 @@ do
local enumerate_auths_query = 'SELECT ' .. S.username .. ',' .. S.password .. ',' .. S.privs ..
',' .. S.lastlogin .. ' FROM ' .. tables.auths.name
thismod.enumerate_auths_query = enumerate_auths_query
thismod.auth_handler = {
get_auth = function(name)
@ -301,6 +308,22 @@ do
end
return true
end,
delete_auth = function(name)
assert(type(name) == 'string')
minetest.log('info', modname .. " deleting player '"..name.."'")
delete_auth_params:set(1, name)
local success, msg = pcall(delete_auth_stmt.exec, delete_auth_stmt)
if not success then
minetest.log('error', modname .. ": delete_auth failed: " .. msg)
return false
end
if delete_auth_stmt:affected_rows() ~= 1 then
minetest.log('error', modname .. ": delete_auth failed: affected row count is " ..
delete_auth_stmt:affected_rows() .. ", expected 1")
return false
end
return true
end,
set_password = function(name, password)
assert(type(name) == 'string')
assert(type(password) == 'string')