From 5dc418cacd7582e53f3bd3fef0533c5a4cce20c5 Mon Sep 17 00:00:00 2001 From: gstio86 Date: Wed, 13 Nov 2024 16:13:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=87=8D=E8=A8=AD=E5=AF=86?= =?UTF-8?q?=E7=A2=BCAPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/UserController.java | 7 +++++++ .../gt/snaptickets/dto/ResetPasswordDto.java | 20 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/main/java/me/gt/snaptickets/dto/ResetPasswordDto.java diff --git a/src/main/java/me/gt/snaptickets/controller/UserController.java b/src/main/java/me/gt/snaptickets/controller/UserController.java index 9352eef..125fe41 100644 --- a/src/main/java/me/gt/snaptickets/controller/UserController.java +++ b/src/main/java/me/gt/snaptickets/controller/UserController.java @@ -2,6 +2,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; +import me.gt.snaptickets.dto.ResetPasswordDto; import me.gt.snaptickets.dto.UserDto; import me.gt.snaptickets.model.Order; import me.gt.snaptickets.model.User; @@ -62,6 +63,12 @@ public ResponseEntity loginUser(@RequestParam String identifier, @Reques return ResponseEntity.ok().body(Map.of("username", user.getUsername(), "token", token)); } + @Operation(summary = "重設密碼") + @PutMapping("/auth/reset-password") + public ResponseEntity resetPassword(@RequestBody ResetPasswordDto resetPasswordDto) { + return updatePassword(resetPasswordDto.getUsername(), resetPasswordDto.getOldPassword(), resetPasswordDto.getNewPassword()); + } + @Operation(summary = "查詢帳號資料") @GetMapping("/user/info/{username}") public ResponseEntity getUserByUsername(@PathVariable String username) { diff --git a/src/main/java/me/gt/snaptickets/dto/ResetPasswordDto.java b/src/main/java/me/gt/snaptickets/dto/ResetPasswordDto.java new file mode 100644 index 0000000..7eb567f --- /dev/null +++ b/src/main/java/me/gt/snaptickets/dto/ResetPasswordDto.java @@ -0,0 +1,20 @@ +package me.gt.snaptickets.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; + +@Data +@Builder +@ToString +@NoArgsConstructor +@AllArgsConstructor +public class ResetPasswordDto { + @Schema(description = "帳號") + private String username; + + @Schema(description = "舊密碼") + private String oldPassword; + + @Schema(description = "新密碼") + private String newPassword; +}