mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-30 14:57:59 +01:00
update connecting ip in session
This commit is contained in:
parent
d1093a80b0
commit
1436c7ff06
2 changed files with 25 additions and 0 deletions
|
@ -47,5 +47,6 @@ defmodule PhilomenaWeb.Endpoint do
|
||||||
|
|
||||||
plug PhilomenaWeb.RenderTimePlug
|
plug PhilomenaWeb.RenderTimePlug
|
||||||
plug PhilomenaWeb.ReferrerPlug
|
plug PhilomenaWeb.ReferrerPlug
|
||||||
|
plug PhilomenaWeb.LastIpPlug
|
||||||
plug PhilomenaWeb.Router
|
plug PhilomenaWeb.Router
|
||||||
end
|
end
|
||||||
|
|
24
lib/philomena_web/plugs/last_ip_plug.ex
Normal file
24
lib/philomena_web/plugs/last_ip_plug.ex
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
defmodule PhilomenaWeb.LastIpPlug do
|
||||||
|
@moduledoc """
|
||||||
|
This plug stores the connecting IP address in the session.
|
||||||
|
## Example
|
||||||
|
|
||||||
|
plug PhilomenaWeb.LastIpPlug
|
||||||
|
"""
|
||||||
|
|
||||||
|
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
|
||||||
|
{:ok, ip} = EctoNetwork.INET.cast(conn.remote_ip)
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> Conn.fetch_session()
|
||||||
|
|> Conn.put_session(:remote_ip, to_string(ip))
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue