philomena/lib/philomena_web/plugs/current_ban_plug.ex
parasprite e058a212e7
Removes discourage bans (#65)
Co-authored-by: Parasprite <foalspeedahead@gmail.com>
2020-11-07 00:22:41 -05:00

29 lines
601 B
Elixir

defmodule PhilomenaWeb.CurrentBanPlug do
@moduledoc """
This plug loads the ban for the current user.
## Example
plug PhilomenaWeb.CurrentBanPlug
"""
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)
fingerprint = conn.cookies["_ses"]
user = conn.assigns.current_user
ip = conn.remote_ip
ban = Bans.exists_for?(user, ip, fingerprint)
Conn.assign(conn, :current_ban, ban)
end
end