updated Bamboo references to Swoosh; added runtime.exs config file
This commit is contained in:
parent
721ba53c15
commit
d43daafdb7
11 changed files with 131 additions and 55 deletions
lib
shift73k
shift73k_web
|
@ -2,12 +2,19 @@ defmodule Shift73k.Accounts.UserNotifier do
|
|||
alias Shift73k.Mailer
|
||||
alias Shift73k.Mailer.UserEmail
|
||||
|
||||
def deliver(user_email, subject, body) do
|
||||
%Swoosh.Email{} = email = UserEmail.compose(user_email, subject, body)
|
||||
case Mailer.deliver(email) do
|
||||
{:ok, msg} -> {:ok, msg, email}
|
||||
err -> err
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Deliver instructions to confirm account.
|
||||
"""
|
||||
def deliver_confirmation_instructions(user, url) do
|
||||
user
|
||||
|> UserEmail.compose("Confirm Your Account", """
|
||||
deliver(user.email, "Confirmation instructions", """
|
||||
|
||||
==============================
|
||||
|
||||
|
@ -21,15 +28,13 @@ defmodule Shift73k.Accounts.UserNotifier do
|
|||
|
||||
==============================
|
||||
""")
|
||||
|> Mailer.deliver_later()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Deliver instructions to reset a user password.
|
||||
"""
|
||||
def deliver_reset_password_instructions(user, url) do
|
||||
user
|
||||
|> UserEmail.compose("Reset Your Password", """
|
||||
deliver(user.email, "Reset password instructions", """
|
||||
|
||||
==============================
|
||||
|
||||
|
@ -43,15 +48,13 @@ defmodule Shift73k.Accounts.UserNotifier do
|
|||
|
||||
==============================
|
||||
""")
|
||||
|> Mailer.deliver_later()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Deliver instructions to update a user email.
|
||||
"""
|
||||
def deliver_update_email_instructions(user, url) do
|
||||
user
|
||||
|> UserEmail.compose("Change Your E-mail", """
|
||||
deliver(user.email, "Update email instructions", """
|
||||
|
||||
==============================
|
||||
|
||||
|
@ -65,6 +68,5 @@ defmodule Shift73k.Accounts.UserNotifier do
|
|||
|
||||
==============================
|
||||
""")
|
||||
|> Mailer.deliver_later()
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
defmodule Shift73k.Mailer do
|
||||
use Bamboo.Mailer, otp_app: :shift73k
|
||||
use Swoosh.Mailer, otp_app: :shift73k
|
||||
end
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
defmodule Shift73k.Mailer.UserEmail do
|
||||
import Bamboo.Email
|
||||
import Swoosh.Email
|
||||
|
||||
@mailer_vars Application.compile_env(:shift73k, :app_global_vars,
|
||||
mailer_reply_to: "admin@example.com",
|
||||
mailer_from: {"Shift73k", "shift73k@example.com"}
|
||||
)
|
||||
|
||||
def compose(user, subject, body_text) do
|
||||
new_email()
|
||||
def compose(user_email, subject, body_text) do
|
||||
new()
|
||||
|> from(@mailer_vars[:mailer_from])
|
||||
|> to(user.email)
|
||||
|> put_header("Reply-To", @mailer_vars[:mailer_reply_to])
|
||||
|> to(user_email)
|
||||
|> header("Reply-To", @mailer_vars[:mailer_reply_to])
|
||||
|> subject(subject)
|
||||
|> text_body(body_text)
|
||||
end
|
||||
|
|
|
@ -39,11 +39,6 @@ defmodule Shift73kWeb.Endpoint do
|
|||
plug(Phoenix.Ecto.CheckRepoStatus, otp_app: :shift73k)
|
||||
end
|
||||
|
||||
plug(Phoenix.LiveDashboard.RequestLogger,
|
||||
param_key: "request_logger",
|
||||
cookie_key: "request_logger"
|
||||
)
|
||||
|
||||
plug(Plug.RequestId)
|
||||
plug(Plug.Telemetry, event_prefix: [:phoenix, :endpoint])
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ defmodule Shift73kWeb.UserLive.Registration do
|
|||
|> Accounts.register_user()
|
||||
|> case do
|
||||
{:ok, user} ->
|
||||
{:ok, %Bamboo.Email{}} =
|
||||
{:ok, _, %Swoosh.Email{} = _captured_email} =
|
||||
Accounts.deliver_user_confirmation_instructions(
|
||||
user,
|
||||
&Routes.user_confirmation_url(socket, :confirm, &1)
|
||||
|
|
|
@ -33,7 +33,7 @@ defmodule Shift73kWeb.UserManagement.FormComponent do
|
|||
defp save_user(%{assigns: %{action: :new}} = socket, user_params) do
|
||||
case Accounts.register_user(user_params) do
|
||||
{:ok, user} ->
|
||||
{:ok, %Bamboo.Email{}} =
|
||||
{:ok, _, %Swoosh.Email{} = _captured_email} =
|
||||
Accounts.deliver_user_confirmation_instructions(
|
||||
user,
|
||||
&Routes.user_confirmation_url(socket, :confirm, &1)
|
||||
|
|
|
@ -13,10 +13,6 @@ defmodule Shift73kWeb.Router do
|
|||
plug(:fetch_current_user)
|
||||
end
|
||||
|
||||
pipeline :api do
|
||||
plug(:accepts, ["json"])
|
||||
end
|
||||
|
||||
pipeline :user do
|
||||
plug(EnsureRolePlug, [:admin, :manager, :user])
|
||||
end
|
||||
|
@ -29,33 +25,24 @@ defmodule Shift73kWeb.Router do
|
|||
plug(EnsureRolePlug, :admin)
|
||||
end
|
||||
|
||||
# Enables the Swoosh mailbox preview in development.
|
||||
#
|
||||
# Note that preview only shows emails that were sent by the same
|
||||
# node running the Phoenix server.
|
||||
if Mix.env() == :dev do
|
||||
scope "/dev" do
|
||||
pipe_through :browser
|
||||
|
||||
forward "/mailbox", Plug.Swoosh.MailboxPreview
|
||||
end
|
||||
end
|
||||
|
||||
scope "/", Shift73kWeb do
|
||||
pipe_through([:browser])
|
||||
|
||||
get("/", Redirector, to: "/assign")
|
||||
end
|
||||
|
||||
# Other scopes may use custom stacks.
|
||||
# scope "/api", Shift73kWeb do
|
||||
# pipe_through :api
|
||||
# end
|
||||
|
||||
# Enables LiveDashboard only for development
|
||||
#
|
||||
# If you want to use the LiveDashboard in production, you should put
|
||||
# it behind authentication and allow only admins to access it.
|
||||
# If your application does not have an admins-only section yet,
|
||||
# you can use Plug.BasicAuth to set up some basic authentication
|
||||
# as long as you are also using SSL (which you should anyway).
|
||||
if Mix.env() in [:dev, :test] do
|
||||
import Phoenix.LiveDashboard.Router
|
||||
|
||||
scope "/" do
|
||||
pipe_through(:browser)
|
||||
live_dashboard("/dashboard", metrics: Shift73kWeb.Telemetry)
|
||||
end
|
||||
end
|
||||
|
||||
scope "/", Shift73kWeb do
|
||||
pipe_through([:browser, :redirect_if_user_is_authenticated])
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue