Add login route with hardcoded password validation
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
<main class="px-4 py-8 max-sm:pb-20 sm:px-6 lg:px-8">
|
||||||
|
<div class="mx-auto max-w-5xl">
|
||||||
|
<.flash_group flash={@flash} />
|
||||||
|
<%= @inner_content %>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
defmodule MusicLibraryWeb.SessionController do
|
||||||
|
use MusicLibraryWeb, :controller
|
||||||
|
|
||||||
|
@empty_form %{"password" => ""}
|
||||||
|
|
||||||
|
def new(conn, _params) do
|
||||||
|
conn |> render(:new, form: @empty_form, layout: {MusicLibraryWeb.Layouts, "unauthenticated"})
|
||||||
|
end
|
||||||
|
|
||||||
|
def create(conn, params) do
|
||||||
|
password = params["password"]
|
||||||
|
|
||||||
|
if password == "password" do
|
||||||
|
redirect(conn, to: "/")
|
||||||
|
else
|
||||||
|
conn
|
||||||
|
|> put_flash(:error, "Invalid password")
|
||||||
|
|> redirect(to: ~p"/login")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
defmodule MusicLibraryWeb.SessionHTML do
|
||||||
|
use MusicLibraryWeb, :html
|
||||||
|
|
||||||
|
embed_templates "session_html/*"
|
||||||
|
end
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
<div class="flex min-h-full items-center justify-center px-4 py-12 sm:px-6 lg:px-8">
|
||||||
|
<div class="w-full max-w-sm space-y-10">
|
||||||
|
<div>
|
||||||
|
<h2 class="mt-10 text-center text-2xl font-bold leading-9 tracking-tight text-gray-900">
|
||||||
|
Welcome to your Music Library
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
<.form class="space-y-6" for={@form} action={~p"/sessions/create"}>
|
||||||
|
<div class="relative -space-y-px rounded-md shadow-sm">
|
||||||
|
<div>
|
||||||
|
<label for="password" class="sr-only">Password</label>
|
||||||
|
<input
|
||||||
|
id="password"
|
||||||
|
name="password"
|
||||||
|
type="password"
|
||||||
|
autocomplete="current-password"
|
||||||
|
required
|
||||||
|
class="relative block w-full rounded-b-md border-0 py-1.5 text-gray-900 ring-1 ring-inset ring-gray-100 placeholder:text-gray-400 focus:z-10 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6"
|
||||||
|
placeholder="Password"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex items-center justify-between">
|
||||||
|
<div class="flex items-center">
|
||||||
|
<input
|
||||||
|
id="remember-me"
|
||||||
|
name="remember-me"
|
||||||
|
type="checkbox"
|
||||||
|
class="h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-600"
|
||||||
|
/>
|
||||||
|
<label for="remember-me" class="ml-3 block text-sm leading-6 text-gray-900">
|
||||||
|
Remember me
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
class="flex w-full justify-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-semibold leading-6 text-white hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
|
||||||
|
>
|
||||||
|
Sign in
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</.form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -21,6 +21,9 @@ defmodule MusicLibraryWeb.Router do
|
|||||||
get "/covers/:record_id", CoverController, :show
|
get "/covers/:record_id", CoverController, :show
|
||||||
get "/", StatsController, :index
|
get "/", StatsController, :index
|
||||||
|
|
||||||
|
get "/login", SessionController, :new
|
||||||
|
post "/sessions/create", SessionController, :create
|
||||||
|
|
||||||
live "/records", RecordLive.Index, :index
|
live "/records", RecordLive.Index, :index
|
||||||
live "/records/import", RecordLive.Index, :import
|
live "/records/import", RecordLive.Index, :import
|
||||||
live "/records/:id/edit", RecordLive.Index, :edit
|
live "/records/:id/edit", RecordLive.Index, :edit
|
||||||
|
|||||||
Reference in New Issue
Block a user