Changeset

12905:8473a516004f

core.usermanager: Add methods for enabling and disabling users Calling into the auth module, where available.
author Kim Alvefur <zash@zash.se>
date Thu, 23 Feb 2023 16:24:41 +0100
parents 12904:4c321d889fdc
children 12906:e282c92ded0e
files core/usermanager.lua teal-src/core/usermanager.d.tl
diffstat 2 files changed, 35 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/core/usermanager.lua	Thu Feb 23 16:04:02 2023 +0100
+++ b/core/usermanager.lua	Thu Feb 23 16:24:41 2023 +0100
@@ -135,6 +135,35 @@
 	return storagemanager.purge(username, host);
 end
 
+local function user_is_enabled(username, host)
+	local method = hosts[host].users.is_enabled;
+	if method then return method(username); end
+
+	-- Fallback
+	local info, err = get_account_info(username, host);
+	if info and info.enabled ~= nil then
+		return info.enabled;
+	elseif err ~= "method-not-implemented" then
+		-- Storage issues etetc
+		return info, err;
+	end
+
+	-- API unsupported implies users are always enabled
+	return true;
+end
+
+local function enable_user(username, host)
+	local method = hosts[host].users.enable;
+	if not method then return nil, "method-not-supported"; end
+	return method(username);
+end
+
+local function disable_user(username, host)
+	local method = hosts[host].users.disable;
+	if not method then return nil, "method-not-supported"; end
+	return method(username);
+end
+
 local function users(host)
 	return hosts[host].users.users();
 end
@@ -266,6 +295,9 @@
 	user_exists = user_exists;
 	create_user = create_user;
 	delete_user = delete_user;
+	user_is_enabled = user_is_enabled;
+	enable_user = enable_user;
+	disable_user = disable_user;
 	users = users;
 	get_sasl_handler = get_sasl_handler;
 	get_provider = get_provider;
--- a/teal-src/core/usermanager.d.tl	Thu Feb 23 16:04:02 2023 +0100
+++ b/teal-src/core/usermanager.d.tl	Thu Feb 23 16:24:41 2023 +0100
@@ -18,6 +18,9 @@
 	user_exists : function (username : string, host : string) : boolean
 	create_user : function (username : string, password : string, host : string) : boolean, string
 	delete_user : function (username : string, host : string) : boolean, string
+	user_is_enabled : function (username : string, host : string) : boolean, string
+	enable_user : function (username : string, host : string) : boolean, string
+	disable_user : function (username : string, host : string) : boolean, string
 	users : function (host : string) : function () : string
 
 	-- Roles