User activity file includes failed logins matched by phone
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
ناهماهنگ نمیشود. تصمیمِ ادغامنکردنِ اینها در یک جدول: ستونهایشان فرق دارد.
|
||||
آزموده نشده: کاربری با دهها هزار ردیف (همهی ردیفها در حافظه میآیند).
|
||||
"""
|
||||
from django.db.models import Q
|
||||
from django.utils import timezone
|
||||
|
||||
from payment.models import Order
|
||||
@@ -19,7 +20,9 @@ COLUMNS = ['زمان', 'نوع', 'شرح', 'مبلغ', 'آیپی']
|
||||
|
||||
def user_activity(user: User) -> list[dict]:
|
||||
rows = [{'at': user.created_at, 'kind': 'ثبتنام', 'detail': '', 'amount': '', 'ip': ''}]
|
||||
for e in LoginEvent.objects.filter(user_id=user.id):
|
||||
# ورودِ ناموفق هنوز user_id ندارد (کاربر معلوم نیست)، پس با شماره هم میگیریم.
|
||||
by_user = Q(user_id=user.id) | (Q(phone=user.phone) if user.phone else Q(pk__in=[]))
|
||||
for e in LoginEvent.objects.filter(by_user):
|
||||
rows.append({'at': e.created_at, 'kind': _EVENT_FA.get(e.event, e.event),
|
||||
'detail': e.user_agent[:80], 'amount': '', 'ip': e.ip or ''})
|
||||
orders = list(Order.objects.filter(user_id=user.id))
|
||||
|
||||
Reference in New Issue
Block a user