Skip to content
Snippets Groups Projects
Commit e3939c67 authored by Jessie Ragot's avatar Jessie Ragot
Browse files

Remove role admin and doctor in registration

parent d1f3037a
Branches
Tags
1 merge request!21- Modification of the front for inscription, changeover to landscape
...@@ -54,6 +54,6 @@ public class DoctorService { ...@@ -54,6 +54,6 @@ public class DoctorService {
} }
} }
//
package com.projet.projetIndu.services; package com.projet.projetIndu.services;
import com.projet.projetIndu.dto.UserRegistrationDTO; import com.projet.projetIndu.dto.UserRegistrationDTO;
import com.projet.projetIndu.entities.Admin;
import com.projet.projetIndu.entities.Doctor;
import com.projet.projetIndu.entities.Patient; import com.projet.projetIndu.entities.Patient;
import com.projet.projetIndu.entities.Role;
import com.projet.projetIndu.entities.User; import com.projet.projetIndu.entities.User;
import com.projet.projetIndu.repositories.UserRepository; import com.projet.projetIndu.repositories.UserRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -14,6 +13,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; ...@@ -14,6 +13,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.Optional; import java.util.Optional;
...@@ -54,18 +54,9 @@ public class UserService implements UserDetailsService { ...@@ -54,18 +54,9 @@ public class UserService implements UserDetailsService {
} }
String encodedPassword = passwordEncoder.encode(userDTO.getPassword()); String encodedPassword = passwordEncoder.encode(userDTO.getPassword());
User user; User user = null;
switch (userDTO.getRole()) { if (Objects.requireNonNull(userDTO.getRole()) == Role.PATIENT) {
case DOCTOR -> {
if (userDTO.getSpeciality() == null || userDTO.getSpeciality().isEmpty()) {
throw new IllegalArgumentException("Speciality is required for doctors");
}
Doctor doctor = new Doctor();
doctor.setSpeciality(userDTO.getSpeciality());
user = doctor;
}
case PATIENT -> {
if (userDTO.getDateOfBirth() == null) { if (userDTO.getDateOfBirth() == null) {
throw new IllegalArgumentException("Date of birth is required for patients"); throw new IllegalArgumentException("Date of birth is required for patients");
} }
...@@ -77,12 +68,8 @@ public class UserService implements UserDetailsService { ...@@ -77,12 +68,8 @@ public class UserService implements UserDetailsService {
patient.setAddress(userDTO.getAddress()); patient.setAddress(userDTO.getAddress());
user = patient; user = patient;
} }
case ADMIN -> {
user = new Admin();
}
default -> throw new IllegalArgumentException("Invalid role");
}
assert user != null;
user.setFirstName(userDTO.getFirstName()); user.setFirstName(userDTO.getFirstName());
user.setLastName(userDTO.getLastName()); user.setLastName(userDTO.getLastName());
user.setPhoneNumber(userDTO.getPhoneNumber()); user.setPhoneNumber(userDTO.getPhoneNumber());
......
...@@ -39,19 +39,9 @@ ...@@ -39,19 +39,9 @@
<label for="role" class="form-label">Rôle</label> <label for="role" class="form-label">Rôle</label>
<select class="form-control" id="role" name="role" required onchange="toggleFields()"> <select class="form-control" id="role" name="role" required onchange="toggleFields()">
<option value="PATIENT">Patient</option> <option value="PATIENT">Patient</option>
<option value="DOCTOR">Médecin</option>
<option value="ADMIN">Administrateur</option>
</select> </select>
</div> </div>
<!-- Champs spécifiques pour Médecin -->
<div id="doctorFields" style="display: none;">
<div class="mb-3">
<label for="speciality" class="form-label">Spécialité</label>
<input type="text" class="form-control" id="speciality" name="speciality">
</div>
</div>
<!-- Champs spécifiques pour Patient --> <!-- Champs spécifiques pour Patient -->
<div id="patientFields"> <div id="patientFields">
<div class="mb-3"> <div class="mb-3">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment