diff options
author | Aaron Tinio <aptinio@gmail.com> | 2019-05-14 08:21:44 +0800 |
---|---|---|
committer | Aaron Tinio <aptinio@gmail.com> | 2019-05-15 05:09:29 +0800 |
commit | 7b8dc99ef106314f1418ff1c314b47cf58a3c2d2 (patch) | |
tree | fa0c18f5aa2f3613b0feb159aa82cb75d1713a40 /lib | |
parent | c133c32ef07077daaf581a4f890939b38c1d7feb (diff) | |
download | pleroma-7b8dc99ef106314f1418ff1c314b47cf58a3c2d2.tar.gz |
Implement Pleroma.Plugs.EnsurePublicOrAuthenticated
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/plugs/ensure_public_or_authenticated_plug.ex | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/pleroma/plugs/ensure_public_or_authenticated_plug.ex b/lib/pleroma/plugs/ensure_public_or_authenticated_plug.ex new file mode 100644 index 000000000..317fd5445 --- /dev/null +++ b/lib/pleroma/plugs/ensure_public_or_authenticated_plug.ex @@ -0,0 +1,31 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug do + import Plug.Conn + alias Pleroma.Config + alias Pleroma.User + + def init(options) do + options + end + + def call(conn, _) do + public? = Config.get!([:instance, :public]) + + case {public?, conn} do + {true, _} -> + conn + + {false, %{assigns: %{user: %User{}}}} -> + conn + + {false, _} -> + conn + |> put_resp_content_type("application/json") + |> send_resp(403, Jason.encode!(%{error: "This resource requires authentication."})) + |> halt + end + end +end |