plugins/mod_register.lua
changeset 7920 1ea3a8dc7dd5
parent 7819 2624f4ee34a2
parent 7919 72b6d5ab4137
child 8072 8f5f197b139d
equal deleted inserted replaced
7918:e3d3ebd417f4 7920:1ea3a8dc7dd5
    19 local new_cache = require "util.cache".new;
    19 local new_cache = require "util.cache".new;
    20 
    20 
    21 local compat = module:get_option_boolean("registration_compat", true);
    21 local compat = module:get_option_boolean("registration_compat", true);
    22 local allow_registration = module:get_option_boolean("allow_registration", false);
    22 local allow_registration = module:get_option_boolean("allow_registration", false);
    23 local additional_fields = module:get_option("additional_registration_fields", {});
    23 local additional_fields = module:get_option("additional_registration_fields", {});
       
    24 local require_encryption = module:get_option("c2s_require_encryption") or module:get_option("require_encryption");
    24 
    25 
    25 local account_details = module:open_store("account_details");
    26 local account_details = module:open_store("account_details");
    26 
    27 
    27 local field_map = {
    28 local field_map = {
    28 	username = { name = "username", type = "text-single", label = "Username", required = true };
    29 	username = { name = "username", type = "text-single", label = "Username", required = true };
    81 local register_stream_feature = st.stanza("register", {xmlns="http://jabber.org/features/iq-register"}):up();
    82 local register_stream_feature = st.stanza("register", {xmlns="http://jabber.org/features/iq-register"}):up();
    82 module:hook("stream-features", function(event)
    83 module:hook("stream-features", function(event)
    83 	local session, features = event.origin, event.features;
    84 	local session, features = event.origin, event.features;
    84 
    85 
    85 	-- Advertise registration to unauthorized clients only.
    86 	-- Advertise registration to unauthorized clients only.
    86 	if not(allow_registration) or session.type ~= "c2s_unauthed" then
    87 	if not(allow_registration) or session.type ~= "c2s_unauthed" or (require_encryption and not session.secure) then
    87 		return
    88 		return
    88 	end
    89 	end
    89 
    90 
    90 	features:add_child(register_stream_feature);
    91 	features:add_child(register_stream_feature);
    91 end);
    92 end);
   211 	local log = session.log or module._log;
   212 	local log = session.log or module._log;
   212 
   213 
   213 	if not(allow_registration) or session.type ~= "c2s_unauthed" then
   214 	if not(allow_registration) or session.type ~= "c2s_unauthed" then
   214 		log("debug", "Attempted registration when disabled or already authenticated");
   215 		log("debug", "Attempted registration when disabled or already authenticated");
   215 		session.send(st.error_reply(stanza, "cancel", "service-unavailable"));
   216 		session.send(st.error_reply(stanza, "cancel", "service-unavailable"));
       
   217 	elseif require_encryption and not session.secure then
       
   218 		session.send(st.error_reply(stanza, "modify", "policy-violation", "Encryption is required"));
   216 	else
   219 	else
   217 		local query = stanza.tags[1];
   220 		local query = stanza.tags[1];
   218 		if stanza.attr.type == "get" then
   221 		if stanza.attr.type == "get" then
   219 			local reply = st.reply(stanza);
   222 			local reply = st.reply(stanza);
   220 			reply:add_child(registration_query);
   223 			reply:add_child(registration_query);