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