Created
December 21, 2016 21:13
-
-
Save javierg/81ce7b15445f5f837b45c1d8f6353bf4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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