Skip to content

Instantly share code, notes, and snippets.

@javierg
Created December 21, 2016 21:13
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 javierg/81ce7b15445f5f837b45c1d8f6353bf4 to your computer and use it in GitHub Desktop.
Save javierg/81ce7b15445f5f837b45c1d8f6353bf4 to your computer and use it in GitHub Desktop.
defmodule PhoenixUeberauthComeonin.SessionsController do
use PhoenixUeberauthComeonin.Web, :controller
alias Ueberauth.Strategy.Helpers
plug Ueberauth
def new(conn, _params) do
render conn, "new.html", callback_url: Helpers.callback_url(conn)
end
def identity_callback(%{assigns: %{ueberauth_auth: auth}} = conn, _) do
conn
|> authenticated(User.authenticate auth)
end
defp authenticated(conn, {:ok, user}) do
conn
|> put_flash(:info, "Successfully authenticated.")
|> Plug.put_session(:current_user, user)
|> redirect(to: "/")
end
defp authenticated(conn, {:error, error}) do
conn
|> put_flash(:error, error)
|> redirect(to: "/sessions/new")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment