WIP
authorKai Moritz <kai@juplo.de>
Sun, 14 Mar 2021 12:13:57 +0000 (13:13 +0100)
committerKai Moritz <kai@juplo.de>
Sun, 14 Mar 2021 12:13:57 +0000 (13:13 +0100)
pwreset/src/main/java/de/juplo/demos/pwreset/adapters/in/WebController.java
pwreset/src/main/java/de/juplo/demos/pwreset/api/domain/PasswordResetRequestProgress.java [new file with mode: 0644]
pwreset/src/main/java/de/juplo/demos/pwreset/api/domain/PasswordRestService.java

index b848ce2..b535a27 100644 (file)
@@ -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 (file)
index 0000000..6cb27f3
--- /dev/null
@@ -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<ZonedDateTime> created;
+  private final Optional<ZonedDateTime> confirmed;
+  private final Optional<ZonedDateTime> accomplished;
+}
index 3eca306..e30ce8d 100644 (file)
@@ -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);
 }