@@ -6,21 +6,28 @@ defmodule RetWeb.Email do
6
6
app_name = AppConfig . get_cached_config_value ( "translations|en|app-name" )
7
7
app_full_name = AppConfig . get_cached_config_value ( "translations|en|app-full-name" ) || app_name
8
8
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" )
11
9
12
10
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
16
19
17
20
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
+ _ ->
20
27
"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 #{
21
28
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
24
31
25
32
email =
26
33
new_email ( )
@@ -41,12 +48,12 @@ defmodule RetWeb.Email do
41
48
end
42
49
43
50
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
+
44
53
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 )
48
55
else
49
- custom_message <> "\n \n #{ RetWeb.Endpoint . url ( ) } /? #{ URI . encode_query ( signin_args ) } "
56
+ custom_message <> "\n \n " <> magic_link
50
57
end
51
58
end
52
59
0 commit comments