From fc92caa43bc8aeedfc7867907145eec1203ca146 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期四, 07 十二月 2023 20:50:53 +0800
Subject: [PATCH] 实现重置用户密码功能
---
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserCtrl.java | 77 ++++++++++++++++++++++++++++++++++++--
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/resources/application.yml | 1
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/ResetPasswordVo.java | 21 ++++++++++
3 files changed, 95 insertions(+), 4 deletions(-)
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/ResetPasswordVo.java b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/ResetPasswordVo.java
new file mode 100644
index 0000000..8950fc2
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/ResetPasswordVo.java
@@ -0,0 +1,21 @@
+package com.dy.pipIrrBase.user;
+
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.*;
+
+@Data
+@EqualsAndHashCode(callSuper = false)
+@ToString(callSuper = true)
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+@Schema(name = "閲嶇疆瀵嗙爜鍊煎璞�")
+public class ResetPasswordVo {
+
+ @Schema(description = "鐢ㄦ埛ID")
+ public String id ;
+
+ @Schema(description = "鏂板瘑鐮�")
+ public String password ;
+}
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserCtrl.java
index 8cf9ed8..f06ce37 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserCtrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserCtrl.java
@@ -39,12 +39,39 @@
private UserSv sv;
+ @Value("${user.defaultTrueRandomFalsePassword:true}")
+ private Boolean defaultTrueRandomFalsePassword;
+
@Value("${user.defaultPassword:ABC123}")
private String defaultPassword;
@Autowired
private void setSv(UserSv sv) {
this.sv = sv;
+ }
+
+
+ /**
+ * 瀹㈡埛绔姹傚緱鍒伴粯璁ゅ瘑鐮�
+ * @return 榛樿瀵嗙爜
+ */
+ @Operation(summary = "鑾峰緱涓�椤电敤鎴�", description = "杩斿洖涓�椤电敤鎴锋暟鎹�")
+ @ApiResponses(value = {
+ @ApiResponse(
+ responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
+ description = "杩斿洖榛樿瀵嗙爜锛圔aseResponse.content:password锛�",
+ content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
+ schema = @Schema(implementation = String.class))}
+ )
+ })
+ @GetMapping(path = "defaultPassword", consumes = MediaType.APPLICATION_JSON_VALUE)
+ public BaseResponse<String> defaultPassword(){
+ if(defaultTrueRandomFalsePassword){
+ return BaseResponseUtils.buildSuccess(defaultPassword) ;
+ }else{
+ String password = this.sv.getStringRandom(6) ;
+ return BaseResponseUtils.buildSuccess(password) ;
+ }
}
/**
@@ -248,11 +275,52 @@
}
/**
+ * 閲嶇疆瀵嗙爜
+ * @param vo form琛ㄥ崟瀵硅薄
+ * @return 鏄惁鎴愬姛
+ */
+ @Operation(summary = "閲嶇疆瀵嗙爜", description = "鎻愪氦鏁版嵁锛坒orm琛ㄥ崟json鏁版嵁锛夛紝杩涜瀵嗙爜閲嶇疆")
+ @ApiResponses(value = {
+ @ApiResponse(
+ responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
+ description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�",
+ content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
+ schema = @Schema(implementation = Boolean.class))}
+ )
+ })
+ @PostMapping(path = "resetPassword", consumes = MediaType.APPLICATION_JSON_VALUE)
+ @SsoAop("-1")//@SsoAop(power = "-1")
+ public BaseResponse<Boolean> resetPassword(@RequestBody @Parameter(description = "form琛ㄥ崟json鏁版嵁", required = true) ResetPasswordVo vo) throws Exception {
+ if (vo.id == null) {
+ return BaseResponseUtils.buildFail("id涓嶈兘涓虹┖");
+ }
+ String password = MD5.encrypt(vo.password);//杩涜鍔犲瘑鐮�
+ Long idLg = Long.parseLong(vo.id);
+ int count;
+ try {
+ BaUser po = this.sv.selectById(idLg);
+ if (Objects.isNull(po)) {
+ return BaseResponseUtils.buildFail("鏈緱鍒扮敤鎴凤紝璇锋眰澶辫触");
+ } else {
+ count = this.sv.changePassword(idLg, password);
+ }
+ } catch (Exception e) {
+ log.error("淇濆瓨鐢ㄦ埛寮傚父", e);
+ return BaseResponseUtils.buildException(e.getMessage());
+ }
+ if (count <= 0) {
+ return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�");
+ } else {
+ return BaseResponseUtils.buildSuccess(true);
+ }
+ }
+
+ /*
* 閲嶇疆瀵嗙爜涓洪粯璁ゅ��
*
* @param id 鐢ㄦ埛ID
* @return 鏄惁鎴愬姛
- */
+
@Operation(summary = "閲嶇疆瀵嗙爜涓洪粯璁ゅ瘑鐮�", description = "鎻愪氦鐢ㄦ埛ID")
@ApiResponses(value = {
@ApiResponse(
@@ -288,13 +356,14 @@
return BaseResponseUtils.buildSuccess(true);
}
}
+ */
- /**
+ /*
* 閲嶇疆瀵嗙爜涓洪殢鏈烘暟瀛楀姞瀛楁瘝
*
* @param id 鐢ㄦ埛ID
* @return 鏄惁鎴愬姛
- */
+
@Operation(summary = "閲嶇疆瀵嗙爜涓洪殢鏈烘暟瀛楀姞瀛楁瘝", description = "鎻愪氦鐢ㄦ埛ID")
@ApiResponses(value = {
@ApiResponse(
@@ -331,7 +400,7 @@
return BaseResponseUtils.buildSuccess(randomPassword);
}
}
-
+ */
/*
* 2023-12-05 鍦� save鍜寀pdate鏂规硶涓繘琛屼簡瑙掕壊璁剧疆鍏宠仈锛屾湰鏂规硶搴熷純
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/resources/application.yml b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/resources/application.yml
index 2162083..28a280a 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/resources/application.yml
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/resources/application.yml
@@ -2,6 +2,7 @@
profiles:
include: global, database, database-ym, database-pj
user:
+ defaultTrueRandomFalsePassword: true #true:閲囩敤榛樿瀵嗙爜锛宖alse:绯荤粺浜х敓闅忔満瀵嗙爜
defaultPassword: "ABC123"
#actutor鐨剋eb绔彛
--
Gitblit v1.8.0