summaryrefslogtreecommitdiff
path: root/lib/lsg_web/controllers/page_controller.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/lsg_web/controllers/page_controller.ex')
-rw-r--r--lib/lsg_web/controllers/page_controller.ex50
1 files changed, 36 insertions, 14 deletions
diff --git a/lib/lsg_web/controllers/page_controller.ex b/lib/lsg_web/controllers/page_controller.ex
index b356b9c..a87cf1d 100644
--- a/lib/lsg_web/controllers/page_controller.ex
+++ b/lib/lsg_web/controllers/page_controller.ex
@@ -1,12 +1,35 @@
defmodule LSGWeb.PageController do
use LSGWeb, :controller
- def index(conn, _params) do
- render conn, "index.html"
+ plug LSGWeb.ContextPlug when action not in [:token]
+ plug LSGWeb.ContextPlug, [restrict: :public] when action in [:token]
+
+ def token(conn, %{"token" => token}) do
+ with \
+ {:ok, account, perks} <- LSG.AuthToken.lookup(token)
+ do
+ IO.puts("Authenticated account #{inspect account}")
+ conn = put_session(conn, :account, account)
+ case perks do
+ nil -> redirect(conn, to: "/")
+ {:redirect, path} -> redirect(conn, to: path)
+ {:external_redirect, url} -> redirect(conn, external: url)
+ end
+ else
+ z ->
+ IO.inspect(z)
+ text(conn, "Error: invalid or expired token")
+ end
end
- def api(conn, _params) do
- render conn, "api.html"
+ def index(conn = %{assigns: %{account: account}}, _) do
+ memberships = IRC.Membership.of_account(account)
+ users = IRC.UserTrack.find_by_account(account)
+ metas = IRC.Account.get_all_meta(account)
+ predicates = IRC.Account.get_predicates(account)
+ conn
+ |> assign(:title, account.name)
+ |> render("user.html", users: users, memberships: memberships, metas: metas, predicates: predicates)
end
def irc(conn, _) do
@@ -16,16 +39,15 @@ defmodule LSGWeb.PageController do
render conn, "irc.html", bot_helps: bot_helps
end
- def icecast(conn, _params) do
- conn
- |> json(LSG.IcecastAgent.get)
- end
-
- def widget(conn, options) do
- icecast = LSG.IcecastAgent.get
- conn
- |> put_layout(false)
- |> render("widget.html", icecast: icecast)
+ def authenticate(conn, _) do
+ with \
+ {:account, account_id} when is_binary(account_id) <- {:account, get_session(conn, :account)},
+ {:account, account} when not is_nil(account) <- {:account, IRC.Account.get(account_id)}
+ do
+ assign(conn, :account, account)
+ else
+ _ -> conn
+ end
end
end