diff --git a/src/main/kotlin/pt/up/fe/ni/website/backend/controller/AuthController.kt b/src/main/kotlin/pt/up/fe/ni/website/backend/controller/AuthController.kt index 00bbceb3..91c3e96c 100644 --- a/src/main/kotlin/pt/up/fe/ni/website/backend/controller/AuthController.kt +++ b/src/main/kotlin/pt/up/fe/ni/website/backend/controller/AuthController.kt @@ -1,5 +1,6 @@ package pt.up.fe.ni.website.backend.controller +import org.springframework.beans.factory.annotation.Value import org.springframework.security.access.prepost.PreAuthorize import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PathVariable @@ -15,6 +16,9 @@ import pt.up.fe.ni.website.backend.service.AuthService @RestController @RequestMapping("/auth") class AuthController(val authService: AuthService) { + @field:Value("\${backend.url}") + private lateinit var backendUrl: String + @PostMapping("/new") fun getNewToken(@RequestBody loginDto: LoginDto): Map { val account = authService.authenticate(loginDto.email, loginDto.password) @@ -33,7 +37,7 @@ class AuthController(val authService: AuthService) { fun generateRecoveryToken(@PathVariable id: Long): Map { val recoveryToken = authService.generateRecoveryToken(id) // TODO: Change URL Later - return mapOf("recovery_url" to "localhost:8080/accounts/recoverPassword/$recoveryToken") + return mapOf("recovery_url" to "$backendUrl/accounts/recoverPassword/$recoveryToken") } @GetMapping diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index feb315ca..f05c3954 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -36,6 +36,9 @@ upload.static-path=classpath:static # URL that will serve static content upload.static-serve=http://localhost:3000/static +# Backend URL +backend.url=http://localhost:8080 + # Due to a problem with Hibernate, which is using a deprecated property. This should be removed when fixed # See https://github.com/spring-projects/spring-data-jpa/issues/2717 for more information spring.jpa.properties.jakarta.persistence.sharedCache.mode=UNSPECIFIED diff --git a/src/test/kotlin/pt/up/fe/ni/website/backend/controller/AccountControllerTest.kt b/src/test/kotlin/pt/up/fe/ni/website/backend/controller/AccountControllerTest.kt index 4f78aeeb..f155b689 100644 --- a/src/test/kotlin/pt/up/fe/ni/website/backend/controller/AccountControllerTest.kt +++ b/src/test/kotlin/pt/up/fe/ni/website/backend/controller/AccountControllerTest.kt @@ -13,6 +13,7 @@ import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test import org.mockito.Mockito import org.springframework.beans.factory.annotation.Autowired +import org.springframework.beans.factory.annotation.Value import org.springframework.http.MediaType import org.springframework.mock.web.MockPart import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.delete @@ -907,6 +908,9 @@ class AccountControllerTest @Autowired constructor( @NestedTest @DisplayName("PUT /recoverPassword/{recoveryToken}") inner class RecoverPassword { + @field:Value("\${backend.url}") + private lateinit var backendUrl: String + private val newPassword = "new-password" private val parameters = listOf( @@ -930,7 +934,7 @@ class AccountControllerTest @Autowired constructor( mockMvc.perform(post("/auth/recoverPassword/${testAccount.id}")) .andReturn().response.let { authResponse -> val recoveryToken = objectMapper.readTree(authResponse.contentAsString)["recovery_url"].asText() - .removePrefix("localhost:8080/accounts/recoverPassword/") + .removePrefix("$backendUrl/accounts/recoverPassword/") mockMvc.perform( put("/accounts/recoverPassword/{recoveryToken}", recoveryToken) .contentType(MediaType.APPLICATION_JSON)