# HG changeset patch # User Marco Cirillo # Date 1314745976 0 # Node ID df57fa689415355e84447792fbbf15eafac15562 # Parent ee28af887507f1f51da1a1bd98c59f2ff1c23166 mod_register_url: code refactor, clean, all the rest (thanks Zash ;)) diff -r ee28af887507 -r df57fa689415 mod_register_url/mod_register_url.lua --- 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