Skip to content

Instantly share code, notes, and snippets.

@shankardevy
Last active August 18, 2017 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shankardevy/45cfe36cfbc5cb031be95e8d1a12e149 to your computer and use it in GitHub Desktop.
Save shankardevy/45cfe36cfbc5cb031be95e8d1a12e149 to your computer and use it in GitHub Desktop.
defmodule MangoWeb.Plugs.AuthenticateCustomer do
import Plug.Conn
import Phoenix.Controller, only: [redirect: 2, put_flash: 3]
def init(opts), do: nil
def call(conn, _opts) do
case conn.assigns[:current_customer] do
nil ->
conn
|> put_session(:intending_to_visit, conn.request_path)
|> put_flash(:info, "You must be signed in")
|> redirect(to: "/login")
|> halt
_ ->
conn
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment