Skip to content

Instantly share code, notes, and snippets.

@shankardevy
Last active February 10, 2019 01:12
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/e7d0bde21d9acb85e2dd17ef8ffd1abc to your computer and use it in GitHub Desktop.
Save shankardevy/e7d0bde21d9acb85e2dd17ef8ffd1abc to your computer and use it in GitHub Desktop.
defmodule MangoWeb.Admin.SessionController do
use MangoWeb, :controller
plug :set_layout
alias Mango.Administration
def new(conn, _params) do
conn
|> render("new.html")
end
def send_link(conn, %{"session" => %{"email" => email}}) do
user = Administration.get_admin_by_email(email)
conn = case user do
nil ->
conn
|> put_flash(:error, "Authentication error")
user ->
link = generate_login_link(conn, user)
conn
|> put_flash(:info, "You magic login link is #{link}")
end
conn |> render("new.html")
end
defp generate_login_link(conn, user) do
token = Phoenix.Token.sign(MangoWeb.Endpoint, "user", user.id)
admin_session_url(conn, :create, %{token: token})
end
defp set_layout(conn, _) do
conn
|> put_layout("admin_login.html")
end
end
@SlowburnAZ
Copy link

Where is the "admin_session_url" on line 28 coming from?

@SlowburnAZ
Copy link

Nevermind... this is only an issue when working with Phoenix 1.4. For anyone else that ran into this problem, you'll need to use "Routes.admin_session_url(conn, :create, %{token: token})"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment