fix login
This commit is contained in:
parent
cb2dcf4d3a
commit
f86389cb84
@ -73,9 +73,22 @@ public class AuthenticationJwtRepository implements AuthenticationRepository {
|
||||
userEntity.setEnabled(true);
|
||||
if(request.getCompanyName() != null && !request.getCompanyName().isEmpty()){
|
||||
userEntity.setRole(Role.ADMIN);
|
||||
CompanyEntity companyEntity = new CompanyEntity();
|
||||
companyEntity.setName(request.getCompanyName());
|
||||
companyDao.save(companyEntity);
|
||||
|
||||
// Rechercher l'entreprise existante ou en créer une nouvelle
|
||||
CompanyEntity companyEntity = companyDao.findByName(request.getCompanyName())
|
||||
.orElseGet(() -> {
|
||||
log.info("Creating new company: {}", request.getCompanyName());
|
||||
CompanyEntity newCompany = new CompanyEntity();
|
||||
newCompany.setName(request.getCompanyName());
|
||||
if (request.getCompanyCountry() != null && !request.getCompanyCountry().isEmpty()) {
|
||||
newCompany.setCountry(request.getCompanyCountry());
|
||||
}
|
||||
return companyDao.save(newCompany);
|
||||
});
|
||||
|
||||
// Lier l'utilisateur à l'entreprise
|
||||
userEntity.setCompany(companyEntity);
|
||||
log.info("User {} linked to company: {}", request.getUsername(), companyEntity.getName());
|
||||
} else {
|
||||
userEntity.setRole(Role.ADMIN);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user