2019-11-17 19:18:21 +01:00
|
|
|
defmodule PhilomenaWeb.CurrentBanPlug do
|
2019-11-16 01:40:32 +01:00
|
|
|
@moduledoc """
|
|
|
|
This plug loads the ban for the current user.
|
|
|
|
|
|
|
|
## Example
|
|
|
|
|
2019-11-17 19:18:21 +01:00
|
|
|
plug PhilomenaWeb.CurrentBanPlug
|
2019-11-16 01:40:32 +01:00
|
|
|
"""
|
|
|
|
alias Philomena.Bans
|
|
|
|
alias Plug.Conn
|
|
|
|
|
|
|
|
@doc false
|
|
|
|
@spec init(any()) :: any()
|
|
|
|
def init(opts), do: opts
|
|
|
|
|
|
|
|
@doc false
|
|
|
|
@spec call(Conn.t(), any()) :: Conn.t()
|
|
|
|
def call(conn, _opts) do
|
2024-06-08 20:43:10 +02:00
|
|
|
fingerprint = conn.assigns.fingerprint
|
2020-07-28 22:56:26 +02:00
|
|
|
user = conn.assigns.current_user
|
2019-11-16 01:40:32 +01:00
|
|
|
ip = conn.remote_ip
|
|
|
|
|
2024-06-25 02:45:56 +02:00
|
|
|
ban = Bans.find(user, ip, fingerprint)
|
2019-11-16 01:40:32 +01:00
|
|
|
|
2020-11-16 03:00:05 +01:00
|
|
|
Conn.assign(conn, :current_ban, ban)
|
2019-11-16 01:40:32 +01:00
|
|
|
end
|
2020-01-11 05:20:19 +01:00
|
|
|
end
|