[#923] Minor code readability fix.
[akkoma] / lib / pleroma / web / auth / authenticator.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.Auth.Authenticator do
6 alias Pleroma.Registration
7 alias Pleroma.User
8
9 def implementation do
10 Pleroma.Config.get(
11 Pleroma.Web.Auth.Authenticator,
12 Pleroma.Web.Auth.PleromaAuthenticator
13 )
14 end
15
16 @callback get_user(Plug.Conn.t(), Map.t()) :: {:ok, User.t()} | {:error, any()}
17 def get_user(plug, params), do: implementation().get_user(plug, params)
18
19 @callback create_from_registration(Plug.Conn.t(), Map.t(), Registration.t()) ::
20 {:ok, User.t()} | {:error, any()}
21 def create_from_registration(plug, params, registration),
22 do: implementation().create_from_registration(plug, params, registration)
23
24 @callback get_registration(Plug.Conn.t(), Map.t()) ::
25 {:ok, Registration.t()} | {:error, any()}
26 def get_registration(plug, params),
27 do: implementation().get_registration(plug, params)
28
29 @callback handle_error(Plug.Conn.t(), any()) :: any()
30 def handle_error(plug, error), do: implementation().handle_error(plug, error)
31
32 @callback auth_template() :: String.t() | nil
33 def auth_template do
34 implementation().auth_template() || Pleroma.Config.get(:auth_template, "show.html")
35 end
36
37 @callback oauth_consumer_template() :: String.t() | nil
38 def oauth_consumer_template do
39 implementation().oauth_consumer_template() ||
40 Pleroma.Config.get(:oauth_consumer_template, "consumer.html")
41 end
42 end