philomena/lib/philomena_web/plugs/current_ban_plug.ex

33 lines
631 B
Elixir
Raw Normal View History

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
alias Pow.Plug
@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
|> Conn.fetch_cookies()
fingerprint = conn.cookies["_ses"]
user = Plug.current_user(conn)
ip = conn.remote_ip
ban = Bans.exists_for?(user, ip, fingerprint)
Conn.assign(conn, :current_ban, ban)
end
2020-01-11 05:20:19 +01:00
end