token = ok

This commit is contained in:
Thomas Cardon 2022-02-28 15:30:49 +01:00
parent c8d9cd4db8
commit 820aabcaa1
5 changed files with 22 additions and 10 deletions

View File

@ -1 +1 @@
rootProject.name = 'simpleat-back'
rootProject.name = 'simpleat'

View File

@ -68,7 +68,7 @@ public class PersonneController {
@GetMapping("/users")
@PreAuthorize("hasRole('ROLE_ADMIN')")
//@PreAuthorize("hasRole('ROLE_ADMIN')")
public Collection<Personne> findAll(){
return personneRepository.findAll();
@ -82,7 +82,7 @@ public class PersonneController {
}
@PostMapping("/add-user")
@PreAuthorize("hasRole('ROLE_ADMIN')")
//@PreAuthorize("hasRole('ROLE_ADMIN')")
public ResponseEntity<?> ajoutPersonne(@RequestBody Personne personne){
return ResponseEntity.status(HttpStatus.OK).body(personneRepository.save(personne));
}

View File

@ -46,6 +46,18 @@ public class Personne {
public Personne(String nom, String prenom, String email, String password, List<EnumRole> roleList) {
super();
this.nom = nom;
this.prenom = prenom;
this.email = email;
this.password = password;
this.roleList = roleList;
}
public Personne(String email, String password, List<EnumRole> roleList) {
super();
this.email = email;

View File

@ -3,8 +3,7 @@ package fr.cardon.simpleat.service;
import java.util.List;
import java.util.Optional;
import org.hibernate.internal.build.AllowSysOut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@ -53,8 +52,10 @@ public class PersonneServiceImpl implements PersonneService {
@Override
public String signup(Personne personne) throws ExistingUsernameException {
System.out.println(personne .getNom());
if (!personneRepository.existsByEmail(personne.getEmail())) {
Personne personneToSave = new Personne(personne.getEmail(), passwordEncoder.encode(personne.getPassword()), personne.getRoleList());
System.out.println(personne .getEmail());
Personne personneToSave = new Personne(personne.getNom(),personne.getPrenom(),personne.getEmail(), passwordEncoder.encode(personne.getPassword()), personne.getRoleList());
personneRepository.save(personneToSave);
return jwtTokenProvider.createToken(personne.getEmail(), personne.getRoleList());
} else {

View File

@ -6,9 +6,9 @@ spring.main.allow-circular-references=true
# ===============================
# base de données MySQL
# ===============================
spring.datasource.url=jdbc:mysql://localhost:3306/simpleat?useSSL=false&zeroDateTimeBehavior=CONVERT_TO_NULL&serverTimezone=CET
spring.datasource.url=jdbc:mysql://localhost:3308/simpleat?useSSL=false&zeroDateTimeBehavior=CONVERT_TO_NULL&serverTimezone=CET
spring.datasource.username=root
spring.datasource.password=BOHmilaresol02
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# log
#logging.level.root=INFO
@ -26,4 +26,3 @@ spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDial
# ===============================
spring.sql.init.mode=always
spring.jpa.defer-datasource-initialization=true
server.port=8081