Dynavera/apps/accounts/management/commands/reset_passwords.py

17 lines
618 B
Python
Raw Normal View History

from django.core.management.base import BaseCommand
from django.contrib.auth import get_user_model
User = get_user_model()
class Command(BaseCommand):
help = 'Resets non-admin account passwords to "password" and admin account passwords to "admin"'
def handle(self, *args, **kwargs):
users = User.objects.all()
for user in users:
if user.is_staff:
user.set_password('admin')
else:
user.set_password('password')
user.save()
self.stdout.write(self.style.SUCCESS(f"Successfully updated {users.count()} users."))