Compare commits

..

No commits in common. "1276635a3ea7a3877904023d4acb0e3bb842b457" and "35de8a6395a7b86b5f18f2ebcb0422d34d4d7224" have entirely different histories.

5 changed files with 44 additions and 29 deletions

View File

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

View File

@ -22,6 +22,8 @@ defmodule MemexWeb.Router do
plug :accepts, ["json"] plug :accepts, ["json"]
end end
## Authentication routes
scope "/", MemexWeb do scope "/", MemexWeb do
pipe_through [:browser, :redirect_if_user_is_authenticated] pipe_through [:browser, :redirect_if_user_is_authenticated]
@ -38,12 +40,6 @@ defmodule MemexWeb.Router do
scope "/", MemexWeb do scope "/", MemexWeb do
pipe_through [:browser, :require_authenticated_user] 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_session :default, on_mount: [{MemexWeb.UserAuth, :ensure_authenticated}] do
live "/notes/new", NoteLive.Index, :new live "/notes/new", NoteLive.Index, :new
live "/notes/:slug/edit", NoteLive.Index, :edit live "/notes/:slug/edit", NoteLive.Index, :edit
@ -59,16 +55,17 @@ defmodule MemexWeb.Router do
live "/pipeline/:slug/add_step", PipelineLive.Show, :add_step live "/pipeline/:slug/add_step", PipelineLive.Show, :add_step
live "/pipeline/:slug/:step_id", PipelineLive.Show, :edit_step live "/pipeline/:slug/:step_id", PipelineLive.Show, :edit_step
end 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 end
scope "/", MemexWeb do scope "/", MemexWeb do
pipe_through [:browser] 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_session :public, on_mount: [{MemexWeb.UserAuth, :mount_current_user}] do
live "/", HomeLive live "/", HomeLive
live "/faq", FaqLive live "/faq", FaqLive
@ -90,8 +87,6 @@ defmodule MemexWeb.Router do
scope "/", MemexWeb do scope "/", MemexWeb do
pipe_through [:browser, :require_authenticated_user, :require_admin] 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_session :admin, on_mount: [{MemexWeb.UserAuth, :ensure_admin}] do
live "/invites", InviteLive.Index, :index live "/invites", InviteLive.Index, :index
live "/invites/new", InviteLive.Index, :new live "/invites/new", InviteLive.Index, :new
@ -99,6 +94,21 @@ defmodule MemexWeb.Router do
end end
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. # Enables the Swoosh mailbox preview in development.
# #
# Note that preview only shows emails that were sent by the same # Note that preview only shows emails that were sent by the same

View File

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

View File

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

View File

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