implement github oauth and display user's name and avatar from it
This commit is contained in:
41
lib/entendu_web/controllers/auth_controller.ex
Normal file
41
lib/entendu_web/controllers/auth_controller.ex
Normal file
@@ -0,0 +1,41 @@
|
||||
defmodule EntenduWeb.AuthController do
|
||||
@moduledoc """
|
||||
Auth controller responsible for handling Ueberauth responses
|
||||
"""
|
||||
|
||||
use EntenduWeb, :controller
|
||||
|
||||
plug Ueberauth
|
||||
|
||||
alias Ueberauth.Strategy.Helpers
|
||||
alias Entendu.UserFromAuth
|
||||
|
||||
def delete(conn, _params) do
|
||||
conn
|
||||
|> put_flash(:info, "You have been logged out!")
|
||||
|> clear_session()
|
||||
|> redirect(to: "/")
|
||||
end
|
||||
|
||||
def callback(%{assigns: %{ueberauth_failure: _fails}} = conn, _params) do
|
||||
conn
|
||||
|> put_flash(:error, "Failed to authenticate.")
|
||||
|> redirect(to: "/")
|
||||
end
|
||||
|
||||
def callback(%{assigns: %{ueberauth_auth: auth}} = conn, _params) do
|
||||
case UserFromAuth.find_or_create(auth) do
|
||||
{:ok, user} ->
|
||||
conn
|
||||
|> put_flash(:info, "Successfully authenticated.")
|
||||
|> put_session(:current_user, user)
|
||||
|> configure_session(renew: true)
|
||||
|> redirect(to: "/")
|
||||
|
||||
{:error, reason} ->
|
||||
conn
|
||||
|> put_flash(:error, reason)
|
||||
|> redirect(to: "/")
|
||||
end
|
||||
end
|
||||
end
|
11
lib/entendu_web/controllers/link_controller.ex
Normal file
11
lib/entendu_web/controllers/link_controller.ex
Normal file
@@ -0,0 +1,11 @@
|
||||
defmodule EntenduWeb.LinkController do
|
||||
@moduledoc """
|
||||
Controller responsible for managing links responses
|
||||
"""
|
||||
|
||||
use EntenduWeb, :controller
|
||||
|
||||
def just(conn, _params) do
|
||||
render(conn, "just.html")
|
||||
end
|
||||
end
|
11
lib/entendu_web/controllers/page_controller.ex
Normal file
11
lib/entendu_web/controllers/page_controller.ex
Normal file
@@ -0,0 +1,11 @@
|
||||
defmodule EntenduWeb.PageController do
|
||||
@moduledoc """
|
||||
Static page controller
|
||||
"""
|
||||
|
||||
use EntenduWeb, :controller
|
||||
|
||||
def index(conn, _params) do
|
||||
render(conn, "index.html", current_user: get_session(conn, :current_user))
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user