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

- Modification of the front for inscription, changeover to landscape

- Modification of the roles for registration, the registration button is now only for patients, doctors will be registered via the superadmin (currently being implemented)
- Addition of the superadmin in the databaseSeeder
- Modification to the home page to have the first and last name after the Welcome rather than the email address
- Addition of buttons to return to the respective dashboard regardless of role
parent e3939c67
Branches
No related tags found
1 merge request!21- Modification of the front for inscription, changeover to landscape
......@@ -18,19 +18,21 @@ public class DatabaseSeeder implements CommandLineRunner {
private final DoctorRepository doctorRepository;
private final PatientRepository patientRepository;
private final AdminRepository adminRepository;
private final MedicalFileRepository medicalFileRepository;
private final MedicalDocumentRepository medicalDocumentRepository;
private final AppointmentRepository appointmentRepository;
private final PasswordEncoder passwordEncoder;
public DatabaseSeeder(DoctorRepository doctorRepository,
PatientRepository patientRepository,
PatientRepository patientRepository, AdminRepository adminRepository,
MedicalFileRepository medicalFileRepository,
MedicalDocumentRepository medicalDocumentRepository,
AppointmentRepository appointmentRepository,
PasswordEncoder passwordEncoder) {
this.doctorRepository = doctorRepository;
this.patientRepository = patientRepository;
this.adminRepository = adminRepository;
this.medicalFileRepository = medicalFileRepository;
this.medicalDocumentRepository = medicalDocumentRepository;
this.appointmentRepository = appointmentRepository;
......@@ -48,6 +50,9 @@ public class DatabaseSeeder implements CommandLineRunner {
Patient patient2 = new Patient("Alice", "Lemoine", LocalDate.parse("1990-05-15"), "0687654321", "alice.lemoine@example.com", "8 Rue du Lac", passwordEncoder.encode("test123"));
patientRepository.saveAll(List.of(patient1, patient2));
Admin admin1 = new Admin("root", "root", "0000000000", "root@example.com", passwordEncoder.encode("root123"));
adminRepository.save(admin1);
MedicalFile file1 = new MedicalFile(patient1, "Arachide", "Ibuprofene");
MedicalFile file2 = new MedicalFile(patient2, "Pollen", "Bisoprolol");
medicalFileRepository.saveAll(List.of(file1, file2));
......@@ -72,6 +77,7 @@ public class DatabaseSeeder implements CommandLineRunner {
System.out.println("Données insérées :");
System.out.println("Médecins : " + doctorRepository.count());
System.out.println("Patients : " + patientRepository.count());
System.out.println("Admin: " + adminRepository.count());
System.out.println("Dossiers médicaux : " + medicalFileRepository.count());
System.out.println("Documents médicaux : " + medicalDocumentRepository.count());
System.out.println("Rendez-vous : " + appointmentRepository.count());
......
package com.projet.projetIndu.controllers;
import com.projet.projetIndu.entities.User;
import com.projet.projetIndu.services.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
......@@ -8,19 +11,42 @@ import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.Collection;
import java.util.Optional;
@Controller
public class HomeController {
private final UserService userService;
@Autowired
public HomeController(UserService userService) {
this.userService = userService;
}
@GetMapping("/")
public String home(Model model) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication != null && authentication.isAuthenticated() && !authentication.getPrincipal().equals("anonymousUser")) {
model.addAttribute("username", authentication.getName());
String username = authentication.getName();
model.addAttribute("username", username);
Optional<User> userOptional = userService.getUserByUsername(username);
if (userOptional.isPresent()) {
User user = userOptional.get();
model.addAttribute("firstName", user.getFirstName());
model.addAttribute("lastName", user.getLastName());
}
Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
boolean isDoctor = authorities.stream().anyMatch(auth -> auth.getAuthority().equals("DOCTOR"));
boolean isPatient = authorities.stream().anyMatch(auth -> auth.getAuthority().equals("PATIENT"));
boolean isAdmin = authorities.stream().anyMatch(auth -> auth.getAuthority().equals("ADMIN"));
model.addAttribute("isDoctor", isDoctor);
model.addAttribute("isPatient", isPatient);
model.addAttribute("isAdmin", isAdmin);
}
return "home";
......
package com.projet.projetIndu.entities;
import jakarta.persistence.Column;
import jakarta.persistence.DiscriminatorValue;
import jakarta.persistence.Entity;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Entity
@Getter
@Setter
@NoArgsConstructor
@DiscriminatorValue("ADMIN")
public class Admin extends User {
public Admin(String firstName, String lastName, String phoneNumber, String email, String password) {
super(firstName, lastName, phoneNumber, email, password);
this.role = Role.ADMIN;
}
}
......@@ -19,11 +19,20 @@
class="px-6 py-2 bg-green-500 text-white rounded-md hover:bg-green-600">Professionnel de
santé</a>
</th:block>
<th:block th:if="${username}">
<span class="text-gray-900 font-semibold">Bienvenue, <b th:text="${username}"></b> !</span>
<th:block th:if="${isPatient}">
<a href="/patients/dashboard"
class="px-6 py-2 bg-pink-500 text-white rounded-md hover:bg-pink-600">Patient</a>
</th:block>
<th:block th:if="${isAdmin}">
<a href="/admin/dashboard"
class="px-6 py-2 bg-orange-500 text-white rounded-md hover:bg-orange-600">Admin</a>
</th:block>
<th:block th:if="${firstName != null and lastName != null}">
<span class="text-gray-900 font-semibold">Bienvenue, <b th:text="${firstName + ' ' + lastName}"></b> !</span>
<a href="/logout" class="ml-4 text-red-500 hover:text-red-700">Déconnexion</a>
</th:block>
<th:block th:unless="${username}">
<a th:href="@{/login}" class="text-blue-500 hover:text-blue-700">Connexion</a>
<a th:href="@{/register}" class="text-blue-500 hover:text-blue-700">Inscription</a>
......
......@@ -16,26 +16,27 @@
</head>
<body class="bg-light">
<div class="container d-flex justify-content-center align-items-center vh-100">
<div class="card shadow p-4" style="width: 350px; border-radius: 10px;">
<div class="card shadow p-4" style="width: 500px; border-radius: 10px;">
<h3 class="text-center mb-3">Inscription</h3>
<form th:action="@{/register}" method="post">
<div class="mb-3">
<div class="row">
<div class="col-md-6 mb-3">
<label for="firstName" class="form-label">Prénom</label>
<input type="text" class="form-control" id="firstName" name="firstName" required>
</div>
<div class="mb-3">
<div class="col-md-6 mb-3">
<label for="lastName" class="form-label">Nom</label>
<input type="text" class="form-control" id="lastName" name="lastName" required>
</div>
<div class="mb-3">
<div class="col-md-6 mb-3">
<label for="email" class="form-label">Email</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="mb-3">
<div class="col-md-6 mb-3">
<label for="password" class="form-label">Mot de passe</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<div class="mb-3">
<div class="col-md-12 mb-3">
<label for="role" class="form-label">Rôle</label>
<select class="form-control" id="role" name="role" required onchange="toggleFields()">
<option value="PATIENT">Patient</option>
......@@ -43,17 +44,19 @@
</div>
<!-- Champs spécifiques pour Patient -->
<div id="patientFields">
<div class="mb-3">
<div id="patientFields" class="col-md-12">
<div class="row">
<div class="col-md-6 mb-3">
<label for="dateOfBirth" class="form-label">Date de naissance</label>
<input type="date" class="form-control" id="dateOfBirth" name="dateOfBirth">
</div>
<div class="mb-3">
<div class="col-md-6 mb-3">
<label for="address" class="form-label">Adresse</label>
<input type="text" class="form-control" id="address" name="address">
</div>
</div>
</div>
</div>
<button type="submit" class="btn btn-success w-100">S'inscrire</button>
</form>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment