Janky initial implementation of auth and profiles
This commit is contained in:
parent
117ccf5e16
commit
2284a437fa
@ -9,6 +9,8 @@ defmodule Friends.Accounts.User do
|
|||||||
field :confirmed_at, :naive_datetime
|
field :confirmed_at, :naive_datetime
|
||||||
|
|
||||||
timestamps()
|
timestamps()
|
||||||
|
|
||||||
|
has_one :profile, Friends.Friend
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
@ -47,7 +49,7 @@ defmodule Friends.Accounts.User do
|
|||||||
defp validate_password(changeset, opts) do
|
defp validate_password(changeset, opts) do
|
||||||
changeset
|
changeset
|
||||||
|> validate_required([:password])
|
|> validate_required([:password])
|
||||||
|> validate_length(:password, min: 12, max: 72)
|
|> validate_length(:password, min: 6, max: 72)
|
||||||
# |> validate_format(:password, ~r/[a-z]/, message: "at least one lower case character")
|
# |> validate_format(:password, ~r/[a-z]/, message: "at least one lower case character")
|
||||||
# |> validate_format(:password, ~r/[A-Z]/, message: "at least one upper case character")
|
# |> validate_format(:password, ~r/[A-Z]/, message: "at least one upper case character")
|
||||||
# |> validate_format(:password, ~r/[!?@#$%^&*_0-9]/, message: "at least one digit or punctuation character")
|
# |> validate_format(:password, ~r/[!?@#$%^&*_0-9]/, message: "at least one digit or punctuation character")
|
||||||
|
|||||||
@ -8,7 +8,7 @@ defmodule Friends.Accounts.UserNotifier do
|
|||||||
email =
|
email =
|
||||||
new()
|
new()
|
||||||
|> to(recipient)
|
|> to(recipient)
|
||||||
|> from({"Friends", "contact@example.com"})
|
|> from({"Friends App", "ryan@pandu.ski"})
|
||||||
|> subject(subject)
|
|> subject(subject)
|
||||||
|> text_body(body)
|
|> text_body(body)
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,7 @@ defmodule Friends.Friend do
|
|||||||
field(:slug, :string)
|
field(:slug, :string)
|
||||||
field(:memories, {:array, :string})
|
field(:memories, {:array, :string})
|
||||||
|
|
||||||
# has_many(:photos, Media.Photo)
|
belongs_to :user, Friends.Accounts.User, foreign_key: :user_id
|
||||||
|
|
||||||
many_to_many(
|
many_to_many(
|
||||||
:relationships,
|
:relationships,
|
||||||
|
|||||||
13
friends/lib/friends_web/controllers/friend_controller.ex
Normal file
13
friends/lib/friends_web/controllers/friend_controller.ex
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
defmodule FriendsWeb.FriendController do
|
||||||
|
use FriendsWeb, :controller
|
||||||
|
alias Friends.{Friend, Relationship}
|
||||||
|
alias Friends.Accounts.User
|
||||||
|
import Helpers
|
||||||
|
|
||||||
|
def index(conn, _params) do
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> assign(:all_friends, Friend.all)
|
||||||
|
|> render("index.html")
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -21,6 +21,8 @@ defmodule FriendsWeb.Router do
|
|||||||
pipe_through :browser
|
pipe_through :browser
|
||||||
|
|
||||||
get "/", PageController, :index
|
get "/", PageController, :index
|
||||||
|
get "/friends", FriendController, :index
|
||||||
|
|
||||||
live "/friend/:slug", FriendsLive.Show
|
live "/friend/:slug", FriendsLive.Show
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
13
friends/lib/friends_web/templates/friend/index.html.heex
Normal file
13
friends/lib/friends_web/templates/friend/index.html.heex
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<h1>All Friends</h1>
|
||||||
|
|
||||||
|
<ul class="text-xl">
|
||||||
|
<%= for f <- @all_friends do %>
|
||||||
|
<li>
|
||||||
|
<.link href={"/friend/#{f.slug}"}><%= f.name %></.link>
|
||||||
|
<%= if f.id == @current_user.profile.id do %>
|
||||||
|
(you)
|
||||||
|
<% end %>
|
||||||
|
</li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
|
||||||
@ -1,10 +1,16 @@
|
|||||||
<ul class="mt-3 p-2 shadow menu menu-compact dropdown-content bg-base-100 text-neutral rounded-box w-52">
|
|
||||||
<%= if @current_user do %>
|
<%= if @current_user do %>
|
||||||
|
<label tabindex="0" class="btn btn-ghost btn-circle avatar">
|
||||||
|
<div class="w-10 rounded-full">
|
||||||
|
<img src="https://placeimg.com/80/80/people" />
|
||||||
|
</div>
|
||||||
|
</label>
|
||||||
|
<ul class="mt-3 p-2 shadow menu menu-compact dropdown-content bg-base-100 text-neutral rounded-box w-52">
|
||||||
<li><%= @current_user.email %></li>
|
<li><%= @current_user.email %></li>
|
||||||
<li><%= link "Settings", to: Routes.user_settings_path(@conn, :edit) %></li>
|
<li><%= link "Settings", to: Routes.user_settings_path(@conn, :edit) %></li>
|
||||||
<li><%= link "Log out", to: Routes.user_session_path(@conn, :delete), method: :delete %></li>
|
<li><%= link "Log out", to: Routes.user_session_path(@conn, :delete), method: :delete %></li>
|
||||||
|
</ul>
|
||||||
<% else %>
|
<% else %>
|
||||||
<li><%= link "Register", to: Routes.user_registration_path(@conn, :new) %></li>
|
<%= link "Log in", to: Routes.user_session_path(@conn, :new), class: "btn" %>
|
||||||
<li><%= link "Log in", to: Routes.user_session_path(@conn, :new) %></li>
|
<%= link "Register", to: Routes.user_registration_path(@conn, :new), class: "btn btn-primary" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
|
||||||
|
|||||||
@ -4,17 +4,14 @@
|
|||||||
<.link navigate={"/"} class="btn btn-ghost normal-case text-xl">Friends</.link>
|
<.link navigate={"/"} class="btn btn-ghost normal-case text-xl">Friends</.link>
|
||||||
</div>
|
</div>
|
||||||
<div class="dropdown dropdown-end">
|
<div class="dropdown dropdown-end">
|
||||||
<label tabindex="0" class="btn btn-ghost btn-circle avatar">
|
|
||||||
<div class="w-10 rounded-full">
|
|
||||||
<img src="https://placeimg.com/80/80/people" />
|
|
||||||
</div>
|
|
||||||
</label>
|
|
||||||
<%= render("_user_menu.html", conn: @conn, current_user: @current_user) %>
|
<%= render("_user_menu.html", conn: @conn, current_user: @current_user) %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="mx-auto w-full lg:w-3/4">
|
<div class="mx-auto w-full lg:w-3/4">
|
||||||
<main class="container p-4 mb-10 md:p-8 prose">
|
<main class="container p-4 mb-10 md:p-8 prose">
|
||||||
|
<p class="alert alert-info" role="alert"><%= get_flash(@conn, :info) %></p>
|
||||||
|
<p class="alert alert-danger" role="alert"><%= get_flash(@conn, :error) %></p>
|
||||||
<%= @inner_content %>
|
<%= @inner_content %>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
6
friends/lib/friends_web/views/friend_view.ex
Normal file
6
friends/lib/friends_web/views/friend_view.ex
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
defmodule FriendsWeb.FriendView do
|
||||||
|
use FriendsWeb, :view
|
||||||
|
import Phoenix.Component
|
||||||
|
import Helpers
|
||||||
|
|
||||||
|
end
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
defmodule Friends.Repo.Migrations.ProfileBelongsToUser do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
alter table(:friends) do
|
||||||
|
add :user_id, references(:users)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -3,6 +3,6 @@ defmodule FriendsWeb.PageControllerTest do
|
|||||||
|
|
||||||
test "GET /", %{conn: conn} do
|
test "GET /", %{conn: conn} do
|
||||||
conn = get(conn, "/")
|
conn = get(conn, "/")
|
||||||
assert html_response(conn, 200) =~ "Welcome to Phoenix!"
|
assert html_response(conn, 200) =~ "Friends App"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user