Software /
code /
prosody
Comparison
plugins/mod_admin_shell.lua @ 12991:6d7e3d5463d8
mod_admin_shell: Simplify user creation when no role given
Idea here is to prevent a user from being created with the default role
if a different role was given, but that dance wouldn't be needed if no
role is provided.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 26 Mar 2023 16:45:23 +0200 |
parent | 12977:74b9e05af71e |
child | 12992:651813914151 |
comparison
equal
deleted
inserted
replaced
12990:939049732317 | 12991:6d7e3d5463d8 |
---|---|
1514 if not prosody.hosts[host] then | 1514 if not prosody.hosts[host] then |
1515 return nil, "No such host: "..host; | 1515 return nil, "No such host: "..host; |
1516 elseif um.user_exists(username, host) then | 1516 elseif um.user_exists(username, host) then |
1517 return nil, "User exists"; | 1517 return nil, "User exists"; |
1518 end | 1518 end |
1519 local ok, err = um.create_user(username, nil, host); | |
1520 if not ok then | |
1521 return nil, "Could not create user: "..err; | |
1522 end | |
1523 | 1519 |
1524 if role then | 1520 if role then |
1521 local ok, err = um.create_user(username, nil, host); | |
1522 if not ok then | |
1523 return nil, "Could not create user: "..err; | |
1524 end | |
1525 | |
1525 local role_ok, rerr = um.set_user_role(jid, host, role); | 1526 local role_ok, rerr = um.set_user_role(jid, host, role); |
1526 if not role_ok then | 1527 if not role_ok then |
1527 return nil, "Could not set role: " .. tostring(rerr); | 1528 return nil, "Could not set role: " .. tostring(rerr); |
1528 end | 1529 end |
1529 end | 1530 |
1530 | 1531 if password then |
1531 local ok, err = um.set_password(username, password, host, nil); | 1532 local ok, err = um.set_password(username, password, host, nil); |
1532 if not ok then | 1533 if not ok then |
1533 return nil, "Could not set password for user: "..err; | 1534 return nil, "Could not set password for user: "..err; |
1535 end | |
1536 end | |
1537 else | |
1538 local ok, err = um.create_user(username, password, host); | |
1539 if not ok then | |
1540 return nil, "Could not create user: "..err; | |
1541 end | |
1534 end | 1542 end |
1535 | 1543 |
1536 return true, "User created"; | 1544 return true, "User created"; |
1537 end | 1545 end |
1538 | 1546 |