comparison mod_register_url/mod_register_url.lua @ 409:df57fa689415

mod_register_url: code refactor, clean, all the rest (thanks Zash ;))
author Marco Cirillo <maranda@lightwitch.org>
date Tue, 30 Aug 2011 23:12:56 +0000
parents ee28af887507
children
comparison
equal deleted inserted replaced
408:ee28af887507 409:df57fa689415
3 -- Redirects IP addresses not in the whitelist to a web page to complete the registration. 3 -- Redirects IP addresses not in the whitelist to a web page to complete the registration.
4 4
5 local st = require "util.stanza"; 5 local st = require "util.stanza";
6 6
7 function reg_redirect(event) 7 function reg_redirect(event)
8 local stanza, origin = event.stanza, event.origin;
8 local ip_wl = module:get_option("registration_whitelist") or { "127.0.0.1" }; 9 local ip_wl = module:get_option("registration_whitelist") or { "127.0.0.1" };
9 local url = module:get_option("registration_url"); 10 local url = module:get_option("registration_url");
10 local no_wl = module:get_option_boolean("no_registration_whitelist", false); 11 local no_wl = module:get_option_boolean("no_registration_whitelist", false);
11 local test_ip = false; 12 local test_ip = false;
12 13
13 if not no_wl then 14 if not no_wl then
14 for i,ip in ipairs(ip_wl) do 15 for i,ip in ipairs(ip_wl) do
15 if event.origin.ip == ip then test_ip = true; end 16 if origin.ip == ip then test_ip = true; end
16 break; 17 break;
17 end 18 end
18 end 19 end
19 20
20 if not test_ip and url ~= nil or no_wl and url ~= nil then 21 if stanza.attr.type == "get" then
21 local reply = st.reply(event.stanza); 22 local reply = st.reply(event.stanza);
22 reply:tag("query", {xmlns = "jabber:iq:register"}) 23 reply:query("jabber:iq:register")
23 :tag("instructions"):text("Please visit "..url.." to register an account on this server."):up() 24 :tag("instructions"):text("Please visit "..url.." to register an account on this server."):up()
24 :tag("x", {xmlns = "jabber:x:oob"}):up() 25 :tag("x", {xmlns = "jabber:x:oob"})
25 :tag("url"):text(url):up(); 26 :tag("url"):text(url);
26 event.origin.send(reply); 27 origin.send(reply);
27 return true; 28 return true;
29 else
30 origin.send(st.error_reply(stanza, "cancel", "not-authorized"))
31 return true
28 end 32 end
29 end 33 end
30 34
31 module:hook("stanza/iq/jabber:iq:register:query", reg_redirect, 10); 35 module:hook("stanza/iq/jabber:iq:register:query", reg_redirect, 10);