Modification du mot de passe

This commit is contained in:
Guams 2025-02-01 14:56:23 +01:00
parent b3b8a0ab63
commit 2259ce7e00
3 changed files with 11 additions and 19 deletions

View File

@ -2,9 +2,10 @@ package com.guams.review;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jdbc.repository.config.EnableJdbcRepositories;
import java.util.List;
@EnableJdbcRepositories
@SpringBootApplication @SpringBootApplication
public class ReViewApplication { public class ReViewApplication {

View File

@ -52,10 +52,11 @@ public class SpringSecurityConfig {
@Bean @Bean
public CorsConfigurationSource corsConfigurationSource() { public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration(); CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(List.of("http://localhost:4200")); // N'autorise que localhost:4200 // configuration.setAllowedOrigins(List.of("http://192.168.1.35:4200"));
configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE")); // Spécifie les méthodes autorisées configuration.setAllowedOrigins(List.of("http://localhost:4200"));
configuration.setAllowedHeaders(List.of("Authorization", "Content-Type")); // Limite les en-têtes autorisés configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE")); // Méthodes HTTP autorisées
configuration.setAllowCredentials(true); // Autorise l'utilisation des cookies ou des tokens configuration.setAllowedHeaders(List.of("Authorization", "Content-Type")); // En-têtes autorisés
configuration.setAllowCredentials(true); // Permet l'utilisation des cookies ou des tokens
configuration.setMaxAge(3600L); // Cache la configuration CORS pendant 1 heure configuration.setMaxAge(3600L); // Cache la configuration CORS pendant 1 heure
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();

View File

@ -54,22 +54,12 @@ public class AuthorController {
@PutMapping("/{id}") @PutMapping("/{id}")
public ReturnableAuthor updateUser(@PathVariable UUID id, @RequestBody Author updatedAuthor, Authentication authentication) { public ReturnableAuthor updateUser(@PathVariable UUID id, @RequestBody Author updatedAuthor, Authentication authentication) {
Author authorToUpdate = authorService.verifyIfUserIsAuthorized(authentication, id); Author authorToUpdate = authorService.verifyIfUserIsAuthorized(authentication, id);
if (passwordEncoder.matches(updatedAuthor.getPassword(), authorToUpdate.getPassword())) { return authorService.insert(updatedAuthor
return authorService.insert(updatedAuthor .setId(authorToUpdate.getId())
.setId(authorToUpdate.getId()) .setRole(authorToUpdate.getRole())
.setRole(authorToUpdate.getRole()) .setPassword(passwordEncoder.encode(updatedAuthor.getPassword())));
.setPassword(authorToUpdate.getPassword()));
} else {
throw new UnauthorizedExecption("You are not authorized to update this author");
}
} }
// @PutMapping("/{id}/password")
// public void changePassword(@PathVariable UUID id, @RequestBody Author updatedAuthor, Authentication authentication) {
// Author authorToUpdate = authorService.verifyIfUserIsAuthorized(authentication, id);
// if (passwordEncoder.matches(updatedAuthor.getPassword(), authorToUpdate.getPassword())) {}
// }
@PutMapping(value = "{id}/avatar", consumes = {MediaType.MULTIPART_FORM_DATA_VALUE}) @PutMapping(value = "{id}/avatar", consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
public Author updateUserAvatar(@PathVariable UUID id, @RequestPart MultipartFile avatar, Authentication authentication) throws IOException { public Author updateUserAvatar(@PathVariable UUID id, @RequestPart MultipartFile avatar, Authentication authentication) throws IOException {
Author authorToUpdate = authorService.verifyIfUserIsAuthorized(authentication, id); Author authorToUpdate = authorService.verifyIfUserIsAuthorized(authentication, id);