Software / code / prosody
Comparison
plugins/mod_register.lua @ 1859:c965b0accc7c
mod_register: Added helpful text to registration error responses.
| author | Waqas Hussain <waqas20@gmail.com> |
|---|---|
| date | Fri, 02 Oct 2009 17:07:18 +0500 |
| parent | 1858:49eef8e19a71 |
| child | 1861:e9500c4994f3 |
comparison
equal
deleted
inserted
replaced
| 1858:49eef8e19a71 | 1859:c965b0accc7c |
|---|---|
| 117 local username = query:child_with_name("username"); | 117 local username = query:child_with_name("username"); |
| 118 local password = query:child_with_name("password"); | 118 local password = query:child_with_name("password"); |
| 119 if username and password then | 119 if username and password then |
| 120 -- Check that the user is not blacklisted or registering too often | 120 -- Check that the user is not blacklisted or registering too often |
| 121 if blacklisted_ips[session.ip] or (whitelist_only and not whitelisted_ips[session.ip]) then | 121 if blacklisted_ips[session.ip] or (whitelist_only and not whitelisted_ips[session.ip]) then |
| 122 session.send(st.error_reply(stanza, "cancel", "not-acceptable")); | 122 session.send(st.error_reply(stanza, "cancel", "not-acceptable", "You are not allowed to register an account.")); |
| 123 return; | 123 return; |
| 124 elseif min_seconds_between_registrations and not whitelisted_ips[session.ip] then | 124 elseif min_seconds_between_registrations and not whitelisted_ips[session.ip] then |
| 125 if not recent_ips[session.ip] then | 125 if not recent_ips[session.ip] then |
| 126 recent_ips[session.ip] = { time = os_time(), count = 1 }; | 126 recent_ips[session.ip] = { time = os_time(), count = 1 }; |
| 127 else | 127 else |
| 128 | |
| 129 local ip = recent_ips[session.ip]; | 128 local ip = recent_ips[session.ip]; |
| 130 ip.count = ip.count + 1; | 129 ip.count = ip.count + 1; |
| 131 | 130 |
| 132 if os_time() - ip.time < min_seconds_between_registrations then | 131 if os_time() - ip.time < min_seconds_between_registrations then |
| 133 ip.time = os_time(); | 132 ip.time = os_time(); |
| 140 -- FIXME shouldn't use table.concat | 139 -- FIXME shouldn't use table.concat |
| 141 username = nodeprep(table.concat(username)); | 140 username = nodeprep(table.concat(username)); |
| 142 password = table.concat(password); | 141 password = table.concat(password); |
| 143 local host = module.host; | 142 local host = module.host; |
| 144 if not username then | 143 if not username then |
| 145 session.send(st.error_reply(stanza, "modify", "not-acceptable")); | 144 session.send(st.error_reply(stanza, "modify", "not-acceptable", "The requested username is invalid.")); |
| 146 elseif usermanager_user_exists(username, host) then | 145 elseif usermanager_user_exists(username, host) then |
| 147 session.send(st.error_reply(stanza, "cancel", "conflict")); | 146 session.send(st.error_reply(stanza, "cancel", "conflict", "The requested username already exists.")); |
| 148 else | 147 else |
| 149 if usermanager_create_user(username, password, host) then | 148 if usermanager_create_user(username, password, host) then |
| 150 session.send(st.reply(stanza)); -- user created! | 149 session.send(st.reply(stanza)); -- user created! |
| 151 module:log("info", "User account created: %s@%s", username, host); | 150 module:log("info", "User account created: %s@%s", username, host); |
| 152 module:fire_event("user-registered", { | 151 module:fire_event("user-registered", { |
| 153 username = username, host = host, source = "mod_register", | 152 username = username, host = host, source = "mod_register", |
| 154 session = session }); | 153 session = session }); |
| 155 else | 154 else |
| 156 -- TODO unable to write file, file may be locked, etc, what's the correct error? | 155 -- TODO unable to write file, file may be locked, etc, what's the correct error? |
| 157 session.send(st.error_reply(stanza, "wait", "internal-server-error")); | 156 session.send(st.error_reply(stanza, "wait", "internal-server-error", "Failed to write data to disk.")); |
| 158 end | 157 end |
| 159 end | 158 end |
| 160 else | 159 else |
| 161 session.send(st.error_reply(stanza, "modify", "not-acceptable")); | 160 session.send(st.error_reply(stanza, "modify", "not-acceptable")); |
| 162 end | 161 end |