Skip to content
Snippets Groups Projects
Commit 1b755eea authored by Andreas's avatar Andreas
Browse files
parents d8e57b67 4eb0fd44
No related branches found
No related tags found
1 merge request!89Refactor/logging controller classes
Pipeline #284499 passed
......@@ -24,5 +24,5 @@ COPY --from=build /app/target/*.jar app.jar
EXPOSE 8080
# Run the application
CMD ["java", "-jar", "app.jar"]
CMD ["java", "-DAPI_URL=https://api.sparesti.org", "-DFRONTEND_URL=https://sparesti.org", "-jar", "app.jar"]
......@@ -17,4 +17,20 @@ public class SparestiApplication {
public static void main(String[] args) {
SpringApplication.run(SparestiApplication.class, args);
}
/**
* Returns the URL for the frontend application.
* @return the URL for the frontend application
*/
public static String getFrontendURL() {
return System.getProperty("FRONTEND_URL", "http://localhost");
}
/**
* Returns the URL for the backend application.
* @return the URL for the backend application
*/
public static String getBackendURL() {
return System.getProperty("API_URL", "http://localhost:8080");
}
}
......@@ -3,6 +3,7 @@ package no.ntnu.idi.stud.savingsapp.controller.redirect;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import no.ntnu.idi.stud.savingsapp.SparestiApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.*;
......@@ -33,13 +34,13 @@ public class RedirectController {
HttpServletRequest request, HttpServletResponse response) {
if (request.getParameterMap().containsKey("code")) {
String code = request.getParameterMap().get("code")[0];
response.setHeader("Location", "http://localhost:5173/redirect?code=" + code + "&state=" + state);
response.setHeader("Location", SparestiApplication.getFrontendURL() + "/redirect?code=" + code + "&state=" + state);
response.setStatus(302);
return;
}
// Default redirection if "code" parameter is missing
try {
response.sendRedirect("http://localhost:5173/login");
response.sendRedirect(SparestiApplication.getFrontendURL() + "/login");
} catch (IOException e) {
throw new RuntimeException(e);
}
......
......@@ -126,6 +126,9 @@ public class UserController {
if (updateDTO.getProfileImage() != null) {
user.setProfileImage(updateDTO.getProfileImage());
}
if(updateDTO.getBannerImage() != null) {
user.setBannerImage(updateDTO.getBannerImage());
}
if (updateDTO.getConfiguration() != null) {
if (updateDTO.getConfiguration().getCommitment() != null) {
user.getConfiguration().setCommitment(Commitment.valueOf(updateDTO.getConfiguration().getCommitment()));
......
......@@ -2,11 +2,9 @@ package no.ntnu.idi.stud.savingsapp.dto.user;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import no.ntnu.idi.stud.savingsapp.dto.configuration.ConfigurationDTO;
import no.ntnu.idi.stud.savingsapp.validation.Name;
import no.ntnu.idi.stud.savingsapp.validation.Password;
@Data
public final class UserUpdateDTO {
......@@ -22,6 +20,8 @@ public final class UserUpdateDTO {
private Long profileImage;
private Long bannerImage;
@Valid
private ConfigurationDTO configuration;
}
package no.ntnu.idi.stud.savingsapp.security;
import jakarta.servlet.DispatcherType;
import no.ntnu.idi.stud.savingsapp.SparestiApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
......@@ -66,7 +67,7 @@ public class SecurityConfig {
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration config = new CorsConfiguration();
config.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"));
config.setAllowedOrigins(List.of("http://localhost"));
config.setAllowedOrigins(List.of(SparestiApplication.getFrontendURL()));
config.setAllowedHeaders(Arrays.asList("Authorization", "Content-Type", "Cache-Control"));
config.setAllowCredentials(true);
......
......@@ -2,6 +2,7 @@ package no.ntnu.idi.stud.savingsapp.service.impl;
import jakarta.mail.MessagingException;
import jakarta.mail.internet.MimeMessage;
import no.ntnu.idi.stud.savingsapp.SparestiApplication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.mail.javamail.JavaMailSender;
......@@ -40,6 +41,7 @@ public class EmailService {
ClassPathResource htmlResource = new ClassPathResource("reset-password/reset-password.html");
String html = StreamUtils.copyToString(htmlResource.getInputStream(), StandardCharsets.UTF_8);
html = html.replace("{RESET_TOKEN}", token);
html = html.replace("{FRONTEND_URL}", SparestiApplication.getFrontendURL());
helper.setText(html, true);
helper.addInline("logo", new ClassPathResource("reset-password/assets/logo.png"));
......
......@@ -3,6 +3,7 @@ package no.ntnu.idi.stud.savingsapp.service.impl;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.mail.MessagingException;
import lombok.extern.slf4j.Slf4j;
import no.ntnu.idi.stud.savingsapp.SparestiApplication;
import no.ntnu.idi.stud.savingsapp.bank.model.Account;
import no.ntnu.idi.stud.savingsapp.bank.service.AccountService;
import no.ntnu.idi.stud.savingsapp.exception.auth.InvalidCredentialsException;
......@@ -151,7 +152,7 @@ public class UserServiceImpl implements UserService {
httpPost.setHeader(HttpHeaders.AUTHORIZATION, "Basic " + "ZGVtby1wcmVwcm9kOm1xWi1fNzUtZjJ3TnNpUVRPTmI3T240YUFaN3pjMjE4bXJSVmsxb3VmYTg=");
List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("client_id", "demo-preprod"));
params.add(new BasicNameValuePair("redirect_uri", "http://localhost:8080/redirect"));
params.add(new BasicNameValuePair("redirect_uri", SparestiApplication.getBackendURL() + "/redirect"));
params.add(new BasicNameValuePair("grant_type", "authorization_code"));
params.add(new BasicNameValuePair("code", code));
httpPost.setEntity(new UrlEncodedFormEntity(params, StandardCharsets.UTF_8));
......
......@@ -60,7 +60,7 @@
<img alt="Sparesti logo" src="cid:logo" id="logo">
<h1>Password Recovery</h1>
<p>You've requested to reset your password. Click the button below to proceed:</p>
<a href="http://localhost:5173/change-password/{RESET_TOKEN}" class="btn"
<a href="{FRONTEND_URL}/change-password/{RESET_TOKEN}" class="btn"
style="font-family:'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; line-height: 16px;
color: #ffffff; font-weight: 400; text-decoration: none;font-size: 14px;display:inline-block;
padding: 10px 24px;background-color: #4184F3; border-radius: 5px; min-width: 90px;">Reset Password</a>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment