feat: add join form
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Simon 2026-03-10 18:25:17 +01:00
parent eadf90b5fc
commit f1d0526209
Signed by: simon
GPG key ID: 40E7A58C4AA1EDB2
19 changed files with 547 additions and 15 deletions

View file

@ -0,0 +1,27 @@
defmodule MvWeb.JoinRateLimit do
@moduledoc """
Rate limiting for the public join form (submit action).
Uses Hammer with ETS backend. Key is derived from client IP so each IP
is limited independently. Config from :mv :join_rate_limit (scale_ms, limit).
"""
use Hammer, backend: :ets
@doc """
Checks if the given key (e.g. client IP) is within rate limit for join form submit.
Returns:
- `:allow` - submission allowed
- `{:deny, _retry_after_ms}` - rate limit exceeded
"""
def check(key) when is_binary(key) do
config = Application.get_env(:mv, :join_rate_limit, [])
scale_ms = Keyword.get(config, :scale_ms, 60_000)
limit = Keyword.get(config, :limit, 10)
case hit(key, scale_ms, limit) do
{:allow, _count} -> :allow
{:deny, retry_after} -> {:deny, retry_after}
end
end
end