Compare commits

..

2 Commits

Author SHA1 Message Date
1276635a3e make emails more efficient
All checks were successful
continuous-integration/drone/push Build is passing
2023-04-14 19:02:06 -04:00
f00dc50215 clean up router 2023-04-14 19:01:56 -04:00
5 changed files with 29 additions and 44 deletions

View File

@ -29,33 +29,28 @@ defmodule Memex.Email do
def generate_email("welcome", user, %{"url" => url}) do
user
|> base_email(dgettext("emails", "confirm your memEx account"))
|> html_email(:confirm_email_html, %{user: user, url: url})
|> text_email(:confirm_email_text, %{user: user, url: url})
|> render_body(:confirm_email, %{user: user, url: url})
end
def generate_email("reset_password", user, %{"url" => url}) do
user
|> base_email(dgettext("emails", "reset your memEx password"))
|> html_email(:reset_password_html, %{user: user, url: url})
|> text_email(:reset_password_text, %{user: user, url: url})
|> render_body(:reset_password, %{user: user, url: url})
end
def generate_email("update_email", user, %{"url" => url}) do
user
|> base_email(dgettext("emails", "update your memEx email"))
|> html_email(:update_email_html, %{user: user, url: url})
|> text_email(:update_email_text, %{user: user, url: url})
|> render_body(:update_email, %{user: user, url: url})
end
defp html_email(email, atom, assigns) do
heex = apply(EmailHTML, atom, [assigns])
html = render_to_string(Layouts, "email_html", "html", email: email, inner_content: heex)
email |> html_body(html)
end
defp render_body(email, template, assigns) do
html_heex = apply(EmailHTML, String.to_existing_atom("#{template}_html"), [assigns])
html = render_to_string(Layouts, "email_html", "html", email: email, inner_content: html_heex)
defp text_email(email, atom, assigns) do
heex = apply(EmailHTML, atom, [assigns])
text = render_to_string(Layouts, "email_text", "text", email: email, inner_content: heex)
email |> text_body(text)
text_heex = apply(EmailHTML, String.to_existing_atom("#{template}_text"), [assigns])
text = render_to_string(Layouts, "email_text", "text", email: email, inner_content: text_heex)
email |> html_body(html) |> text_body(text)
end
end

View File

@ -22,8 +22,6 @@ defmodule MemexWeb.Router do
plug :accepts, ["json"]
end
## Authentication routes
scope "/", MemexWeb do
pipe_through [:browser, :redirect_if_user_is_authenticated]
@ -40,6 +38,12 @@ defmodule MemexWeb.Router do
scope "/", MemexWeb do
pipe_through [:browser, :require_authenticated_user]
get "/users/settings", UserSettingsController, :edit
put "/users/settings", UserSettingsController, :update
delete "/users/settings/:id", UserSettingsController, :delete
get "/users/settings/confirm_email/:token", UserSettingsController, :confirm_email
get "/export/:mode", ExportController, :export
live_session :default, on_mount: [{MemexWeb.UserAuth, :ensure_authenticated}] do
live "/notes/new", NoteLive.Index, :new
live "/notes/:slug/edit", NoteLive.Index, :edit
@ -55,17 +59,16 @@ defmodule MemexWeb.Router do
live "/pipeline/:slug/add_step", PipelineLive.Show, :add_step
live "/pipeline/:slug/:step_id", PipelineLive.Show, :edit_step
end
get "/users/settings", UserSettingsController, :edit
put "/users/settings", UserSettingsController, :update
delete "/users/settings/:id", UserSettingsController, :delete
get "/users/settings/confirm_email/:token", UserSettingsController, :confirm_email
get "/export/:mode", ExportController, :export
end
scope "/", MemexWeb do
pipe_through [:browser]
delete "/users/log_out", UserSessionController, :delete
get "/users/confirm", UserConfirmationController, :new
post "/users/confirm", UserConfirmationController, :create
get "/users/confirm/:token", UserConfirmationController, :confirm
live_session :public, on_mount: [{MemexWeb.UserAuth, :mount_current_user}] do
live "/", HomeLive
live "/faq", FaqLive
@ -87,6 +90,8 @@ defmodule MemexWeb.Router do
scope "/", MemexWeb do
pipe_through [:browser, :require_authenticated_user, :require_admin]
live_dashboard "/dashboard", metrics: MemexWeb.Telemetry, ecto_repos: [Memex.Repo]
live_session :admin, on_mount: [{MemexWeb.UserAuth, :ensure_admin}] do
live "/invites", InviteLive.Index, :index
live "/invites/new", InviteLive.Index, :new
@ -94,21 +99,6 @@ defmodule MemexWeb.Router do
end
end
scope "/", MemexWeb do
pipe_through [:browser, :require_authenticated_user, :require_admin]
live_dashboard "/dashboard", metrics: MemexWeb.Telemetry, ecto_repos: [Memex.Repo]
end
scope "/", MemexWeb do
pipe_through [:browser]
delete "/users/log_out", UserSessionController, :delete
get "/users/confirm", UserConfirmationController, :new
post "/users/confirm", UserConfirmationController, :create
get "/users/confirm/:token", UserConfirmationController, :confirm
end
# Enables the Swoosh mailbox preview in development.
#
# Note that preview only shows emails that were sent by the same

View File

@ -71,7 +71,7 @@ msgstr ""
msgid "confirm your memEx account"
msgstr ""
#: lib/memex/accounts/email.ex:38
#: lib/memex/accounts/email.ex:37
#, elixir-autogen, elixir-format, fuzzy
msgid "reset your memEx password"
msgstr ""
@ -86,7 +86,7 @@ msgstr ""
msgid "this email was sent from memEx at %{url}"
msgstr ""
#: lib/memex/accounts/email.ex:45
#: lib/memex/accounts/email.ex:43
#, elixir-autogen, elixir-format, fuzzy
msgid "update your memEx email"
msgstr ""

View File

@ -71,7 +71,7 @@ msgstr ""
msgid "confirm your memEx account"
msgstr ""
#: lib/memex/accounts/email.ex:38
#: lib/memex/accounts/email.ex:37
#, elixir-autogen, elixir-format
msgid "reset your memEx password"
msgstr ""
@ -86,7 +86,7 @@ msgstr ""
msgid "this email was sent from memEx at %{url}"
msgstr ""
#: lib/memex/accounts/email.ex:45
#: lib/memex/accounts/email.ex:43
#, elixir-autogen, elixir-format
msgid "update your memEx email"
msgstr ""

View File

@ -72,7 +72,7 @@ msgstr ""
msgid "confirm your memEx account"
msgstr ""
#: lib/memex/accounts/email.ex:38
#: lib/memex/accounts/email.ex:37
#, elixir-autogen, elixir-format, fuzzy
msgid "reset your memEx password"
msgstr ""
@ -87,7 +87,7 @@ msgstr ""
msgid "this email was sent from memEx at %{url}"
msgstr ""
#: lib/memex/accounts/email.ex:45
#: lib/memex/accounts/email.ex:43
#, elixir-autogen, elixir-format, fuzzy
msgid "update your memEx email"
msgstr ""