Skip to content

Commit

Permalink
add dependency phx_gen_auth to Authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinix committed Jan 16, 2024
1 parent 76e6b91 commit c769d14
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
2 changes: 1 addition & 1 deletion config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Config
# Configure your database
config :pento, Pento.Repo,
username: "postgres",
password: "postgres",
password: "password",
hostname: "localhost",
database: "pento_dev",
stacktrace: true,
Expand Down
7 changes: 7 additions & 0 deletions lib/pento_web/controllers/live/page_live.html.heex
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<input
type="text"
name="q"
value="<%= @query %>"
placeholder="Live dependency search"
list="results"
autocomplete="off"/>
43 changes: 43 additions & 0 deletions lib/pento_web/controllers/live/wrong_live.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
defmodule PentoWeb.WrongLive do
use PentoWeb, :live_view

def mount(_params, _session, socket) do
{
:ok,
assign(socket, score: 0, message: "Guess a number")
}
end

def render(assigns) do
~L"""
<h1>Your score: <%= @score %></h1>
<h2>
<%= @message %>
</h2>
<h2>
<%= for n <- 1..10 do %>
<a href="#" phx-click="guess" phx-value-number="<%= n %>"><%= n %></a>
<% end %>
</h2>
<h2>
<%= @message %>
It's <%= time() %>
</h2>
"""
end

def handle_event("guess", %{"number" => guess} = data, socket) do
IO.inspect(data)
message = "Your guess: #{guess}. Wrong. Guess again. "
score = socket.assigns.score - 1

{
:noreply,
assign(socket, message: message, score: score)
}
end

def time() do
DateTime.utc_now() |> to_string()
end
end
1 change: 1 addition & 0 deletions lib/pento_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ defmodule PentoWeb.Router do
pipe_through :browser

get "/", PageController, :home
live "/guess", WrongLive
end

# Other scopes may use custom stacks.
Expand Down
3 changes: 2 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ defmodule Pento.MixProject do
{:gettext, "~> 0.20"},
{:jason, "~> 1.2"},
{:dns_cluster, "~> 0.1.1"},
{:plug_cowboy, "~> 2.5"}
{:plug_cowboy, "~> 2.5"},
{:phx_gen_auth, "~> 0.7", only: [:dev], runtime: false}
]
end

Expand Down

0 comments on commit c769d14

Please sign in to comment.