set password in welcome script

This commit is contained in:
Diego Calvo
2021-04-05 09:46:26 +02:00
parent 50ada7c6b6
commit 7bdda999d8
2 changed files with 19 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
from django.core.management.base import BaseCommand
from django.core.mail import EmailMessage
from django.template.loader import render_to_string
from core import utils
from core.models import CustomUser
@@ -11,9 +12,16 @@ class Command(BaseCommand):
managers = CustomUser.objects.filter(role='COOP_MANAGER')
for manager in managers:
try:
password = utils.generate_password(12)
manager.set_password(password)
manager.save()
except:
return Response({'error': f"Could not set new password [{str(type(e))}]: {str(e)}"}, status=500)
link = "https://latienda.coop/login"
company_message = render_to_string('welcome_coop.html', {
'manager': manager,
'password': password,
'link': link
})
# send email to company