From: Kai Moritz Date: Sun, 14 Mar 2021 12:13:57 +0000 (+0100) Subject: WIP X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=2abe7756a3f2dac635611726450dcf28aebc79c7;p=demos%2Fpact WIP --- diff --git a/pwreset/src/main/java/de/juplo/demos/pwreset/adapters/in/WebController.java b/pwreset/src/main/java/de/juplo/demos/pwreset/adapters/in/WebController.java index b848ce2..b535a27 100644 --- a/pwreset/src/main/java/de/juplo/demos/pwreset/adapters/in/WebController.java +++ b/pwreset/src/main/java/de/juplo/demos/pwreset/adapters/in/WebController.java @@ -1,6 +1,6 @@ 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; @@ -20,52 +20,68 @@ public class WebController @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; diff --git a/pwreset/src/main/java/de/juplo/demos/pwreset/api/domain/PasswordResetRequestProgress.java b/pwreset/src/main/java/de/juplo/demos/pwreset/api/domain/PasswordResetRequestProgress.java new file mode 100644 index 0000000..6cb27f3 --- /dev/null +++ b/pwreset/src/main/java/de/juplo/demos/pwreset/api/domain/PasswordResetRequestProgress.java @@ -0,0 +1,23 @@ +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 created; + private final Optional confirmed; + private final Optional accomplished; +} diff --git a/pwreset/src/main/java/de/juplo/demos/pwreset/api/domain/PasswordRestService.java b/pwreset/src/main/java/de/juplo/demos/pwreset/api/domain/PasswordRestService.java index 3eca306..e30ce8d 100644 --- a/pwreset/src/main/java/de/juplo/demos/pwreset/api/domain/PasswordRestService.java +++ b/pwreset/src/main/java/de/juplo/demos/pwreset/api/domain/PasswordRestService.java @@ -5,14 +5,7 @@ import java.util.UUID; public interface PasswordRestService { - enum Progress - { - CREATED, - CONFIRMED, - ACCOMPLISHED - } - - PasswordResetRequest request(String email); - PasswordResetRequest get(); - PasswordResetRequest confirm(UUID requestId, String code, String password); + PasswordResetRequestProgress request(String email); + PasswordResetRequestProgress get(UUID requestId); + PasswordResetRequestProgress confirm(UUID requestId, String code, String password); }