diff --git a/config/runtime.exs b/config/runtime.exs
index 76f2616..7704f4f 100644
--- a/config/runtime.exs
+++ b/config/runtime.exs
@@ -29,7 +29,6 @@ if config_env() == :prod do
You can generate one by calling: mix phx.gen.secret
"""
- app_name = System.fetch_env!("FLY_APP_NAME")
host = System.get_env("URL_HOST") || "example.com"
config :live_beats, LiveBeatsWeb.Endpoint,
diff --git a/fly.toml b/fly.toml
index 5f07bf5..1fe5bc7 100644
--- a/fly.toml
+++ b/fly.toml
@@ -11,6 +11,10 @@ processes = []
IPV6 = 1
URL_HOST = "livebeats.fly.dev"
+[mounts]
+ source="data"
+ destination="/app/live_beats/lib/live_beats-0.1.0/priv/uploads"
+
[experimental]
allowed_public_ports = []
auto_rollback = true
@@ -25,7 +29,7 @@ processes = []
[services.concurrency]
hard_limit = 25
soft_limit = 20
- type = "connections"
+ type = "requests"
[[services.ports]]
handlers = ["http"]
diff --git a/lib/live_beats/accounts.ex b/lib/live_beats/accounts.ex
index 982f712..50efa35 100644
--- a/lib/live_beats/accounts.ex
+++ b/lib/live_beats/accounts.ex
@@ -21,6 +21,12 @@ defmodule LiveBeats.Accounts do
Repo.all(from u in User, limit: ^Keyword.fetch!(opts, :limit))
end
+ def lists_users_by_active_profile(id, opts) do
+ Repo.all(
+ from u in User, where: u.active_profile_user_id == ^id, limit: ^Keyword.fetch!(opts, :limit)
+ )
+ end
+
def admin?(%User{} = user) do
user.email in Application.fetch_env!(:live_beats, :admin_emails)
end
@@ -76,6 +82,8 @@ defmodule LiveBeats.Accounts do
"""
def get_user!(id), do: Repo.get!(User, id)
+ def get_user(id), do: Repo.get(User, id)
+
def get_user_by!(fields), do: Repo.get_by!(User, fields)
def update_active_profile(%User{active_profile_user_id: same_id} = current_user, same_id) do
diff --git a/lib/live_beats_web/channels/presence.ex b/lib/live_beats_web/channels/presence.ex
index 299464d..39ed342 100644
--- a/lib/live_beats_web/channels/presence.ex
+++ b/lib/live_beats_web/channels/presence.ex
@@ -15,7 +15,7 @@ defmodule LiveBeatsWeb.Presence do
~H"""
-
Who's Here
+
Who's Listening
<%= for presence <- @presences do %>
-
diff --git a/lib/live_beats_web/controllers/file_controller.ex b/lib/live_beats_web/controllers/file_controller.ex
index 78cc1c6..97b97b5 100644
--- a/lib/live_beats_web/controllers/file_controller.ex
+++ b/lib/live_beats_web/controllers/file_controller.ex
@@ -7,7 +7,7 @@ defmodule LiveBeatsWeb.FileController do
alias LiveBeats.MediaLibrary
def show(conn, %{"id" => filename_uuid, "token" => token}) do
- case Phoenix.Token.verify(conn, "file", token, max_age: :timer.minutes(10)) do
+ case Phoenix.Token.verify(conn, "file", token, max_age: :timer.minutes(1)) do
{:ok, ^filename_uuid} -> do_send_file(conn, MediaLibrary.local_filepath(filename_uuid))
{:ok, _} -> send_resp(conn, :unauthorized, "")
{:error, _} -> send_resp(conn, :unauthorized, "")
diff --git a/lib/live_beats_web/controllers/redirect_controller.ex b/lib/live_beats_web/controllers/redirect_controller.ex
index fd42b28..7769cdb 100644
--- a/lib/live_beats_web/controllers/redirect_controller.ex
+++ b/lib/live_beats_web/controllers/redirect_controller.ex
@@ -1,6 +1,10 @@
defmodule LiveBeatsWeb.RedirectController do
use LiveBeatsWeb, :controller
+ import LiveBeatsWeb.UserAuth, only: [fetch_current_user: 2]
+
+ plug :fetch_current_user
+
def redirect_authenticated(conn, _) do
if conn.assigns.current_user do
LiveBeatsWeb.UserAuth.redirect_if_user_is_authenticated(conn, [])
diff --git a/lib/live_beats_web/controllers/user_auth.ex b/lib/live_beats_web/controllers/user_auth.ex
index a646cde..eb48ad3 100644
--- a/lib/live_beats_web/controllers/user_auth.ex
+++ b/lib/live_beats_web/controllers/user_auth.ex
@@ -9,7 +9,7 @@ defmodule LiveBeatsWeb.UserAuth do
def on_mount(:current_user, _params, session, socket) do
case session do
%{"user_id" => user_id} ->
- {:cont, LiveView.assign_new(socket, :current_user, fn -> Accounts.get_user!(user_id) end)}
+ {:cont, LiveView.assign_new(socket, :current_user, fn -> Accounts.get_user(user_id) end)}
%{} ->
{:cont, LiveView.assign(socket, :current_user, nil)}
@@ -19,14 +19,21 @@ defmodule LiveBeatsWeb.UserAuth do
def on_mount(:ensure_authenticated, _params, session, socket) do
case session do
%{"user_id" => user_id} ->
- {:cont, LiveView.assign_new(socket, :current_user, fn -> Accounts.get_user!(user_id) end)}
+ new_socket = LiveView.assign_new(socket, :current_user, fn -> Accounts.get_user!(user_id) end)
+ %Accounts.User{} = new_socket.assigns.current_user
+ {:cont, new_socket}
%{} ->
- {:halt,
- socket
- |> LiveView.put_flash(:error, "Please sign in")
- |> LiveView.redirect(to: Routes.sign_in_path(socket, :index))}
+ {:halt, redirect_require_login(socket)}
end
+ rescue
+ Ecto.NoResultsError -> {:halt, redirect_require_login(socket)}
+ end
+
+ defp redirect_require_login(socket) do
+ socket
+ |> LiveView.put_flash(:error, "Please sign in")
+ |> LiveView.redirect(to: Routes.sign_in_path(socket, :index))
end
@doc """
@@ -78,7 +85,7 @@ defmodule LiveBeatsWeb.UserAuth do
"""
def fetch_current_user(conn, _opts) do
user_id = get_session(conn, :user_id)
- user = user_id && Accounts.get_user!(user_id)
+ user = user_id && Accounts.get_user(user_id)
assign(conn, :current_user, user)
end
diff --git a/lib/live_beats_web/live/song_live/index.ex b/lib/live_beats_web/live/song_live/index.ex
index 43d8879..c6d54bf 100644
--- a/lib/live_beats_web/live/song_live/index.ex
+++ b/lib/live_beats_web/live/song_live/index.ex
@@ -13,7 +13,7 @@ defmodule LiveBeatsWeb.SongLive.Index do
<%= @profile.tagline %> <%= if @owns_profile? do %>(you)<% end %>
<.link href={@profile.external_homepage_url} _target="blank" class="block text-sm text-gray-600">
- <.icon name={:code}/> <%= url_text(@profile.external_homepage_url) %>
+ <.icon name={:code}/> <%= url_text(@profile.external_homepage_url) %>
@@ -40,7 +40,6 @@ defmodule LiveBeatsWeb.SongLive.Index do
- <:abbrev let={user}><%= String.first(user.username) %>
<:title let={user}><%= user.username %>
@@ -231,8 +230,8 @@ defmodule LiveBeatsWeb.SongLive.Index do
end
defp assign_presences(socket) do
- # TODO
- assign(socket, presences: Accounts.list_users(limit: 10))
+ users = Accounts.lists_users_by_active_profile(socket.assigns.profile.user_id, limit: 10)
+ assign(socket, presences: users)
end
defp url_text(nil), do: ""
diff --git a/lib/live_beats_web/router.ex b/lib/live_beats_web/router.ex
index 1db8141..b9d0e83 100644
--- a/lib/live_beats_web/router.ex
+++ b/lib/live_beats_web/router.ex
@@ -2,7 +2,7 @@ defmodule LiveBeatsWeb.Router do
use LiveBeatsWeb, :router
import LiveBeatsWeb.UserAuth,
- only: [fetch_current_user: 2, redirect_if_user_is_authenticated: 2]
+ only: [redirect_if_user_is_authenticated: 2]
pipeline :browser do
plug :accepts, ["html"]
@@ -11,7 +11,6 @@ defmodule LiveBeatsWeb.Router do
plug :put_root_layout, {LiveBeatsWeb.LayoutView, :root}
plug :protect_from_forgery
plug :put_secure_browser_headers
- plug :fetch_current_user
end
pipeline :api do
diff --git a/lib/live_beats_web/templates/layout/live.html.heex b/lib/live_beats_web/templates/layout/live.html.heex
index a8bdfd1..2e890b9 100644
--- a/lib/live_beats_web/templates/layout/live.html.heex
+++ b/lib/live_beats_web/templates/layout/live.html.heex
@@ -113,23 +113,25 @@
-
-
-
-
-
+ <%= if @current_user do %>
+
-
+ <% end %>