diff --git a/lib/chess/auth.ex b/lib/chess/auth.ex index 9c55709..4cce885 100644 --- a/lib/chess/auth.ex +++ b/lib/chess/auth.ex @@ -40,9 +40,9 @@ defmodule Chess.Auth do end @doc false - def authenticate_user(username, password) do + def authenticate_user(email, password) do query = from u in User, - where: u.username == ^username + where: u.email == ^email query |> Repo.one diff --git a/lib/chess/auth/user.ex b/lib/chess/auth/user.ex index 5148183..85391e8 100644 --- a/lib/chess/auth/user.ex +++ b/lib/chess/auth/user.ex @@ -7,7 +7,7 @@ defmodule Chess.Auth.User do schema "users" do field :name, :string - field :username, :string + field :email, :string field :password, :string, virtual: true field :password_hash, :string @@ -22,7 +22,7 @@ defmodule Chess.Auth.User do struct |> cast(params, required_attrs()) |> validate_required(required_attrs()) - |> unique_constraint(:username) + |> unique_constraint(:email) |> hash_password() end @@ -36,5 +36,5 @@ defmodule Chess.Auth.User do end end - defp required_attrs, do: ~w[name username password]a + defp required_attrs, do: ~w[name email password]a end diff --git a/lib/chess_web/controllers/game_controller.ex b/lib/chess_web/controllers/game_controller.ex index e26e6e3..549b10e 100644 --- a/lib/chess_web/controllers/game_controller.ex +++ b/lib/chess_web/controllers/game_controller.ex @@ -81,7 +81,7 @@ defmodule ChessWeb.GameController do defp get_opponents(user) do query = from user in "users", where: user.id != ^user.id, - select: {user.username, user.id} + select: {user.name, user.id} query |> Repo.all diff --git a/lib/chess_web/controllers/session_controller.ex b/lib/chess_web/controllers/session_controller.ex index 1c9c54f..5517490 100644 --- a/lib/chess_web/controllers/session_controller.ex +++ b/lib/chess_web/controllers/session_controller.ex @@ -12,9 +12,9 @@ defmodule ChessWeb.SessionController do def create( conn, - %{"user" => %{"username" => username, "password" => password}} + %{"user" => %{"email" => email, "password" => password}} ) do - case Auth.authenticate_user(username, password) do + case Auth.authenticate_user(email, password) do {:ok, user} -> conn |> Guardian.Plug.sign_in(user) @@ -23,7 +23,7 @@ defmodule ChessWeb.SessionController do {:error, _error} -> changeset = User.changeset(%User{}) conn - |> put_flash(:error, "Bad username or password") + |> put_flash(:error, "Bad email or password") |> render("new.html", changeset: changeset) end end diff --git a/lib/chess_web/templates/game/index.html.eex b/lib/chess_web/templates/game/index.html.eex index a9d71c3..36be170 100644 --- a/lib/chess_web/templates/game/index.html.eex +++ b/lib/chess_web/templates/game/index.html.eex @@ -5,7 +5,7 @@ <%= for game <- @games do %>
<%= link "Back to games", to: game_path(@conn, :index) %>
diff --git a/lib/chess_web/templates/layout/app.html.eex b/lib/chess_web/templates/layout/app.html.eex index 54b1120..8071437 100644 --- a/lib/chess_web/templates/layout/app.html.eex +++ b/lib/chess_web/templates/layout/app.html.eex @@ -16,7 +16,7 @@