move user stuff into subfolder, fix/hook some things

This commit is contained in:
Mayel 2020-11-05 14:03:37 +01:00
parent 99a9f3681e
commit b2a260f0a4
78 changed files with 254 additions and 177 deletions

View file

@ -6,10 +6,5 @@
@import "./components/pagination";
@import "./components/toggle";
// Auth Flow mixins and styles
@import "../../lib/web/live/users/mixins";
// Profile Flow mixins and styles
@import "../../lib/web/live/users/profile/hero";
@import "../../lib/web/live/users/profile/profile";
@import "../../lib/web/live/users/settings/settings";
// app mixins and styles
@import "../../lib/web/mixins";

View file

@ -1,8 +1,8 @@
/* HTML TEMPLATE
<div class="named-avatar">
<img alt="profile pic" src="<%= @user.icon_url %>" />
<h3><%= @user.name %></h3>
<img alt="profile pic" src="<%= e(@user, :profile, :icon_url, "") %>" />
<h3><%= e(@user, :profile, :name, "Me") %></h3>
</div>
*/

View file

@ -146,9 +146,9 @@ config :vox_publica, SignupForm,
email: [format: ~r(^[^@]{1,128}@[^@\.]+\.[^@]{2,128}$)],
password: [length: [min: 10, max: 64]]
alias VoxPublica.Users.CreateForm
alias VoxPublica.Users.ValidFields
config :vox_publica, CreateForm,
config :vox_publica, ValidFields,
username: [format: ~r(^[a-z][a-z0-9_]{2,30}$)i],
name: [length: [min: 3, max: 50]],
summary: [length: [min: 20, max: 500]]

View file

@ -8,7 +8,7 @@ services:
context: .
dockerfile: "Dockerfile.dev"
ports:
- "4002:4000"
- "4003:4000"
# env_file:
# - config/dev/public.env
# - config/dev/secrets.env

View file

@ -6,12 +6,14 @@ defmodule VoxPublica.Accounts.Emails do
alias Pointers.Changesets
alias VoxPublica.Web.EmailView
def confirm_email(%Account{email: %{email: email}}=account) when is_binary(email) do
def confirm_email(%Account{email: %{email: email, confirm_token: confirm_token}}=account) when is_binary(email) do
IO.inspect(account)
conf =
Application.get_env(:vox_publica, __MODULE__, [])
|> Keyword.get(:confirm_email, [])
new_email()
|> subject(Keyword.get(conf, :subject, "Confirm your email - VoxPublica"))
|> assign(:confirm_token, confirm_token)
|> put_html_layout({EmailView, "confirm_email.html"})
|> put_text_layout({EmailView, "confirm_email.text"})
end

View file

@ -11,12 +11,12 @@ defmodule VoxPublica.Web.CreateUserController do
def create(conn, params) do
Map.get(params, "create_form", %{})
|> Users.create(conn.assigns[:account])
|> Users.create(conn.assigns[:account])
|> case do
{:ok, user} -> switched(conn, user)
{:error, form} ->
render(conn, "form.html", form: form)
end
end
end
defp form(attrs \\ %{}, account), do: Users.changeset(:create, attrs, account)
@ -24,8 +24,8 @@ defmodule VoxPublica.Web.CreateUserController do
defp switched(conn, %User{id: id, character: %{username: username}}) do
conn
|> put_flash(:info, "Welcome, #{username}, you're all ready to go!")
|> put_session(:user_id, id)
|> redirect(to: "/home/@#{username}")
|> put_session(:username, username)
|> redirect(to: "/")
end
end

View file

@ -24,7 +24,7 @@ defmodule VoxPublica.Web.LoginController do
defp logged_in(account, conn) do
conn
|> put_session(:account_id, account.id)
|> redirect(to: "/home")
|> redirect(to: "/switch-user")
end
end

View file

@ -0,0 +1,18 @@
defmodule VoxPublica.Web.LogoutController do
use VoxPublica.Web, :controller
alias VoxPublica.Accounts
def index(conn, _) do
conn |>
logout()
end
defp logout(conn) do
conn
|> put_session(:account_id, nil)
|> redirect(to: "/")
end
end

View file

@ -27,11 +27,12 @@ defmodule VoxPublica.Web.SwitchUserController do
defp lookup({:error, :not_found}, conn), do: not_found(conn)
defp lookup({:error, :not_permitted}, conn), do: not_permitted(conn)
defp switch(conn, user) do
defp switch(conn, %{character: %{username: username}}) do
conn
|> put_session(:user_id, user.id)
|> put_flash(:info, "Welcome back, @#{user.character.username}!")
|> redirect(to: "/home/@#{user.character.username}")
# |> put_session(:user_id, user.id)
|> put_session(:username, username)
|> put_flash(:info, "Welcome back, @#{username}!")
|> redirect(to: "/home/@#{username}")
end
defp no_users(conn) do

View file

@ -0,0 +1,4 @@
defmodule VoxPublica.Web.HeaderMeLive do
use VoxPublica.Web, :live_component
end

View file

@ -0,0 +1,43 @@
<%= if @current_user do %>
<div class="box__info">
<%= live_redirect to: "/@"<> e(@current_user, :character, :username, "") do %>
<img src="<%= e(@current_user, :profile, :icon_url, "") %>" />
<h3><%= e(@current_user, :profile, :name, "Me") %></h3>
<% end %>
<details class="drawer__profile ligth" >
<summary class="user__dropdown">
<span class="right__notification"><i class="feather-plus"></i></span>
</summary>
<ul class="dropdown__list">
<h2>Create</h2>
<li phx-target="#write_widget" phx-click="toggle_post"><i class="feather-edit"></i> Write a post</li>
</ul>
</details>
<span class="right__notification"><i class="feather-bell"></i></span>
<details class="drawer__profile ligth" >
<summary class="user__dropdown">
<span class="right__notification"><i class="feather-chevron-down"></i></span>
</summary>
<ul class="dropdown__list">
<li><%= live_redirect to: "/@"<> e(@current_user, :character, :username, "me") do %>Profile<% end %></li>
<%= if e(@current_user, :is_instance_admin, false) do %>
<li><%= live_redirect to: "/admin/settings/access" do %>Admin<% end %></li>
<% end %>
<li><%= live_redirect to: "/settings" do %>Settings<% end %></li>
<li><a href="/logout">Logout</a></li>
</ul>
</details>
</div>
<% end %>
<%= if @current_user == nil do %>
<div class="panel__item">
<%= live_redirect to: "/login", class: "button" do %>
<i class="feather-log-in"></i> Log in
<% end %>
</div>
<div class="panel__item">
<%= live_redirect to: "/signup", class: "button" do %>
<i class="feather-zap"></i> Sign up
<% end %>
</div>
<% end %>

View file

@ -6,27 +6,27 @@ defmodule VoxPublica.Web.HeroProfileLive do
~L"""
<div class="mainContent__hero">
<div class="hero__image">
<img alt="background image" src="<%= @user.image_url %>" />
<img alt="background image" src="<%= e(@user, :profile, :image_url, "") %>" />
</div>
<div class="hero__info">
<div class="info__icon">
<img alt="profile pic" src="<%= @user.icon_url %>" />
<img alt="profile pic" src="<%= e(@user, :profile, :icon_url, "") %>" />
</div>
<div class="info__meta">
<h1><%= @user.name %></h1>
<h4 class="info__username"><%= @user.username %></h4>
<h1><%= e(@user, :profile, :name, "Me") %></h1>
<h4 class="info__username"><%= e(@user, :character, :username, "me") %></h4>
<div class="info__details">
<%= if @user.website do %>
<%= if e(@user, :profile, :website, nil) do %>
<div class="details__meta">
<a href="#" target="_blank">
<i class="feather-external-link"></i>
<%= @user.website %>
<%= e(@user, :profile, :website, "") %>
</a>
</div>
<% end %>
<%= if @user.location do %>
<%= if e(@user, :profile, :location, nil) do %>
<div class="details__meta">
<i class="feather-map-pin"></i><%= @user.location %>
<i class="feather-map-pin"></i><%= e(@user, :profile, :location, "") %>
</div>
<% end %>
</div>

View file

@ -4,7 +4,7 @@ defmodule VoxPublica.Web.ProfileLive do
alias VoxPublica.Web.ProfileNavigationLive
alias VoxPublica.Web.ProfileAboutLive
alias VoxPublica.Fake
import VoxPublica.Web.CommonHelper
@impl true
def mount(params, session, socket) do
@ -14,8 +14,8 @@ defmodule VoxPublica.Web.ProfileLive do
|> assign(
page_title: "User",
selected_tab: "about",
user: Fake.user_live(),
current_user: Fake.user_live()
user: socket.assigns.current_user
# current_user: Fake.user_live()
)}
end
@ -29,7 +29,8 @@ defmodule VoxPublica.Web.ProfileLive do
def handle_params(%{} = _params, _url, socket) do
{:noreply,
assign(socket,
current_user: Fake.user_live()
selected_tab: "about"
# current_user: Fake.user_live()
)}
end

View file

@ -3,18 +3,18 @@
<div class="member__hero">
<div class="suphero">
<div class="suphero__left">
<%= live_patch to: "/@" <> @user.username <> "/about" do %>
<%= live_patch to: "/@" <> e(@user, :character, :username, "me") <> "/about" do %>
<div class="named-avatar">
<img alt="profile pic" src="<%= @user.icon_url %>" />
<h3><%= @user.name %></h3>
<img alt="profile pic" src="<%= e(@user, :profile, :icon_url, "") %>" />
<h3><%= e(@user, :profile, :name, "Me") %></h3>
</div>
<% end %>
</div>
<div class="suphero__actions">
<%= if is_map(@current_user) and @user.id==@current_user.id do %>
<%= live_redirect to: "/~/settings" do %>Settings<% end %>
<%= live_redirect to: "/settings" do %>Settings<% end %>
<% else %>
<%= if @user.is_followed do %>
<%= if e(@user, :is_followed) do %>
<button class="button follow" phx-click="unfollow">Unfollow</button>
<% else %>
<button class="button follow" phx-click="follow">Follow</button>
@ -29,21 +29,21 @@
<div class="mainContent__selected">
<h3 class="area__title">likes</h3>
<div class="selected__area">
</div>
</div>
<% @selected_tab == "following" -> %>
<div class="mainContent__selected">
<h3 class="area__title"><%= @user.name %> is following</h3>
<h3 class="area__title"><%= e(@user, :profile, :name, "") %> is following</h3>
<div class="selected__area">
</div>
</div>
<% @selected_tab == "posts" -> %>
<div class="mainContent__selected">
<h3 class="area__title">Posts</h3>
<div class="selected__area">
</div>
</div>
<% true -> %>
@ -59,14 +59,14 @@
<%= live_component(
@socket,
ProfileAboutLive,
description: @user.summary
description: e(@user, :profile, :summary, "me")
) %>
</div>
</div>
<div class="mainContent__selected">
<h3 class="area__title">Updates</h3>
<div class="selected__area">
</div>
</div>
</div>
@ -76,7 +76,7 @@
@socket,
ProfileNavigationLive,
selected: @selected_tab,
username: @user.username,
username: e(@user, :character, :username, "me"),
current_user: @current_user
)
%>

View file

@ -1,4 +1,4 @@
defmodule VoxPublica.Web.SettingsLive.SettingsGeneralLive do
use VoxPublica.Web, :live_component
import VoxPublica.Web.CommonHelper
end

View file

@ -1,18 +1,18 @@
<section class="settings__section">
<div class="section__main">
<h1>Edit profile</h1>
<form action="/~/settings" phx-submit="profile_save" method="post" enctype="multipart/form-data" <%= if @trigger_submit, do: "phx-trigger-action" %>>
<form action="/settings" phx-submit="profile_save" method="post" enctype="multipart/form-data" <%= if @trigger_submit, do: "phx-trigger-action" %>>
<div class="section__item">
<h4>Edit your name</h4>
<input name="profile[name]" type="text" value="<%= @current_user.name %>" placeholder="Type a new name...">
<input name="profile[name]" type="text" value="<%= e(@current_user, :profile, :name, "Me") %>" placeholder="Type a new name...">
</div>
<div class="section__item">
<h4>Edit your email</h4>
<input name="profile[email]" value="<%= @current_user.email %>" type="text" placeholder="Type a new email...">
<input name="profile[email]" value="<%= e(@current_user, :profile, :email, "") %>" type="text" placeholder="Type a new email...">
</div>
<div class="section__item">
<h4>Edit your summary</h4>
<textarea name="profile[summary]" placeholder="Type your summary..."><%= @current_user.summary %></textarea>
<textarea name="profile[summary]" placeholder="Type your summary..."><%= e(@current_user, :profile, :summary, "") %></textarea>
</div>
<div class="section__preview">
@ -21,8 +21,8 @@
<div class="card__bar">
<div class="bar__icon" style="background-image: url(<%= e(@current_user, :icon_url, "") %>)"></div>
<div class="bar__meta">
<h3><%= @current_user.name %></h3>
<h4><%= @current_user.username %></h4>
<h3><%= e(@current_user, :profile, :name, "") %></h3>
<h4>@<%= e(@current_user, :character, :username, "") %></h4>
</div>
</div>
</div>
@ -47,11 +47,11 @@
<h3>Profile metadata</h3>
<div class="section__item">
<h4>Edit your website</h4>
<input name="profile[website]" value="<%= @current_user.website %>" type="text" placeholder="Type a new website...">
<input name="profile[website]" value="<%= e(@current_user, :profile, :website, "") %>" type="text" placeholder="Type a new website...">
</div>
<div class="section__item">
<h4>Edit your location</h4>
<input name="profile[location]" type="text" value="<%= @current_user.location %>" placeholder="Type a new location...">
<input name="profile[location]" type="text" value="<%= e(@current_user, :profile, :location, "") %>" placeholder="Type a new location...">
</div>
</div>

View file

@ -4,7 +4,7 @@ defmodule VoxPublica.Web.SettingsLive.SettingsNavigationLive do
def render(assigns) do
~L"""
<%= live_patch link_body("My profile", "feather-user"),
to: "/~/settings/general",
to: "/settings/general",
class: if @selected == "general", do: "navigation__item active", else: "navigation__item"
%>

View file

@ -1,7 +1,7 @@
defmodule VoxPublica.Web.SettingsLive do
use VoxPublica.Web, :live_view
import VoxPublica.Web.CommonHelper
# alias VoxPublica.Profiles.Web.ProfilesHelper
# alias VoxPublica.Web.GraphQL.UsersResolver
alias VoxPublica.Fake
@ -20,8 +20,8 @@ defmodule VoxPublica.Web.SettingsLive do
|> assign(
page_title: "Settings",
selected_tab: "general",
trigger_submit: false,
current_user: Fake.user_live()
trigger_submit: false
# current_user: Fake.user_live()
# session: session_token
)}
end
@ -56,14 +56,14 @@ defmodule VoxPublica.Web.SettingsLive do
:noreply,
assign(socket, trigger_submit: true)
|> put_flash(:info, "Details saved!")
# |> push_redirect(to: "/~/profile")
# |> push_redirect(to: "/profile")
}
true ->
{:noreply,
socket
|> put_flash(:info, "Profile saved!")
|> push_redirect(to: "/~/profile")}
|> push_redirect(to: "/profile")}
end
end
end

View file

@ -3,11 +3,11 @@
<div class="settings__hero">
<div class="suphero">
<div class="suphero__left named-avatar">
<img alt="profile pic" src="<%= @current_user.icon_url %>" />
<h3><%= @current_user.name %></h3>
<img alt="profile pic" src="<%= e(@current_user, :profile, :icon_url, "") %>" />
<h3><%= e(@current_user, :profile, :name, "") %></h3>
</div>
<div class="suphero__actions">
<%= live_redirect to: "/~/profile" do %>View my profile<% end %>
<%= live_redirect to: "/profile" do %>View my profile<% end %>
<details class="more__dropdown">
<summary>
<i class="feather-more-horizontal"></i>

View file

@ -29,6 +29,6 @@ defmodule VoxPublica.Web.My.SettingsUpload do
})
conn
|> redirect(external: "/~/profile")
|> redirect(external: "/profile")
end
end

30
lib/me/me_router.ex Normal file
View file

@ -0,0 +1,30 @@
defmodule VoxPublica.Me.Router do
defmacro __using__(_) do
quote do
scope "/", VoxPublica.Web do
pipe_through :browser
# guest visible pages
resources "/signup", SignupController, only: [:index, :create]
resources "/confirm-email", ConfirmEmailController, only: [:index, :show, :create]
resources "/login", LoginController, only: [:index, :create]
resources "/password/forgot", ForgotPasswordController, only: [:index, :create]
resources "/password/reset/:token", ResetPasswordController, only: [:index, :create]
resources "/password/change", ChangePasswordController, only: [:index, :create]
# authenticated pages
resources "/create-user", CreateUserController, only: [:index, :create]
get "/switch-user", SwitchUserController, :index
get "/switch-user/@:username", SwitchUserController, :show
get "/logout", LogoutController, :index
live "/profile", ProfileLive, :profile
live "/@:username", ProfileLive, :profile
live "/@:username/:tab", ProfileLive, :profile_tab
live "/settings", SettingsLive, :setting
live "/settings/:tab", SettingsLive, :setting_tav
end
end
end
end

View file

@ -5,7 +5,7 @@ defmodule VoxPublica.Users do
use OK.Pipe
alias CommonsPub.Accounts.Account
alias CommonsPub.Users.User
alias VoxPublica.Users.CreateForm
alias VoxPublica.Users.ValidFields
alias Pointers.Changesets
alias VoxPublica.{Repo, Utils}
alias Ecto.Changeset
@ -14,15 +14,15 @@ defmodule VoxPublica.Users do
@type changeset_name :: :create
@spec changeset(changeset_name, attrs :: map, %Account{}) :: Changeset.t
def changeset(:create, attrs, %Account{}=account), do: CreateForm.changeset(attrs, account)
def changeset(:create, attrs, %Account{}=account), do: ValidFields.changeset(attrs, account)
def create(attrs, %Account{}=account) when not is_struct(attrs),
do: create(changeset(:create, attrs, account))
defp create(%Changeset{data: %CreateForm{}}=cs),
defp create(%Changeset{data: %ValidFields{}}=cs),
do: Changeset.apply_action(cs, :insert) ~>> create()
defp create(%CreateForm{}=form) do
defp create(%ValidFields{}=form) do
Map.from_struct(form)
|> create_changeset()
|> Repo.put()
@ -42,12 +42,16 @@ defmodule VoxPublica.Users do
def by_account(account_id) when is_binary(account_id),
do: Repo.all(by_account_query(account_id))
def by_account_query(account_id) do
def by_account_one(account_id) when is_binary(account_id),
do: Repo.all(by_account_query(account_id, 1))
def by_account_query(account_id, limit \\ 100) do
from u in User,
join: a in assoc(u, :accounted),
join: c in assoc(u, :character),
where: a.account_id == ^account_id,
preload: [accounted: a, character: c]
preload: [accounted: a, character: c],
limit: ^limit
end
def by_username(username), do: Repo.single(by_username_query(username))

View file

@ -1,9 +1,9 @@
defmodule VoxPublica.Users.CreateForm do
defmodule VoxPublica.Users.ValidFields do
use Ecto.Schema
alias Ecto.Changeset
alias CommonsPub.Accounts.Account
alias VoxPublica.Users.CreateForm
alias VoxPublica.Users.ValidFields
embedded_schema do
field :username, :string
@ -19,7 +19,7 @@ defmodule VoxPublica.Users.CreateForm do
# required: [:username, :name, :summary],
# ]
def changeset(form \\ %CreateForm{}, attrs, %Account{id: id}) do
def changeset(form \\ %ValidFields{}, attrs, %Account{id: id}) do
form
|> Changeset.cast(attrs, @cast)
|> Changeset.change(account_id: id)

View file

@ -0,0 +1,3 @@
defmodule VoxPublica.Web.ChangePasswordView do
use VoxPublica.Web, [:view, "lib/me/views/templates"]
end

View file

@ -0,0 +1,3 @@
defmodule VoxPublica.Web.ConfirmEmailView do
use VoxPublica.Web, [:view, "lib/me/views/templates"]
end

View file

@ -0,0 +1,3 @@
defmodule VoxPublica.Web.CreateUserView do
use VoxPublica.Web, [:view, "lib/me/views/templates"]
end

View file

@ -0,0 +1 @@
Token: <%= @confirm_token %>

View file

@ -0,0 +1 @@
Token: <%= @confirm_token %>

View file

@ -0,0 +1,3 @@
defmodule VoxPublica.Web.EmailView do
use VoxPublica.Web, [:view, "lib/me/views/templates"]
end

View file

@ -0,0 +1,3 @@
defmodule VoxPublica.Web.LoginView do
use VoxPublica.Web, [:view, "lib/me/views/templates"]
end

View file

@ -0,0 +1,3 @@
defmodule VoxPublica.Web.ResetPasswordView do
use VoxPublica.Web, [:view, "lib/me/views/templates"]
end

View file

@ -0,0 +1,3 @@
defmodule VoxPublica.Web.SignupView do
use VoxPublica.Web, [:view, "lib/me/views/templates"]
end

View file

@ -0,0 +1,3 @@
defmodule VoxPublica.Web.SwitchUserView do
use VoxPublica.Web, [:view, "lib/me/views/templates"]
end

7
lib/web/_mixins.scss Normal file
View file

@ -0,0 +1,7 @@
// Auth Flow mixins and styles
@import "../me/live/users/mixins";
// Profile Flow mixins and styles
@import "../me/live/users/profile/hero";
@import "../me/live/users/profile/profile";
@import "../me/live/users/settings/settings";

View file

@ -148,7 +148,9 @@ defmodule VoxPublica.Web.CommonHelper do
def init_assigns(
_params,
%{
"auth_token" => auth_token,
# "auth_token" => auth_token,
"account_id" => account_id,
"username" => username,
"current_user" => current_user,
"_csrf_token" => csrf_token
} = _session,
@ -156,34 +158,44 @@ defmodule VoxPublica.Web.CommonHelper do
) do
# Logger.info(session_preloaded: session)
socket
|> assign(:auth_token, fn -> auth_token end)
|> assign(:current_user, fn -> current_user end)
|> assign(:csrf_token, fn -> csrf_token end)
|> assign(:csrf_token, csrf_token)
# |> assign(:auth_token, auth_token)
|> assign(:account_id, account_id)
|> assign(:username, username)
|> assign(:current_user, current_user)
|> assign(:static_changed, static_changed?(socket))
|> assign(:search, "")
|> assign(:toggle_post, false)
end
def init_assigns(
_params,
%{
"auth_token" => auth_token,
# "auth_token" => auth_token,
"account_id" => account_id,
"username" => username,
"_csrf_token" => csrf_token
} = session,
%Phoenix.LiveView.Socket{} = socket
) do
) when is_binary(account_id) do
# Logger.info(session_load: session)
current_user = Fake.user_live()
{:ok, current_user} = if Kernel.function_exported?(VoxPublica.Users, :by_username, 1) do
VoxPublica.Users.by_username(username)
else
Fake.user_live()
end
# IO.inspect(current_user)
socket
|> assign(:csrf_token, csrf_token)
|> assign(:static_changed, static_changed?(socket))
|> assign(:auth_token, auth_token)
|> assign(:show_title, false)
|> assign(:toggle_post, false)
|> assign(:current_context, nil)
# |> assign(:auth_token, auth_token)
|> assign(:account_id, account_id)
|> assign(:username, username)
|> assign(:current_user, current_user)
|> assign(:static_changed, static_changed?(socket))
|> assign(:search, "")
|> assign(:toggle_post, false)
end
def init_assigns(

View file

@ -1,6 +1,6 @@
defmodule VoxPublica.Web.HomeLive do
use VoxPublica.Web, :live_view
import VoxPublica.Web.CommonHelper
def mount(params, session, socket) do

View file

@ -1,6 +1,6 @@
defmodule VoxPublica.Web.IndexLive do
use VoxPublica.Web, :live_view
import VoxPublica.Web.CommonHelper
def mount(params, session, socket) do

View file

@ -15,25 +15,14 @@ defmodule VoxPublica.Web.Router do
pipe_through :browser
# guest visible pages
live "/", IndexLive, :index
resources "/signup", SignupController, only: [:index, :create]
resources "/confirm-email", ConfirmEmailController, only: [:index, :show, :create]
resources "/login", LoginController, only: [:index, :create]
resources "/password/forgot", ForgotPasswordController, only: [:index, :create]
resources "/password/reset/:token", ResetPasswordController, only: [:index, :create]
resources "/password/change", ChangePasswordController, only: [:index, :create]
# authenticated pages
resources "/create-user", CreateUserController, only: [:index, :create]
get "/switch-user", SwitchUserController, :index
get "/switch-user/@:username", SwitchUserController, :show
live "/home", HomeLive, :home
live "/home/@:username", HomeLive, :home_user
live "/@:username", ProfileLive, :profile
live "/@:username/:tab", ProfileLive, :profile_tab
live "/settings", SettingsLive, :setting
live "/settings/:tab", SettingsLive, :setting_tav
end
use VoxPublica.Me.Router
# If your application does not have an admins-only section yet,
# you can use Plug.BasicAuth to set up some basic authentication
# as long as you are also using SSL (which you should anyway).

View file

@ -1,6 +1,7 @@
defmodule VoxPublica.Web.Layout.HeaderLive do
use VoxPublica.Web, :live_component
import VoxPublica.Web.CommonHelper
alias VoxPublica.Web.HeaderMeLive
def update(assigns, socket) do
{

View file

@ -1,57 +1,19 @@
<header class="cpub__header">
<nav
role="navigation"
<nav
role="navigation"
aria-label="Main navigation">
<div class="header__left">
<% homepage = if @current_user, do: "/~", else: "/" %>
<%= live_redirect to: homepage do %>
<%= live_redirect to: "/" do %>
<h3>VoxPublica</h3>
<% end %>
</div>
<div class="header__right">
<%= if @current_user do %>
<div class="box__info">
<%= live_redirect to: "/@"<> e(@current_user, :username, "") do %>
<img src="<%= e(@current_user, :icon_url, "") %>" />
<h3><%= e(@current_user, :name, "Me") %></h3>
<% end %>
<details class="drawer__profile ligth" >
<summary class="user__dropdown">
<span class="right__notification"><i class="feather-plus"></i></span>
</summary>
<ul class="dropdown__list">
<h2>Create</h2>
<li phx-target="#write_widget" phx-click="toggle_post"><i class="feather-edit"></i> Write a post</li>
</ul>
</details>
<span class="right__notification"><i class="feather-bell"></i></span>
<details class="drawer__profile ligth" >
<summary class="user__dropdown">
<span class="right__notification"><i class="feather-chevron-down"></i></span>
</summary>
<ul class="dropdown__list">
<li><%= live_redirect to: "/@"<> e(@current_user, :username, "me") do %>Profile<% end %></li>
<%= if @current_user.is_instance_admin do %>
<li><%= live_redirect to: "/admin/settings/access" do %>Admin<% end %></li>
<% end %>
<li><%= live_redirect to: "/settings" do %>Settings<% end %></li>
<li><a href="/logout">Logout</a></li>
</ul>
</details>
</div>
<% end %>
<%= if @current_user == nil do %>
<div class="panel__item">
<%= live_redirect to: "/login", class: "button" do %>
<i class="feather-log-in"></i> Log in
<% end %>
</div>
<div class="panel__item">
<%= live_redirect to: "/signup", class: "button" do %>
<i class="feather-zap"></i> Sign up
<% end %>
</div>
<% end %>
<%= live_component(
@socket,
HeaderMeLive,
current_user: @current_user
) %>
</div>
</nav>
</header>
</header>

View file

@ -1,3 +0,0 @@
defmodule VoxPublica.Web.ChangePasswordView do
use VoxPublica.Web, :view
end

View file

@ -1,3 +0,0 @@
defmodule VoxPublica.Web.ConfirmEmailView do
use VoxPublica.Web, :view
end

View file

@ -1,3 +0,0 @@
defmodule VoxPublica.Web.CreateUserView do
use VoxPublica.Web, :view
end

View file

@ -1,3 +0,0 @@
defmodule VoxPublica.Web.EmailView do
use VoxPublica.Web, :view
end

View file

@ -1,3 +0,0 @@
defmodule VoxPublica.Web.LoginView do
use VoxPublica.Web, :view
end

View file

@ -1,3 +0,0 @@
defmodule VoxPublica.Web.ResetPasswordView do
use VoxPublica.Web, :view
end

View file

@ -1,3 +0,0 @@
defmodule VoxPublica.Web.SignupView do
use VoxPublica.Web, :view
end

View file

@ -1,3 +0,0 @@
defmodule VoxPublica.Web.SwitchUserView do
use VoxPublica.Web, :view
end

View file

@ -12,10 +12,10 @@ defmodule VoxPublica.Web do
end
end
def view do
def view(root \\ "lib/web/templates") do
quote do
use Phoenix.View,
root: "lib/web/templates",
root: unquote(root),
namespace: VoxPublica.Web
# Import convenience functions from controllers
@ -75,6 +75,8 @@ defmodule VoxPublica.Web do
import VoxPublica.Web.ErrorHelpers
import VoxPublica.Web.Gettext
alias VoxPublica.Web.Router.Helpers, as: Routes
import VoxPublica.Web.CommonHelper
end
end
@ -84,4 +86,8 @@ defmodule VoxPublica.Web do
defmacro __using__(which) when is_atom(which) do
apply(__MODULE__, which, [])
end
defmacro __using__([which | args]) do
apply(__MODULE__, which, args)
end
end