Comparison

core/usermanager.lua @ 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
parent 12683:75f0c69eba71
child 12906:e282c92ded0e
comparison
equal deleted inserted replaced
12904:4c321d889fdc 12905:8473a516004f
133 if not ok then return nil, err; end 133 if not ok then return nil, err; end
134 prosody.events.fire_event("user-deleted", { username = username, host = host }); 134 prosody.events.fire_event("user-deleted", { username = username, host = host });
135 return storagemanager.purge(username, host); 135 return storagemanager.purge(username, host);
136 end 136 end
137 137
138 local function user_is_enabled(username, host)
139 local method = hosts[host].users.is_enabled;
140 if method then return method(username); end
141
142 -- Fallback
143 local info, err = get_account_info(username, host);
144 if info and info.enabled ~= nil then
145 return info.enabled;
146 elseif err ~= "method-not-implemented" then
147 -- Storage issues etetc
148 return info, err;
149 end
150
151 -- API unsupported implies users are always enabled
152 return true;
153 end
154
155 local function enable_user(username, host)
156 local method = hosts[host].users.enable;
157 if not method then return nil, "method-not-supported"; end
158 return method(username);
159 end
160
161 local function disable_user(username, host)
162 local method = hosts[host].users.disable;
163 if not method then return nil, "method-not-supported"; end
164 return method(username);
165 end
166
138 local function users(host) 167 local function users(host)
139 return hosts[host].users.users(); 168 return hosts[host].users.users();
140 end 169 end
141 170
142 local function get_sasl_handler(host, session) 171 local function get_sasl_handler(host, session)
264 set_password = set_password; 293 set_password = set_password;
265 get_account_info = get_account_info; 294 get_account_info = get_account_info;
266 user_exists = user_exists; 295 user_exists = user_exists;
267 create_user = create_user; 296 create_user = create_user;
268 delete_user = delete_user; 297 delete_user = delete_user;
298 user_is_enabled = user_is_enabled;
299 enable_user = enable_user;
300 disable_user = disable_user;
269 users = users; 301 users = users;
270 get_sasl_handler = get_sasl_handler; 302 get_sasl_handler = get_sasl_handler;
271 get_provider = get_provider; 303 get_provider = get_provider;
272 get_user_role = get_user_role; 304 get_user_role = get_user_role;
273 set_user_role = set_user_role; 305 set_user_role = set_user_role;