implement github oauth and display user's name and avatar from it

This commit is contained in:
2021-11-12 20:20:40 -05:00
parent dfaa328af4
commit 540519222d
24 changed files with 226 additions and 181 deletions

View 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

View 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

View 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