Browse Source

Add login/logout buttons

master
Shadowfacts 1 year ago
parent
commit
680f82664e
Signed by: shadowfacts GPG Key ID: 94A5AB95422746E5
4 changed files with 34 additions and 6 deletions
  1. +2
    -0
      config/config.exs
  2. +1
    -1
      lib/clacks_web/router.ex
  3. +13
    -5
      lib/clacks_web/templates/layout/app.html.eex
  4. +18
    -0
      lib/clacks_web/views/layout_view.ex

+ 2
- 0
config/config.exs 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,


+ 1
- 1
lib/clacks_web/router.ex 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


+ 13
- 5
lib/clacks_web/templates/layout/app.html.eex 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">


+ 18
- 0
lib/clacks_web/views/layout_view.ex 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

Loading…
Cancel
Save