package de.juplo.demos.pwreset.adapters.in;
-import de.juplo.demos.pwreset.api.domain.PasswordResetRequest;
+import de.juplo.demos.pwreset.api.domain.PasswordResetRequestProgress;
import de.juplo.demos.pwreset.api.domain.PasswordRestService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
@GetMapping("/")
- public String requestForm()
+ public String welcome()
{
return "request";
}
@PostMapping("/")
- public void resetRequest(
+ public void createResetRequest(
@RequestParam String email,
HttpServletResponse httpServletResponse)
throws
IOException
{
- PasswordResetRequest resetRequest = passwordRestService.request(email);
- httpServletResponse.sendRedirect(resetRequest.getUserId().toString());
+ PasswordResetRequestProgress progress = passwordRestService.request(email);
+ httpServletResponse.sendRedirect(progress.getRequestId().toString());
}
@GetMapping("/{id}")
public ModelAndView getResetRequest(@PathVariable UUID id)
{
- PasswordResetRequest resetRequest = passwordRestService.get(id);
- ModelAndView mav = new ModelAndView("confirm");
- return "confirm";
+ PasswordResetRequestProgress progress = passwordRestService.get(id);
+ return createModelAndView(progress);
}
- @PutMapping("/{id")
+ @PutMapping("/{id}")
public ModelAndView confirmResetRequest(
@PathVariable UUID id,
@RequestParam String code,
@RequestParam String password)
{
- ModelAndView mav = new ModelAndView("confirm");
+ PasswordResetRequestProgress progress =
+ passwordRestService.confirm(
+ id,
+ code,
+ password);
+
+ ModelAndView mav = createModelAndView(progress);
+
mav.addObject("code", code);
mav.addObject("password", password);
- try
- {
- PasswordResetRequest resetRequest =
- passwordRestService.confirm(
- id,
- code,
- password);
+ return mav;
+ }
+
+ ModelAndView createModelAndView(PasswordResetRequestProgress progress)
+ {
+ ModelAndView mav = new ModelAndView();
+ mav.addObject("progress", progress);
+ if (progress.isAccepted())
+ {
+ if (progress.getConfirmed().isEmpty())
+ {
+ mav.setViewName("confirm");
+ }
+ else
+ {
+ mav.setViewName("confirmed");
+ }
}
- catch (Exception e)
+ else
{
- mav.addObject("message", e.getMessage());
+ mav.setViewName("denied");
}
return mav;
--- /dev/null
+package de.juplo.demos.pwreset.api.domain;
+
+import lombok.Builder;
+import lombok.Getter;
+import lombok.ToString;
+
+import java.time.ZonedDateTime;
+import java.util.Optional;
+import java.util.UUID;
+
+
+@Builder
+@Getter
+@ToString
+public class PasswordResetRequestProgress
+{
+ private final UUID requestId;
+ private final boolean accepted;
+ private final String message;
+ private final Optional<ZonedDateTime> created;
+ private final Optional<ZonedDateTime> confirmed;
+ private final Optional<ZonedDateTime> accomplished;
+}