Add login/logout buttons

This commit is contained in:
Shadowfacts 2020-01-15 21:24:35 -05:00
parent 7054b39937
commit 680f82664e
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
4 changed files with 34 additions and 6 deletions

View File

@ -7,6 +7,8 @@
# General application configuration
use Mix.Config
config :clacks, :instance, name: "Clacks"
config :clacks, :frontend, unauthenticated_homepage: :public_timeline
config :clacks,

View File

@ -43,7 +43,7 @@ defmodule ClacksWeb.Router do
get "/login", LoginController, :login
post "/login", LoginController, :login_post
post "/logout", LoginController, :logout_post
post "/logout", LoginController, :logout
end
scope "/", ClacksWeb do

View File

@ -4,7 +4,7 @@
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Clacks · Phoenix Framework</title>
<title><%= assigns[:page_title] || "Clacks" %></title>
<link rel="stylesheet" href="<%= Routes.static_path(@conn, "/css/app.css") %>"/>
</head>
<body>
@ -12,12 +12,20 @@
<section class="container">
<nav role="navigation">
<ul>
<li><a href="https://hexdocs.pm/phoenix/overview.html">Get Started</a></li>
<li><a href="/"><%= instance_name() %></a></li>
</ul>
<ul>
<li>
<%= if @conn.assigns[:user] do %>
<%= form_for @conn, Routes.login_path(@conn, :logout), [method: :post], fn f -> %>
<%= submit "Log Out", class: "btn-link" %>
<% end %>
<% else %>
<a href="<%= login_path(@conn) %>">Log In</a>
<% end %>
</li>
</ul>
</nav>
<a href="http://phoenixframework.org/" class="phx-logo">
<img src="<%= Routes.static_path(@conn, "/images/phoenix.png") %>" alt="Phoenix Framework Logo"/>
</a>
</section>
</header>
<main role="main" class="container">

View File

@ -1,3 +1,21 @@
defmodule ClacksWeb.LayoutView do
use ClacksWeb, :view
alias ClacksWeb.Router.Helpers, as: Routes
def instance_name do
Application.get_env(:clacks, :instance, %{}) |> Keyword.get(:name)
end
def login_path(conn) do
params =
case Phoenix.Controller.current_path(conn) do
"/" ->
[]
path ->
[continue: path]
end
Routes.login_path(conn, :login, params)
end
end