Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
73a3ad3
commit 4f2196d
Showing
13 changed files
with
2,204 additions
and
2,124 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
defmodule PointingParty.User do | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
|
||
schema "users" do | ||
field :username, :string | ||
end | ||
|
||
@doc false | ||
def changeset(user, attrs \\ %{}) do | ||
user | ||
|> cast(attrs, [:username]) | ||
|> validate_required([:username]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
defmodule PointingPartyWeb.CardController do | ||
use PointingPartyWeb, :controller | ||
plug :authenticate_user | ||
alias PointingParty.Card | ||
|
||
def index(conn, _params) do | ||
# temporary, just to get something on the page for now | ||
card = Card.get!(1) | ||
render(conn, "index.html", card: card) | ||
end | ||
|
||
def authenticate_user(conn, _params) do | ||
case get_session(conn, :username) do | ||
nil -> redirect(conn, to: "/login") |> halt() | ||
username -> assign(conn, :username, username) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
defmodule PointingPartyWeb.SessionController do | ||
use PointingPartyWeb, :controller | ||
alias PointingParty.User | ||
|
||
def new(conn, _params) do | ||
changeset = User.changeset(%User{}) | ||
render(conn, "new.html", changeset: changeset) | ||
end | ||
|
||
def create(conn, params) do | ||
changeset = User.changeset(%User{}, params["user"]) | ||
if changeset.valid? do | ||
user = Ecto.Changeset.apply_changes(changeset) | ||
put_session(conn, :username, user.username) | ||
|> redirect(to: "/cards") |> halt() | ||
else | ||
changeset = %{changeset | action: :insert} | ||
render(conn, "new.html", changeset: changeset) | ||
end | ||
end | ||
|
||
def delete(conn, _params) do | ||
clear_session(conn) | ||
|> redirect(to: "/login") |> halt() | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= @card.title %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<h1>Sign In</h1> | ||
<%= form_for @changeset, Routes.session_path(@conn, :create), fn f -> %> | ||
<label> | ||
Username: <%= text_input f, :username %> | ||
</label> | ||
<%= error_tag f, :username %> | ||
|
||
<%= submit "Sign In" %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
defmodule PointingPartyWeb.CardView do | ||
use PointingPartyWeb, :view | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
defmodule PointingPartyWeb.LayoutHelpers do | ||
use Phoenix.HTML | ||
|
||
@doc """ | ||
Generates tag for inlined form input errors. | ||
""" | ||
def signed_in?(conn) do | ||
conn.assigns[:username] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
defmodule PointingPartyWeb.SessionView do | ||
use PointingPartyWeb, :view | ||
end |