mirror of
https://github.com/fly-apps/live_beats.git
synced 2024-11-21 15:41: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
|
||||
"""
|
||||
|
||||
app_name = System.fetch_env!("FLY_APP_NAME")
|
||||
host = System.get_env("URL_HOST") || "example.com"
|
||||
|
||||
config :live_beats, LiveBeatsWeb.Endpoint,
|
||||
|
|
6
fly.toml
6
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"]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -15,7 +15,7 @@ defmodule LiveBeatsWeb.Presence do
|
|||
~H"""
|
||||
<!-- users -->
|
||||
<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">
|
||||
<%= for presence <- @presences do %>
|
||||
<li class="relative col-span-1 flex shadow-sm rounded-md overflow-hidden">
|
||||
|
|
|
@ -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, "")
|
||||
|
|
|
@ -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, [])
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ defmodule LiveBeatsWeb.SongLive.Index do
|
|||
<%= @profile.tagline %> <%= if @owns_profile? do %>(you)<% end %>
|
||||
</div>
|
||||
<.link href={@profile.external_homepage_url} _target="blank" class="block text-sm text-gray-600">
|
||||
<.icon name={:code}/> <span class=""><%= url_text(@profile.external_homepage_url) %></span>
|
||||
<.icon name={:code}/> <span class=""><%= url_text(@profile.external_homepage_url) %></span>
|
||||
</.link>
|
||||
</div>
|
||||
|
||||
|
@ -40,7 +40,6 @@ defmodule LiveBeatsWeb.SongLive.Index do
|
|||
</.title_bar>
|
||||
|
||||
<Presence.listening_now presences={@presences}>
|
||||
<:abbrev let={user}><%= String.first(user.username) %></:abbrev>
|
||||
<:title let={user}><%= user.username %></:title>
|
||||
</Presence.listening_now>
|
||||
|
||||
|
@ -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: ""
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -113,23 +113,25 @@
|
|||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="flex items-center">
|
||||
<!-- Profile dropdown TODO -->
|
||||
<div @keydown.escape.stop="open = false" @click.away="open = false" class="ml-3 relative">
|
||||
<div>
|
||||
<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"
|
||||
id="user-menu-button" @click="open = true"
|
||||
aria-expanded="false" aria-haspopup="true"
|
||||
>
|
||||
<span class="sr-only">Open user menu</span>
|
||||
<img class="h-8 w-8 rounded-full"
|
||||
src={@current_user.avatar_url}
|
||||
alt="">
|
||||
</button>
|
||||
<%= if @current_user do %>
|
||||
<div class="flex items-center">
|
||||
<!-- Profile dropdown TODO -->
|
||||
<div class="ml-3 relative">
|
||||
<div>
|
||||
<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"
|
||||
id="user-menu-button" @click="open = true"
|
||||
aria-expanded="false" aria-haspopup="true"
|
||||
>
|
||||
<span class="sr-only">Open user menu</span>
|
||||
<img class="h-8 w-8 rounded-full"
|
||||
src={@current_user.avatar_url}
|
||||
alt="">
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Reference in a new issue