diff --git a/Back-End/Subscriptions/serializers.py b/Back-End/Subscriptions/serializers.py index e9d4ee5..3191a7e 100644 --- a/Back-End/Subscriptions/serializers.py +++ b/Back-End/Subscriptions/serializers.py @@ -21,6 +21,7 @@ from N3wtSchool import settings from django.utils import timezone import pytz import Subscriptions.util as util +from N3wtSchool.mailManager import sendRegisterForm class AbsenceManagementSerializer(serializers.ModelSerializer): student_name = serializers.SerializerMethodField() @@ -215,6 +216,14 @@ class StudentSerializer(serializers.ModelSerializer): profile_role_serializer = ProfileRoleSerializer(data=profile_role_data) profile_role_serializer.is_valid(raise_exception=True) profile_role = profile_role_serializer.save() + # Envoi du mail d'inscription si un nouveau profil vient d'être créé + email = None + if profile_data and 'email' in profile_data: + email = profile_data['email'] + elif profile_role and profile_role.profile: + email = profile_role.profile.email + if email: + sendRegisterForm(email, establishment_id) elif profile_role: # Récupérer un ProfileRole existant par son ID profile_role = ProfileRole.objects.get(id=profile_role.id) diff --git a/Back-End/Subscriptions/views/register_form_views.py b/Back-End/Subscriptions/views/register_form_views.py index d7e6e93..51e0caf 100644 --- a/Back-End/Subscriptions/views/register_form_views.py +++ b/Back-End/Subscriptions/views/register_form_views.py @@ -323,6 +323,27 @@ class RegisterFormWithIdView(APIView): registerForm.registration_file = util.rfToPDF(registerForm, initial_pdf) registerForm.save() + # Envoi du mail d'inscription au second guardian si besoin + guardians = registerForm.student.guardians.all() + from Auth.models import Profile + from N3wtSchool.mailManager import sendRegisterForm + + for guardian in guardians: + # Recherche de l'email dans le profil lié au guardian (si existant) + email = None + if hasattr(guardian, "profile_role") and guardian.profile_role and hasattr(guardian.profile_role, "profile") and guardian.profile_role.profile: + email = guardian.profile_role.profile.email + # Fallback sur le champ email direct (si jamais il existe) + if not email: + email = getattr(guardian, "email", None) + logger.error(f"[RF_UNDER_REVIEW] Guardian id={guardian.id}, email={email}") + if email: + profile_exists = Profile.objects.filter(email=email).exists() + logger.error(f"[RF_UNDER_REVIEW] Profile existe pour {email} ? {profile_exists}") + if not profile_exists: + logger.error(f"[RF_UNDER_REVIEW] Envoi du mail d'inscription à {email} pour l'établissement {registerForm.establishment.pk}") + sendRegisterForm(email, registerForm.establishment.pk) + # Mise à jour de l'automate # Vérification de la présence du fichier SEPA if registerForm.sepa_file: @@ -332,6 +353,9 @@ class RegisterFormWithIdView(APIView): # Mise à jour de l'automate pour une signature classique updateStateMachine(registerForm, 'EVENT_SIGNATURE') except Exception as e: + logger.error(f"[RF_UNDER_REVIEW] Exception: {e}") + import traceback + logger.error(traceback.format_exc()) return JsonResponse({'error': str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) elif _status == RegistrationForm.RegistrationFormStatus.RF_SENT: if registerForm.status == RegistrationForm.RegistrationFormStatus.RF_UNDER_REVIEW: diff --git a/Front-End/src/components/Inscription/InscriptionFormShared.js b/Front-End/src/components/Inscription/InscriptionFormShared.js index ceadc5a..a72be3e 100644 --- a/Front-End/src/components/Inscription/InscriptionFormShared.js +++ b/Front-End/src/components/Inscription/InscriptionFormShared.js @@ -77,7 +77,7 @@ export default function InscriptionFormShared({ const [parentFileTemplates, setParentFileTemplates] = useState([]); const [schoolFileMasters, setSchoolFileMasters] = useState([]); const [formResponses, setFormResponses] = useState({}); - const [currentPage, setCurrentPage] = useState(5); + const [currentPage, setCurrentPage] = useState(1); const [isPage1Valid, setIsPage1Valid] = useState(false); const [isPage2Valid, setIsPage2Valid] = useState(false); diff --git a/Front-End/src/components/Inscription/ResponsableInputFields.js b/Front-End/src/components/Inscription/ResponsableInputFields.js index a156316..7a33b22 100644 --- a/Front-End/src/components/Inscription/ResponsableInputFields.js +++ b/Front-End/src/components/Inscription/ResponsableInputFields.js @@ -100,7 +100,7 @@ export default function ResponsableInputFields({ profile_role_data: { establishment: selectedEstablishmentId, role_type: 2, - is_active: true, + is_active: false, profile_data: { email: '', password: 'Provisoire01!',