allauth/decorators.py
raw| 1 | from __future__ import annotations |
| 2 | |
| 3 | from functools import wraps |
| 4 | |
| 5 | from django.http import HttpRequest |
| 6 | |
| 7 | from allauth.core import ratelimit |
| 8 | |
| 9 | |
| 10 | def rate_limit(*, action, **rl_kwargs): |
| 11 | def decorator(function): |
| 12 | @wraps(function) |
| 13 | def wrap(request: HttpRequest, *args, **kwargs): |
| 14 | resp = ratelimit.consume_or_429(request, action=action, **rl_kwargs) |
| 15 | if not resp: |
| 16 | resp = function(request, *args, **kwargs) |
| 17 | return resp |
| 18 | |
| 19 | return wrap |
| 20 | |
| 21 | return decorator |