Skip to content

Commit 52e4d7c

Browse files
committed
removed from config.toml + add with statement
1 parent bb7cf47 commit 52e4d7c

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

habitat/config/config.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,6 @@ server = {{ toToml cfg.email.server }}
242242
port = {{ toToml cfg.email.port }}
243243
username = {{ toToml cfg.email.username }}
244244
password = {{ toToml cfg.email.password }}
245-
custom_email_subject = {{ toToml cfg.email.custom_email_subject }}
246-
custom_email_message = {{ toToml cfg.email.custom_email_message }}
247245

248246
[ret."Elixir.Ret.Support"]
249247
slack_webhook_url = "{{ cfg.support.slack_webhook_url }}"

lib/ret_web/email.ex

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,28 @@ defmodule RetWeb.Email do
66
app_name = AppConfig.get_cached_config_value("translations|en|app-name")
77
app_full_name = AppConfig.get_cached_config_value("translations|en|app-full-name") || app_name
88
admin_email = Application.get_env(:ret, Ret.Account)[:admin_email]
9-
custom_login_subject = AppConfig.get_cached_config_value("auth|login_subject")
10-
custom_login_body = AppConfig.get_cached_config_value("auth|login_body")
119

1210
email_subject =
13-
if string_is_nil_or_empty(custom_login_subject),
14-
do: "Your #{app_name} Sign-In Link",
15-
else: custom_login_subject
11+
with custom_login_subject <-
12+
AppConfig.get_config_value("auth|login_subject"),
13+
false <- string_is_nil_or_empty(custom_login_subject) do
14+
custom_login_subject
15+
else
16+
_ ->
17+
"Your #{app_name} Sign-In Link"
18+
end
1619

1720
email_body =
18-
if string_is_nil_or_empty(custom_login_body),
19-
do:
21+
with custom_login_body <-
22+
AppConfig.get_cached_config_value("auth|login_body"),
23+
false <- string_is_nil_or_empty(custom_login_body) do
24+
add_magic_link_to_custom_login_body(custom_login_body, signin_args)
25+
else
26+
_ ->
2027
"To sign-in to #{app_name}, please visit the link below. If you did not make this request, please ignore this e-mail.\n\n #{
2128
RetWeb.Endpoint.url()
22-
}/?#{URI.encode_query(signin_args)}",
23-
else: add_magic_link_to_custom_login_body(custom_login_body, signin_args)
29+
}/?#{URI.encode_query(signin_args)}"
30+
end
2431

2532
email =
2633
new_email()
@@ -41,12 +48,12 @@ defmodule RetWeb.Email do
4148
end
4249

4350
defp add_magic_link_to_custom_login_body(custom_message, signin_args) do
51+
magic_link = "#{RetWeb.Endpoint.url()}/?#{URI.encode_query(signin_args)}"
52+
4453
if Regex.match?(~r/{{ link }}/, custom_message) do
45-
Regex.replace(~r/{{ link }}/, custom_message, "#{RetWeb.Endpoint.url()}/?#{URI.encode_query(signin_args)}",
46-
global: false
47-
)
54+
Regex.replace(~r/{{ link }}/, custom_message, magic_link, global: false)
4855
else
49-
custom_message <> "\n\n #{RetWeb.Endpoint.url()}/?#{URI.encode_query(signin_args)}"
56+
custom_message <> "\n\n" <> magic_link
5057
end
5158
end
5259

0 commit comments

Comments
 (0)