feat: created a better account creation flow
All checks were successful
Format / formatting (push) Successful in 6s
Build / build (push) Successful in 5m20s
CI / build (push) Successful in 11s

This commit is contained in:
Pierre Tellier
2025-04-09 17:39:43 +02:00
parent 385c5cd8d0
commit 66be0baca6
14 changed files with 377 additions and 88 deletions

View File

@ -99,4 +99,20 @@ public class AdminApi {
public void deleteProject(@PathVariable long projectId) {
adminApiService.deleteProject(projectId);
}
@GetMapping("/admin/setadmin/{userId}")
public void setAdmin(@PathVariable long userId, @AuthenticationPrincipal Jwt principal) {
this.adminApiService.setAdmin(userId, principal.getTokenValue());
}
@GetMapping("/admin/validate_user_account/{userId}")
public void validateEntrepreneurAcc(
@PathVariable long userId, @AuthenticationPrincipal Jwt principal) {
this.adminApiService.validateEntrepreneurAccount(userId, principal.getTokenValue());
}
@GetMapping("/admin/get_pending_accounts")
public Iterable<User> validateEntrepreneurAcc() {
return this.adminApiService.getPendingUsers();
}
}

View File

@ -0,0 +1,51 @@
package enseirb.myinpulse.controller;
import enseirb.myinpulse.model.Entrepreneur;
import enseirb.myinpulse.service.EntrepreneurApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.oauth2.jwt.Jwt;
import org.springframework.web.bind.annotation.*;
@SpringBootApplication
@RestController
public class UnauthApi {
private final EntrepreneurApiService entrepreneurApiService;
@Autowired
UnauthApi(EntrepreneurApiService entrepreneurApiService) {
this.entrepreneurApiService = entrepreneurApiService;
}
@GetMapping("/unauth/create_account")
public void createAccount(@AuthenticationPrincipal Jwt principal) {
boolean sneeStatus;
if (principal.getClaimAsString("sneeStatus") != null) {
sneeStatus = principal.getClaimAsString("sneeStatus").equals("true");
} else {
sneeStatus = false;
}
String userSurname = principal.getClaimAsString("userSurname");
String username = principal.getClaimAsString("preferred_username");
String primaryMail = principal.getClaimAsString("email");
String secondaryMail = principal.getClaimAsString("secondaryMail");
String phoneNumber = principal.getClaimAsString("phoneNumber");
String school = principal.getClaimAsString("school");
String course = principal.getClaimAsString("course");
Entrepreneur e =
new Entrepreneur(
userSurname,
username,
primaryMail,
secondaryMail,
phoneNumber,
school,
course,
sneeStatus,
true);
entrepreneurApiService.createAccount(e);
}
}