Rate limiting
The throttle middleware limits whole routes. @rate_limit() from KScript.Cache limits anything else, such as password resets per email:
<import package="KScript.Http" />
<import package="KScript.Auth" />
<import package="KScript.Cache" />
<fn name="send_reset" params="form: map">
<do>@rate_limit("reset:{ $form.email }", limit: 5, per: 1h)->attempt(fn() => @reset_token($form.email))</do>
<return value="@redirect_back('/forgot')" />
</fn>import KScript.Http
import KScript.Auth
import KScript.Cache
fn send_reset(form: map) {
@rate_limit("reset:{ $form.email }", limit: 5, per: 1h)->attempt(fn() => @reset_token($form.email))
return @redirect_back('/forgot')
}Past the limit, ->attempt() throws TooManyRequests, which a route answers with 429 and Retry-After.