plugins/mod_register.lua
changeset 3995 e504b06492c6
parent 3540 bc139431830b
child 3996 7f35b292531b
equal deleted inserted replaced
3994:42899d5efe3b 3995:e504b06492c6
    13 local usermanager_user_exists = require "core.usermanager".user_exists;
    13 local usermanager_user_exists = require "core.usermanager".user_exists;
    14 local usermanager_create_user = require "core.usermanager".create_user;
    14 local usermanager_create_user = require "core.usermanager".create_user;
    15 local usermanager_set_password = require "core.usermanager".set_password;
    15 local usermanager_set_password = require "core.usermanager".set_password;
    16 local os_time = os.time;
    16 local os_time = os.time;
    17 local nodeprep = require "util.encodings".stringprep.nodeprep;
    17 local nodeprep = require "util.encodings".stringprep.nodeprep;
       
    18 local jid_bare = require "util.jid".bare;
       
    19 
       
    20 local compat = module:get_option_boolean("registration_compat", true);
    18 
    21 
    19 module:add_feature("jabber:iq:register");
    22 module:add_feature("jabber:iq:register");
    20 
    23 
    21 module:hook("iq/self/jabber:iq:register:query", function(event)
    24 local function handle_registration_stanza(event)
    22 	local session, stanza = event.origin, event.stanza;
    25 	local session, stanza = event.origin, event.stanza;
    23 
    26 
    24 	local query = stanza.tags[1];
    27 	local query = stanza.tags[1];
    25 	if stanza.attr.type == "get" then
    28 	if stanza.attr.type == "get" then
    26 		local reply = st.reply(stanza);
    29 		local reply = st.reply(stanza);
    84 				session.send(st.error_reply(stanza, "modify", "bad-request"));
    87 				session.send(st.error_reply(stanza, "modify", "bad-request"));
    85 			end
    88 			end
    86 		end
    89 		end
    87 	end
    90 	end
    88 	return true;
    91 	return true;
    89 end);
    92 end
       
    93 
       
    94 module:hook("iq/self/jabber:iq:register:query", handle_registration_stanza);
       
    95 if compat then
       
    96 	module:hook("iq/host/jabber:iq:register:query", function (event)
       
    97 		local session, stanza = event.origin, event.stanza;
       
    98 		if session.type == "c2s" and jid_bare(stanza.attr.to) == session.host then
       
    99 			return handle_registration_stanza(event);
       
   100 		end
       
   101 	end);
       
   102 end
    90 
   103 
    91 local recent_ips = {};
   104 local recent_ips = {};
    92 local min_seconds_between_registrations = module:get_option("min_seconds_between_registrations");
   105 local min_seconds_between_registrations = module:get_option("min_seconds_between_registrations");
    93 local whitelist_only = module:get_option("whitelist_registration_only");
   106 local whitelist_only = module:get_option("whitelist_registration_only");
    94 local whitelisted_ips = module:get_option("registration_whitelist") or { "127.0.0.1" };
   107 local whitelisted_ips = module:get_option("registration_whitelist") or { "127.0.0.1" };