diff --git a/lib/lsg_web/context_plug.ex b/lib/lsg_web/context_plug.ex index 29eab28..aaf851e 100644 --- a/lib/lsg_web/context_plug.ex +++ b/lib/lsg_web/context_plug.ex @@ -1,91 +1,92 @@ defmodule LSGWeb.ContextPlug do import Plug.Conn import Phoenix.Controller def init(opts \\ []) do opts || [] end def get_account(conn) do cond do get_session(conn, :account) -> get_session(conn, :account) get_session(conn, :oidc_id) -> if account = IRC.Account.find_meta_account("identity-id", get_session(conn, :oidc_id)), do: account.id + true -> nil end end def call(conn, opts) do account = with \ {:account, account_id} when is_binary(account_id) <- {:account, get_account(conn)}, {:account, account} when not is_nil(account) <- {:account, IRC.Account.get(account_id)} do account else _ -> nil end network = Map.get(conn.params, "network") network = if network == "-", do: nil, else: network oidc_account = IRC.Account.find_meta_account("identity-id", get_session(conn, :oidc_id)) conns = IRC.Connection.get_network(network) chan = if c = Map.get(conn.params, "chan") do LSGWeb.reformat_chan(c) end chan_conn = IRC.Connection.get_network(network, chan) memberships = if account do IRC.Membership.of_account(account) end auth_required = cond do Keyword.get(opts, :restrict) == :public -> false account == nil -> true network == nil -> false Keyword.get(opts, :restrict) == :logged_in -> false network && chan -> !Enum.member?(memberships, {network, chan}) network -> !Enum.any?(memberships, fn({n, _}) -> n == network end) end bot = cond do network && chan && chan_conn -> chan_conn.nick network && conns -> conns.nick true -> nil end cond do account && auth_required -> conn |> put_status(404) |> text("Page not found") |> halt() auth_required -> conn |> put_status(403) |> render(LSGWeb.AlcoologView, "auth.html", bot: bot, no_header: true, network: network) |> halt() (network && !conns) -> conn |> put_status(404) |> text("Page not found") |> halt() (chan && !chan_conn) -> conn |> put_status(404) |> text("Page not found") |> halt() true -> conn = conn |> assign(:network, network) |> assign(:chan, chan) |> assign(:bot, bot) |> assign(:account, account) |> assign(:oidc_account, oidc_account) |> assign(:memberships, memberships) end end end diff --git a/lib/lsg_web/templates/alcoolog/index.html.eex b/lib/lsg_web/templates/alcoolog/index.html.eex index 3f522e9..263da95 100644 --- a/lib/lsg_web/templates/alcoolog/index.html.eex +++ b/lib/lsg_web/templates/alcoolog/index.html.eex @@ -1,206 +1,205 @@ <%= if @stats == [] do %>
<%= status.last_cl %>cl @ <%= status.last_deg %>°
<%= if status.last_descr && status.last_descr != "" do %>
<%= status.last_descr %>
<% end %>
<%= LSGWeb.LayoutView.format_time(status.last_at) %>
— sobre dans: <%= status.sober_in_s %>
<%= if status.since do %>
— depuis: <%= status.since_s %>
<% end %>
— 15m: <%= status.active15m %> g/l - 30m: <%= status.active30m %> g/l - 1h: <%= status.active1h %> g/l
— aujourd'hui: <%= status.daily_volumes %> points, <%= status.daily_gl %> g/l
date | nick | ||
---|---|---|---|
<%= LSGWeb.LayoutView.format_time(date, false) %> | <%= link nick, to: alcoolog_path(@conn, :nick, @network, nick) %> | <%= cl %>cl <%= deg %>° | <%= comment||"" %> |