Remove vapidPublicKey from Nodeinfo
[akkoma] / lib / pleroma / plugs / ensure_authenticated_plug.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Plugs.EnsureAuthenticatedPlug do
6 import Plug.Conn
7 import Pleroma.Web.TranslationHelpers
8 alias Pleroma.User
9
10 def init(options) do
11 options
12 end
13
14 def call(%{assigns: %{user: %User{}}} = conn, _) do
15 conn
16 end
17
18 def call(conn, options) do
19 perform =
20 cond do
21 options[:if_func] -> options[:if_func].()
22 options[:unless_func] -> !options[:unless_func].()
23 true -> true
24 end
25
26 if perform do
27 fail(conn)
28 else
29 conn
30 end
31 end
32
33 def fail(conn) do
34 conn
35 |> render_error(:forbidden, "Invalid credentials.")
36 |> halt()
37 end
38 end