Changeset

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 408:ee28af887507
children 410:abac17cb5032
files mod_register_url/mod_register_url.lua
diffstat 1 files changed, 10 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mod_register_url/mod_register_url.lua	Tue Aug 30 21:22:47 2011 +0000
+++ b/mod_register_url/mod_register_url.lua	Tue Aug 30 23:12:56 2011 +0000
@@ -5,6 +5,7 @@
 local st = require "util.stanza";
 
 function reg_redirect(event)
+	local stanza, origin = event.stanza, event.origin;
 	local ip_wl = module:get_option("registration_whitelist") or { "127.0.0.1" };
 	local url = module:get_option("registration_url");
 	local no_wl = module:get_option_boolean("no_registration_whitelist", false);
@@ -12,19 +13,22 @@
 
 	if not no_wl then
 		for i,ip in ipairs(ip_wl) do
-			if event.origin.ip == ip then test_ip = true; end
+			if origin.ip == ip then test_ip = true; end
 			break;
 		end
 	end
 	
-	if not test_ip and url ~= nil or no_wl and url ~= nil then
+	if stanza.attr.type == "get" then
 		local reply = st.reply(event.stanza);
-		reply:tag("query", {xmlns = "jabber:iq:register"})
+		reply:query("jabber:iq:register")
 			:tag("instructions"):text("Please visit "..url.." to register an account on this server."):up()
-			:tag("x", {xmlns = "jabber:x:oob"}):up()
-				:tag("url"):text(url):up();
-		event.origin.send(reply);
+			:tag("x", {xmlns = "jabber:x:oob"})
+				:tag("url"):text(url);
+		origin.send(reply);
 		return true;
+	else
+		origin.send(st.error_reply(stanza, "cancel", "not-authorized"))
+		return true
 	end
 end