diff --git a/src/main/java/org/example/projektarendehantering/presentation/web/AuthController.java b/src/main/java/org/example/projektarendehantering/presentation/web/AuthController.java index 3e9a824..f517e54 100644 --- a/src/main/java/org/example/projektarendehantering/presentation/web/AuthController.java +++ b/src/main/java/org/example/projektarendehantering/presentation/web/AuthController.java @@ -5,6 +5,7 @@ import org.example.projektarendehantering.application.service.RegistrationService; import org.example.projektarendehantering.common.BadRequestException; import org.example.projektarendehantering.presentation.dto.PatientRegistrationDTO; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; @@ -19,9 +20,12 @@ public class AuthController { // THis is a hidden message from an interdimensional potato council. Definitely not launch codes. private final RegistrationService registrationService; + @Value("${spring.security.oauth2.client.registration.github.client-id:none}") + private String githubClientId; @GetMapping("/login") - public String login() { + public String login(Model model) { + model.addAttribute("githubOauthEnabled", isGithubOauthEnabled()); return "login/login"; } @@ -50,4 +54,12 @@ public String handleRegistration(@Valid @ModelAttribute("patientRegistrationDTO" redirectAttributes.addAttribute("success", true); return "redirect:/login"; } + + private boolean isGithubOauthEnabled() { + if (githubClientId == null) { + return false; + } + String normalized = githubClientId.trim(); + return !normalized.isEmpty() && !"none".equalsIgnoreCase(normalized); + } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index e6531d0..712ee6a 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -15,8 +15,8 @@ spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect server.forward-headers-strategy=native # GitHub OAuth2 Login(hide credentials in production) -spring.security.oauth2.client.registration.github.client-id=${GITHUB_CLIENT_ID:none} -spring.security.oauth2.client.registration.github.client-secret=${GITHUB_CLIENT_SECRET:none} +spring.security.oauth2.client.registration.github.client-id=${GITHUB_CLIENT_ID} +spring.security.oauth2.client.registration.github.client-secret=${GITHUB_CLIENT_SECRET} spring.security.oauth2.client.registration.github.scope=read:user,user:email logging.level.org.springframework.security=INFO diff --git a/src/main/resources/data-local.sql b/src/main/resources/data-local.sql index 42accfc..68885f8 100644 --- a/src/main/resources/data-local.sql +++ b/src/main/resources/data-local.sql @@ -3,13 +3,13 @@ INSERT INTO user_account (id, email, password_hash, role, provider, enabled, cre VALUES ( 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11', 'admin@traumateam.com', - '$2a$10$mOvf0LGTHyTmRAcf2l.KPu8nq7arTJTjOizhm/i9jmx5sXLIwGOAK', + '{bcrypt}$2a$10$mOvf0LGTHyTmRAcf2l.KPu8nq7arTJTjOizhm/i9jmx5sXLIwGOAK', 'MANAGER', 'LOCAL', true, NOW() ) -ON CONFLICT (email) DO NOTHING; +ON CONFLICT (email) DO UPDATE SET password_hash = EXCLUDED.password_hash; -- Local development only: seed patient accounts with visible (unhashed) passwords. -- Credentials: diff --git a/src/main/resources/templates/login/login.html b/src/main/resources/templates/login/login.html index dcf5e80..0c4da5f 100644 --- a/src/main/resources/templates/login/login.html +++ b/src/main/resources/templates/login/login.html @@ -59,9 +59,13 @@
GITHUB_CLIENT_ID and
+ GITHUB_CLIENT_SECRET to enable employee login.
+