aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorlain <lain@soykaf.club>2018-09-05 17:59:19 +0200
committerlain <lain@soykaf.club>2018-09-05 17:59:19 +0200
commit3cf17dc402ceab7f823edc263ad09af7013d0646 (patch)
tree6914d3cc45b874859621789c18d55812b161ef2a /lib
parentfaf53477488edfc6ba4268529f9945a494f30aee (diff)
downloadpleroma-3cf17dc402ceab7f823edc263ad09af7013d0646.tar.gz
Add EnsureAuthenticatedPlug
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/plugs/ensure_authenticated_plug.ex19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/pleroma/plugs/ensure_authenticated_plug.ex b/lib/pleroma/plugs/ensure_authenticated_plug.ex
new file mode 100644
index 000000000..bca44eb2c
--- /dev/null
+++ b/lib/pleroma/plugs/ensure_authenticated_plug.ex
@@ -0,0 +1,19 @@
+defmodule Pleroma.Plugs.EnsureAuthenticatedPlug do
+ import Plug.Conn
+ alias Pleroma.User
+
+ def init(options) do
+ options
+ end
+
+ def call(%{assigns: %{user: %User{}}} = conn, _) do
+ conn
+ end
+
+ def call(conn, _) do
+ conn
+ |> put_resp_content_type("application/json")
+ |> send_resp(403, Jason.encode!(%{error: "Invalid credentials."}))
+ |> halt
+ end
+end