mirror of
https://github.com/fly-apps/live_beats.git
synced 2024-11-22 08:01:00 +00:00
Fixup profiles
This commit is contained in:
parent
364b0659e1
commit
2f4940fab6
10 changed files with 54 additions and 32 deletions
|
@ -29,7 +29,6 @@ if config_env() == :prod do
|
||||||
You can generate one by calling: mix phx.gen.secret
|
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"
|
host = System.get_env("URL_HOST") || "example.com"
|
||||||
|
|
||||||
config :live_beats, LiveBeatsWeb.Endpoint,
|
config :live_beats, LiveBeatsWeb.Endpoint,
|
||||||
|
|
6
fly.toml
6
fly.toml
|
@ -11,6 +11,10 @@ processes = []
|
||||||
IPV6 = 1
|
IPV6 = 1
|
||||||
URL_HOST = "livebeats.fly.dev"
|
URL_HOST = "livebeats.fly.dev"
|
||||||
|
|
||||||
|
[mounts]
|
||||||
|
source="data"
|
||||||
|
destination="/app/live_beats/lib/live_beats-0.1.0/priv/uploads"
|
||||||
|
|
||||||
[experimental]
|
[experimental]
|
||||||
allowed_public_ports = []
|
allowed_public_ports = []
|
||||||
auto_rollback = true
|
auto_rollback = true
|
||||||
|
@ -25,7 +29,7 @@ processes = []
|
||||||
[services.concurrency]
|
[services.concurrency]
|
||||||
hard_limit = 25
|
hard_limit = 25
|
||||||
soft_limit = 20
|
soft_limit = 20
|
||||||
type = "connections"
|
type = "requests"
|
||||||
|
|
||||||
[[services.ports]]
|
[[services.ports]]
|
||||||
handlers = ["http"]
|
handlers = ["http"]
|
||||||
|
|
|
@ -21,6 +21,12 @@ defmodule LiveBeats.Accounts do
|
||||||
Repo.all(from u in User, limit: ^Keyword.fetch!(opts, :limit))
|
Repo.all(from u in User, limit: ^Keyword.fetch!(opts, :limit))
|
||||||
end
|
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
|
def admin?(%User{} = user) do
|
||||||
user.email in Application.fetch_env!(:live_beats, :admin_emails)
|
user.email in Application.fetch_env!(:live_beats, :admin_emails)
|
||||||
end
|
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(id), do: Repo.get(User, id)
|
||||||
|
|
||||||
def get_user_by!(fields), do: Repo.get_by!(User, fields)
|
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
|
def update_active_profile(%User{active_profile_user_id: same_id} = current_user, same_id) do
|
||||||
|
|
|
@ -15,7 +15,7 @@ defmodule LiveBeatsWeb.Presence do
|
||||||
~H"""
|
~H"""
|
||||||
<!-- users -->
|
<!-- users -->
|
||||||
<div class="px-4 mt-6 sm:px-6 lg:px-8">
|
<div class="px-4 mt-6 sm:px-6 lg:px-8">
|
||||||
<h2 class="text-gray-500 text-xs font-medium uppercase tracking-wide">Who's Here</h2>
|
<h2 class="text-gray-500 text-xs font-medium uppercase tracking-wide">Who's Listening</h2>
|
||||||
<ul role="list" class="grid grid-cols-1 gap-4 sm:gap-4 sm:grid-cols-2 xl:grid-cols-5 mt-3" x-max="1">
|
<ul role="list" class="grid grid-cols-1 gap-4 sm:gap-4 sm:grid-cols-2 xl:grid-cols-5 mt-3" x-max="1">
|
||||||
<%= for presence <- @presences do %>
|
<%= for presence <- @presences do %>
|
||||||
<li class="relative col-span-1 flex shadow-sm rounded-md overflow-hidden">
|
<li class="relative col-span-1 flex shadow-sm rounded-md overflow-hidden">
|
||||||
|
|
|
@ -7,7 +7,7 @@ defmodule LiveBeatsWeb.FileController do
|
||||||
alias LiveBeats.MediaLibrary
|
alias LiveBeats.MediaLibrary
|
||||||
|
|
||||||
def show(conn, %{"id" => filename_uuid, "token" => token}) do
|
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, ^filename_uuid} -> do_send_file(conn, MediaLibrary.local_filepath(filename_uuid))
|
||||||
{:ok, _} -> send_resp(conn, :unauthorized, "")
|
{:ok, _} -> send_resp(conn, :unauthorized, "")
|
||||||
{:error, _} -> send_resp(conn, :unauthorized, "")
|
{:error, _} -> send_resp(conn, :unauthorized, "")
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
defmodule LiveBeatsWeb.RedirectController do
|
defmodule LiveBeatsWeb.RedirectController do
|
||||||
use LiveBeatsWeb, :controller
|
use LiveBeatsWeb, :controller
|
||||||
|
|
||||||
|
import LiveBeatsWeb.UserAuth, only: [fetch_current_user: 2]
|
||||||
|
|
||||||
|
plug :fetch_current_user
|
||||||
|
|
||||||
def redirect_authenticated(conn, _) do
|
def redirect_authenticated(conn, _) do
|
||||||
if conn.assigns.current_user do
|
if conn.assigns.current_user do
|
||||||
LiveBeatsWeb.UserAuth.redirect_if_user_is_authenticated(conn, [])
|
LiveBeatsWeb.UserAuth.redirect_if_user_is_authenticated(conn, [])
|
||||||
|
|
|
@ -9,7 +9,7 @@ defmodule LiveBeatsWeb.UserAuth do
|
||||||
def on_mount(:current_user, _params, session, socket) do
|
def on_mount(:current_user, _params, session, socket) do
|
||||||
case session do
|
case session do
|
||||||
%{"user_id" => user_id} ->
|
%{"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)}
|
{:cont, LiveView.assign(socket, :current_user, nil)}
|
||||||
|
@ -19,14 +19,21 @@ defmodule LiveBeatsWeb.UserAuth do
|
||||||
def on_mount(:ensure_authenticated, _params, session, socket) do
|
def on_mount(:ensure_authenticated, _params, session, socket) do
|
||||||
case session do
|
case session do
|
||||||
%{"user_id" => user_id} ->
|
%{"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,
|
{:halt, redirect_require_login(socket)}
|
||||||
|
end
|
||||||
|
rescue
|
||||||
|
Ecto.NoResultsError -> {:halt, redirect_require_login(socket)}
|
||||||
|
end
|
||||||
|
|
||||||
|
defp redirect_require_login(socket) do
|
||||||
socket
|
socket
|
||||||
|> LiveView.put_flash(:error, "Please sign in")
|
|> LiveView.put_flash(:error, "Please sign in")
|
||||||
|> LiveView.redirect(to: Routes.sign_in_path(socket, :index))}
|
|> LiveView.redirect(to: Routes.sign_in_path(socket, :index))
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
@ -78,7 +85,7 @@ defmodule LiveBeatsWeb.UserAuth do
|
||||||
"""
|
"""
|
||||||
def fetch_current_user(conn, _opts) do
|
def fetch_current_user(conn, _opts) do
|
||||||
user_id = get_session(conn, :user_id)
|
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)
|
assign(conn, :current_user, user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,6 @@ defmodule LiveBeatsWeb.SongLive.Index do
|
||||||
</.title_bar>
|
</.title_bar>
|
||||||
|
|
||||||
<Presence.listening_now presences={@presences}>
|
<Presence.listening_now presences={@presences}>
|
||||||
<:abbrev let={user}><%= String.first(user.username) %></:abbrev>
|
|
||||||
<:title let={user}><%= user.username %></:title>
|
<:title let={user}><%= user.username %></:title>
|
||||||
</Presence.listening_now>
|
</Presence.listening_now>
|
||||||
|
|
||||||
|
@ -231,8 +230,8 @@ defmodule LiveBeatsWeb.SongLive.Index do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp assign_presences(socket) do
|
defp assign_presences(socket) do
|
||||||
# TODO
|
users = Accounts.lists_users_by_active_profile(socket.assigns.profile.user_id, limit: 10)
|
||||||
assign(socket, presences: Accounts.list_users(limit: 10))
|
assign(socket, presences: users)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp url_text(nil), do: ""
|
defp url_text(nil), do: ""
|
||||||
|
|
|
@ -2,7 +2,7 @@ defmodule LiveBeatsWeb.Router do
|
||||||
use LiveBeatsWeb, :router
|
use LiveBeatsWeb, :router
|
||||||
|
|
||||||
import LiveBeatsWeb.UserAuth,
|
import LiveBeatsWeb.UserAuth,
|
||||||
only: [fetch_current_user: 2, redirect_if_user_is_authenticated: 2]
|
only: [redirect_if_user_is_authenticated: 2]
|
||||||
|
|
||||||
pipeline :browser do
|
pipeline :browser do
|
||||||
plug :accepts, ["html"]
|
plug :accepts, ["html"]
|
||||||
|
@ -11,7 +11,6 @@ defmodule LiveBeatsWeb.Router do
|
||||||
plug :put_root_layout, {LiveBeatsWeb.LayoutView, :root}
|
plug :put_root_layout, {LiveBeatsWeb.LayoutView, :root}
|
||||||
plug :protect_from_forgery
|
plug :protect_from_forgery
|
||||||
plug :put_secure_browser_headers
|
plug :put_secure_browser_headers
|
||||||
plug :fetch_current_user
|
|
||||||
end
|
end
|
||||||
|
|
||||||
pipeline :api do
|
pipeline :api do
|
||||||
|
|
|
@ -113,9 +113,10 @@
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
<%= if @current_user do %>
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
<!-- Profile dropdown TODO -->
|
<!-- Profile dropdown TODO -->
|
||||||
<div @keydown.escape.stop="open = false" @click.away="open = false" class="ml-3 relative">
|
<div class="ml-3 relative">
|
||||||
<div>
|
<div>
|
||||||
<button type="button"
|
<button type="button"
|
||||||
class="max-w-xs bg-white flex items-center text-sm rounded-full focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-purple-500"
|
class="max-w-xs bg-white flex items-center text-sm rounded-full focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-purple-500"
|
||||||
|
@ -130,6 +131,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue