perf: save_passwd_change filter user source local and passwords not emtpy (#13680)

Co-authored-by: feng <1304903146@qq.com>
pull/13682/head
fit2bot 2024-07-10 14:25:43 +08:00 committed by GitHub
parent cf727d22c0
commit 81027cd561
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 10 deletions

View File

@ -65,22 +65,15 @@ def user_authenticated_handle(user, created, source, attrs=None, **kwargs):
@receiver(post_save, sender=User)
def save_passwd_change(sender, instance: User, **kwargs):
if instance.source != User.Source.local.value:
if instance.source != User.Source.local.value or not instance.password:
return
passwords = UserPasswordHistory.objects \
.filter(user=instance) \
.order_by('-date_created') \
.values_list('password', flat=True)
passwords = passwords[:int(settings.OLD_PASSWORD_HISTORY_LIMIT_COUNT)]
.values_list('password', flat=True)[:settings.OLD_PASSWORD_HISTORY_LIMIT_COUNT]
if not passwords:
return
for p in passwords:
if instance.password == p:
break
else:
if instance.password not in list(passwords):
UserPasswordHistory.objects.create(
user=instance, password=instance.password,
date_created=instance.date_password_last_updated