Add EnsureAuthenticatedPlug
This commit is contained in:
parent
faf5347748
commit
3cf17dc402
2 changed files with 46 additions and 0 deletions
19
lib/pleroma/plugs/ensure_authenticated_plug.ex
Normal file
19
lib/pleroma/plugs/ensure_authenticated_plug.ex
Normal file
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue