Skip to content

Commit abb4e2c

Browse files
committed
allow to set landing_page to auto
1 parent d8f295e commit abb4e2c

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

src/mod_invites.erl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ mod_doc() ->
9494
?T("Same as top-level _`default_db`_ option, but applied to this "
9595
"module only.")}},
9696
{landing_page,
97-
#{value => "none | binary()",
98-
desc => ?T("Web address of service handling invite links. This is either a local address handled by `mod_invites` configured as a handler at `ejabberd_http` or an external service like 'easy-xmpp-invitation'. The address must be given as a template pattern with fields from the `invite` that will then get replaced accordingly. Eg.: 'https://{{ host }}:5281/invites/{{ invite.token }}' or as an external service like 'http://{{ host }}:8080/easy-xmpp-invites/#{{ invite.uri|strip_protocol }}'. This is the landing page that is being communicated when creating an invite using one of the ad-hoc commands.")}
97+
#{value => "none | auto | LandingPageURLTemplate",
98+
desc => ?T("This is the landing page that is being communicated when creating an invite using one of the ad-hoc commands, the web address of service handling invite links. This is either a local address handled by `mod_invites` configured as a handler at `ejabberd_http` or an external service like 'easy-xmpp-invitation'. The address must be given as a template pattern with fields from the `invite` that will then get replaced accordingly. Eg.: 'https://{{ host }}:5281/invites/{{ invite.token }}' or as an external service like 'http://{{ host }}:8080/easy-xmpp-invites/#{{ invite.uri|strip_protocol }}'. For convenience you can choose 'auto' here and the ejabberd_http handler will be used.")}
9999
},
100100
{max_invites,
101101
#{value => "pos_integer() | infinity",
@@ -126,9 +126,12 @@ mod_doc() ->
126126
"",
127127
"modules:",
128128
" mod_invites:",
129-
" access_create_account: register"]},
129+
" access_create_account: register"
130+
" landing_page: auto"
131+
]},
130132
{?T("If you want all your users to be able to send 'create account' "
131-
"invites, you would configure your server like this instead:"),
133+
"invites and have a proxy in front of `ejabberd_http` to not expose its port "
134+
"directly, you would configure your server like this instead:"),
132135
["acl:",
133136
" local:",
134137
" user_regexp: \"\"",
@@ -138,7 +141,8 @@ mod_doc() ->
138141
"",
139142
"modules:",
140143
" mod_invites:",
141-
" access_create_account: create_account_invite"]},
144+
" access_create_account: create_account_invite"
145+
" landing_page: https://yourhost/invites/{{ invite.token }}"]},
142146
?T("Note that the names of the access rules are just examples and "
143147
"you're free to change them.")
144148
%% TODO add example for invite page
@@ -184,7 +188,7 @@ mod_opt_type(access_create_account) ->
184188
mod_opt_type(db_type) ->
185189
econf:db_type(?MODULE);
186190
mod_opt_type(landing_page) ->
187-
econf:either(none, econf:binary("^http[s]?://"));
191+
econf:either(none, econf:binary());
188192
mod_opt_type(max_invites) ->
189193
econf:pos_int(infinity);
190194
mod_opt_type(site_name) ->

src/mod_invites_http.erl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,23 @@ landing_page(Host, Invite) ->
6363
case mod_invites_opt:landing_page(Host) of
6464
none ->
6565
<<>>;
66+
<<"auto">> ->
67+
case ejabberd_http:get_auto_url(any, mod_invites) of
68+
undefined ->
69+
?WARNING_MSG("'auto' URL configured for mod_invites but no request_handler found in your ~s listeners configuration.", [Host]),
70+
<<>>;
71+
AutoURL0 ->
72+
AutoURL = misc:expand_keyword(<<"@HOST@">>, AutoURL0, Host),
73+
render_landing_page_url(<<AutoURL/binary, "/{{ invite.token }}">>, Host, Invite)
74+
end;
6675
Tmpl ->
67-
Ctx = [{invite, invite_to_proplist(Invite)}, {host, Host}],
68-
render_url(Tmpl, Ctx)
76+
render_landing_page_url(Tmpl, Host, Invite)
6977
end.
7078

79+
render_landing_page_url(Tmpl, Host, Invite) ->
80+
Ctx = [{invite, invite_to_proplist(Invite)}, {host, Host}],
81+
render_url(Tmpl, Ctx).
82+
7183
-spec process(LocalPath::[binary()], #request{}) ->
7284
{HTTPCode::integer(), [{binary(), binary()}], Page::string()}.
7385
process([?STATIC | StaticFile], #request{host = Host} = Request) ->

test/ejabberd_SUITE_data/ejabberd.mnesia.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ define_macro:
1919
db_type: internal
2020
mod_invites:
2121
db_type: internal
22-
landing_page: "http://@HOST@:5280/invites/{{ invite.token }}" # fixme
22+
landing_page: auto
2323
mod_last:
2424
db_type: internal
2525
mod_muc:

test/ejabberd_SUITE_data/ejabberd.mysql.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ define_macro:
1818
db_type: sql
1919
mod_invites:
2020
db_type: sql
21+
landing_page: auto
2122
mod_last:
2223
db_type: sql
2324
mod_muc:

0 commit comments

Comments
 (0)