philomena/lib/philomena_web/plugs/current_ban_plug.ex

30 lines
600 B
Elixir
Raw Normal View History

2019-11-17 13:18:21 -05:00
defmodule PhilomenaWeb.CurrentBanPlug do
2019-11-15 19:40:32 -05:00
@moduledoc """
This plug loads the ban for the current user.
## Example
2019-11-17 13:18:21 -05:00
plug PhilomenaWeb.CurrentBanPlug
2019-11-15 19:40:32 -05: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
conn = Conn.fetch_cookies(conn)
2019-11-15 19:40:32 -05:00
fingerprint = conn.cookies["_ses"]
user = conn.assigns.current_user
2019-11-15 19:40:32 -05:00
ip = conn.remote_ip
ban = Bans.exists_for?(user, ip, fingerprint)
Conn.assign(conn, :current_ban, ban)
2019-11-15 19:40:32 -05:00
end
2020-01-10 23:20:19 -05:00
end