52 lines
1.9 KiB
Java
52 lines
1.9 KiB
Java
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/finalize")
|
|
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);
|
|
}
|
|
}
|