From 7566d254e4e6215c5197cefbfc7dbab1982ef904 Mon Sep 17 00:00:00 2001 From: Evgeniy Khramtsov Date: Fri, 1 Sep 2017 12:14:01 +0300 Subject: [PATCH] Introduce 'redirect_url' option for mod_register The option enables registration redirection as described in https://xmpp.org/extensions/xep-0077.html#redirect Fixes #1976 --- src/mod_register.erl | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/mod_register.erl b/src/mod_register.erl index d6227f00f..61975e8a1 100644 --- a/src/mod_register.erl +++ b/src/mod_register.erl @@ -210,7 +210,14 @@ process_iq(#iq{type = get, from = From, to = To, id = ID, lang = Lang} = IQ, Instr = translate:translate( Lang, <<"Choose a username and password to register " "with this server">>), - if IsCaptchaEnabled and not IsRegistered -> + URL = gen_mod:get_module_opt(Server, ?MODULE, redirect_url, <<"">>), + if (URL /= <<"">>) and not IsRegistered -> + Txt = translate:translate(Lang, <<"To register, visit ~s">>), + Desc = str:format(Txt, [URL]), + xmpp:make_iq_result( + IQ, #register{instructions = Desc, + sub_els = [#oob_x{url = URL}]}); + IsCaptchaEnabled and not IsRegistered -> TopInstr = translate:translate( Lang, <<"You need a client that supports x:data " "and CAPTCHA to register">>), @@ -614,9 +621,11 @@ mod_opt_type({welcome_message, subject}) -> fun iolist_to_binary/1; mod_opt_type({welcome_message, body}) -> fun iolist_to_binary/1; +mod_opt_type(redirect_url) -> + fun iolist_to_binary/1; mod_opt_type(_) -> [access, access_from, access_remove, captcha_protected, ip_access, - iqdisc, password_strength, registration_watchers, + iqdisc, password_strength, registration_watchers, redirect_url, {welcome_message, subject}, {welcome_message, body}]. -spec opt_type(registration_timeout) -> fun((timeout()) -> timeout());