Skip to content
Snippets Groups Projects
Commit cd63e1a6 authored by maripuus's avatar maripuus
Browse files

Merge branch '46-fr-30-profile-page' into 'main'

Resolve "FR-30: Profile page"

Closes #46

See merge request !10
parents e2564971 117875b3
Branches 15-fr-05-delete-account-2
No related tags found
1 merge request!10Resolve "FR-30: Profile page"
Pipeline #44528 passed
......@@ -23,7 +23,7 @@ defmodule PropTrackr.Accounts.User do
|> cast(params, [:name, :surname, :birth_date, :phone_number, :bio, :email, :password, :confirm_password])
|> validate_required([:name, :surname, :birth_date, :phone_number, :email, :password, :confirm_password])
|> validate_password_confirmation(:password, :confirm_password)
|> validate_unique_email()
# |> validate_unique_email()
end
defp validate_password_confirmation(changeset, field_1, field_2) do
......
<header class="header">
<ol class="breadcrumb pull-right">
<%= if @conn.assigns.current_user do %>
<li>Hello <%= @conn.assigns.current_user.name %></li>
<button
id="logout_button"
phx-click={JS.navigate("/logout")}
class="text-sm font-semibold leading-6 text-zinc-900 hover:text-zinc-700"
>
<.icon name="hero-arrow-left-solid" class="h-3 w-3" /> Logout
</button>
<% else %>
<% end %>
</ol>
<header class="header flex flex-row-reverse gap-x-4 px-4 py-1">
<%= if @conn.assigns.current_user do %>
<button
id="logout_button"
phx-click={JS.navigate("/logout")}
class="text-sm font-semibold leading-6 text-zinc-900 hover:text-zinc-700"
>
Logout
<.icon name="hero-arrow-right-solid" class="h-3 w-3" />
</button>
<span>Hello, <%= @conn.assigns.current_user.name %>!</span>
<% end %>
<span class="logo"></span>
</header>
<main class="px-4 py-20 sm:px-6 lg:px-8">
<div class="mx-auto max-w-2xl"><.flash_group flash={@flash} /> <%= @inner_content %></div>
</main>
defmodule PropTrackrWeb.ProfileController do
use PropTrackrWeb, :controller
import PropTrackr.Authentication
alias PropTrackr.Repo
alias PropTrackr.Accounts.User
def index(conn, _params) do
user_id = get_session(conn, :user_id)
if user_id == nil do
conn
|> put_flash(:error, "You are not logged!")
|> redirect(to: ~p"/login")
else
user = Repo.get(User, user_id)
render(conn, "index.html", user: user)
end
end
end
defmodule PropTrackrWeb.ProfileHTML do
use PropTrackrWeb, :html
embed_templates "profile_html/*"
end
<.header>
<%= @user.name %> <%= @user.surname %>'s profile
<:actions>
<.link href={~p"/me/details"}>
<.button>Edit details</.button>
</.link>
<.link href={~p"/me/delete"}>
<.button class="bg-red-700 hover:bg-red-500">Delete account</.button>
</.link>
</:actions>
</.header>
<p><span class="bold">Birth date:</span> <%= @user.birth_date %></p>
<p><span class="bold">Phone number:</span> <%= @user.phone_number %></p>
<p><span class="bold">Email:</span> <%= @user.email %></p>
<p><span class="bold">Bio:</span> <%= @user.bio %></p>
......@@ -20,11 +20,16 @@ defmodule PropTrackrWeb.Router do
get "/", PageController, :home
resources "/users", UserController, only: [:index]
# Authentication
resources "/register", RegisterController, only: [:index, :create]
resources "/login", LoginController, only: [:index, :create]
resources "/logout", LogoutController
resources "/logout", LogoutController, only: [:index]
# User profile
resources "/me", ProfileController, only: [:index]
resources "/me/details", UpdateController, only: [:index, :create]
resources "/me/password", PasswordController, only: [:index, :create]
resources "/me/details", UpdateController
end
# Other scopes may use custom stacks.
......
......@@ -29,6 +29,8 @@ defmodule PropTrackrWeb.UserControllerTest do
assert html_response(conn, 200) =~ "Passwords do not match."
end
# TODO(Kerdo): Reintroduce this test when re-enabling already existing email constraint
@tag :skip
test "AC4: user sees an error if an account with the same email exists", %{conn: conn, user_params: user_params} do
Repo.insert!(%User{email: user_params[:email], password: "test123"})
conn = post(conn, "/register", user: user_params)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment