Add ipban for failed login attempt in new login flow (#15551)

* Add ipban for failed login attempt in new login flow

* Address review comment

* Use decorator to clean up code
This commit is contained in:
Jason Hu authored and Paulus Schoutsen committed 2018-07-24 10:09:52 +02:00
1 parent 45c35ceb2b
commit d7690c5fda
2 files changed
+21 -1

No files matched your search

+11 -1
View File
@@ -1,5 +1,4 @@
"""Ban logic for HTTP component."""
from collections import defaultdict
from datetime import datetime
from ipaddress import ip_address
@@ -71,6 +70,17 @@ async def ban_middleware(request, handler):
raise
def log_invalid_auth(func):
"""Decorator to handle invalid auth or failed login attempts."""
async def handle_req(view, request, *args, **kwargs):
"""Try to log failed login attempts if response status >= 400."""
resp = await func(view, request, *args, **kwargs)
if resp.status >= 400:
await process_wrong_login(request)
return resp
return handle_req
async def process_wrong_login(request):
"""Process a wrong login attempt.