1 package de.juplo.demos.pwreset.adapters.in;
3 import de.juplo.demos.pwreset.domain.ports.in.PasswordResetRequestProgressDTO;
4 import de.juplo.demos.pwreset.domain.ports.in.PasswordResetPort;
5 import lombok.RequiredArgsConstructor;
6 import org.springframework.stereotype.Controller;
7 import org.springframework.web.bind.annotation.*;
8 import org.springframework.web.servlet.ModelAndView;
10 import javax.servlet.http.HttpServletResponse;
11 import java.io.IOException;
12 import java.util.UUID;
16 @RequiredArgsConstructor
17 public class WebController
19 private final PasswordResetPort passwordResetPort;
23 public String welcome()
29 public void createResetRequest(
30 @RequestParam String email,
31 HttpServletResponse httpServletResponse)
35 PasswordResetRequestProgressDTO progress = passwordResetPort.createRequest(email);
36 httpServletResponse.sendRedirect(progress.getRequestId().toString());
40 public ModelAndView getResetRequest(@PathVariable UUID id)
42 PasswordResetRequestProgressDTO progress = passwordResetPort.getRequest(id);
43 return createModelAndView(progress);
47 public ModelAndView confirmResetRequest(
48 @PathVariable UUID id,
49 @RequestParam String code,
50 @RequestParam String password)
52 PasswordResetRequestProgressDTO progress =
53 passwordResetPort.confirmRequest(
58 ModelAndView mav = createModelAndView(progress);
60 mav.addObject("code", code);
61 mav.addObject("password", password);
66 ModelAndView createModelAndView(PasswordResetRequestProgressDTO progress)
68 ModelAndView mav = new ModelAndView();
69 mav.addObject("progress", progress);
71 if (progress.isAccepted())
73 if (progress.getConfirmed().isEmpty())
75 mav.setViewName("confirm");
79 mav.setViewName("confirmed");
84 mav.setViewName("denied");