mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 20:18:00 +01:00
don't bump ratelimit after unsuccessful attempts
This commit is contained in:
parent
aefc79eb8e
commit
6a045ce88e
1 changed files with 16 additions and 5 deletions
|
@ -31,12 +31,9 @@ defmodule PhilomenaWeb.LimitPlug do
|
|||
]
|
||||
|
||||
key = "rl-#{Enum.join(data, "")}"
|
||||
amt = Redix.command!(:redix, ["GET", key]) || 0
|
||||
|
||||
[amt, _] =
|
||||
Redix.pipeline!(:redix, [
|
||||
["INCR", key],
|
||||
["EXPIRE", key, time]
|
||||
])
|
||||
conn = increment_after_post(conn, key, time)
|
||||
|
||||
cond do
|
||||
amt <= limit ->
|
||||
|
@ -86,4 +83,18 @@ defmodule PhilomenaWeb.LimitPlug do
|
|||
_ -> false
|
||||
end
|
||||
end
|
||||
|
||||
defp increment_after_post(conn, key, time) do
|
||||
Conn.register_before_send(conn, fn conn ->
|
||||
# Phoenix status returns 200 for form validation errors
|
||||
if conn.status != 200 do
|
||||
Redix.pipeline!(:redix, [
|
||||
["INCR", key],
|
||||
["EXPIRE", key, time]
|
||||
])
|
||||
end
|
||||
|
||||
conn
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue