Software /
code /
prosody
Comparison
core/usermanager.lua @ 13169:7b6e7290265b
usermanager: Add create_user_with_role() method to atomically set initial role
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 29 Jun 2023 15:31:46 +0100 |
parent | 12993:623fbb5f9b05 |
comparison
equal
deleted
inserted
replaced
13168:536055476912 | 13169:7b6e7290265b |
---|---|
203 }); | 203 }); |
204 end | 204 end |
205 return role, err; | 205 return role, err; |
206 end | 206 end |
207 | 207 |
208 local function create_user_with_role(username, password, host, role) | |
209 local ok, err = create_user(username, nil, host); | |
210 if not ok then return ok, err; end | |
211 | |
212 local role_ok, role_err = set_user_role(username, host, role); | |
213 if not role_ok then | |
214 delete_user(username, host); | |
215 return nil, "Failed to assign role: "..role_err; | |
216 end | |
217 | |
218 if password then | |
219 local pw_ok, pw_err = set_password(username, password, host); | |
220 if not pw_ok then | |
221 return nil, "Failed to set password: "..pw_err; | |
222 end | |
223 | |
224 local enable_ok, enable_err = enable_user(username, host); | |
225 if not enable_ok and enable_err ~= "method not implemented" then | |
226 return enable_ok, "Failed to enable account: "..enable_err; | |
227 end | |
228 end | |
229 | |
230 return true; | |
231 end | |
232 | |
208 local function user_can_assume_role(user, host, role_name) | 233 local function user_can_assume_role(user, host, role_name) |
209 if host and not hosts[host] then return false; end | 234 if host and not hosts[host] then return false; end |
210 if type(user) ~= "string" then return false; end | 235 if type(user) ~= "string" then return false; end |
211 | 236 |
212 return hosts[host].authz.user_can_assume_role(user, role_name); | 237 return hosts[host].authz.user_can_assume_role(user, role_name); |
306 get_password = get_password; | 331 get_password = get_password; |
307 set_password = set_password; | 332 set_password = set_password; |
308 get_account_info = get_account_info; | 333 get_account_info = get_account_info; |
309 user_exists = user_exists; | 334 user_exists = user_exists; |
310 create_user = create_user; | 335 create_user = create_user; |
336 create_user_with_role = create_user_with_role; | |
311 delete_user = delete_user; | 337 delete_user = delete_user; |
312 user_is_enabled = user_is_enabled; | 338 user_is_enabled = user_is_enabled; |
313 enable_user = enable_user; | 339 enable_user = enable_user; |
314 disable_user = disable_user; | 340 disable_user = disable_user; |
315 users = users; | 341 users = users; |