Browse Source

加入用户注销功能,只是简单的注销,团队没有做处理

Yangzw 1 week ago
parent
commit
0026ebdc29

+ 15 - 0
feifan-module-member/feifan-module-member-biz/src/main/java/cn/newfeifan/mall/module/member/controller/app/auth/AppAuthController.java

@@ -63,6 +63,21 @@ public class AppAuthController {
         return success(true);
         return success(true);
     }
     }
 
 
+    @PostMapping("/deleteUser")
+    @Operation(summary = "用户注销")
+    @Parameter(name = "deleteUser", description = "用户注销", required = true)
+    public CommonResult<Boolean> deleteUser(HttpServletRequest request){
+        authService.deleteUser(getLoginUserId());
+
+        String token = SecurityFrameworkUtils.obtainAuthorization(request,
+                securityProperties.getTokenHeader(), securityProperties.getTokenParameter());
+        if (StrUtil.isNotBlank(token)) {
+            authService.logout(token);
+        }
+
+        return success(true);
+    }
+
     @PostMapping("/refresh-token")
     @PostMapping("/refresh-token")
     @Operation(summary = "刷新令牌")
     @Operation(summary = "刷新令牌")
     @Parameter(name = "refreshToken", description = "刷新令牌", required = true)
     @Parameter(name = "refreshToken", description = "刷新令牌", required = true)

+ 6 - 0
feifan-module-member/feifan-module-member-biz/src/main/java/cn/newfeifan/mall/module/member/service/auth/MemberAuthService.java

@@ -103,4 +103,10 @@ public interface MemberAuthService {
      * @return 跳转登录
      * @return 跳转登录
      */
      */
     String redirectLogin();
     String redirectLogin();
+
+    /**
+     * 注销用户
+     * @param loginUserId 用户id
+     */
+    void deleteUser(Long loginUserId);
 }
 }

+ 5 - 0
feifan-module-member/feifan-module-member-biz/src/main/java/cn/newfeifan/mall/module/member/service/auth/MemberAuthServiceImpl.java

@@ -220,6 +220,11 @@ public class MemberAuthServiceImpl implements MemberAuthService {
         return url + "/login" + "?accessToken=" + token.getAccessToken() + "&refreshToken=" + token.getRefreshToken();
         return url + "/login" + "?accessToken=" + token.getAccessToken() + "&refreshToken=" + token.getRefreshToken();
     }
     }
 
 
+    @Override
+    public void deleteUser(Long loginUserId) {
+        userService.deleteUserById(loginUserId);
+    }
+
     @Override
     @Override
     public AppAuthLoginRespVO weixinMiniAppLogin(AppAuthWeixinMiniAppLoginReqVO reqVO) {
     public AppAuthLoginRespVO weixinMiniAppLogin(AppAuthWeixinMiniAppLoginReqVO reqVO) {
         // 获得对应的手机号信息
         // 获得对应的手机号信息

+ 6 - 0
feifan-module-member/feifan-module-member-biz/src/main/java/cn/newfeifan/mall/module/member/service/user/MemberUserService.java

@@ -280,4 +280,10 @@ public interface MemberUserService {
      * @return 用户名
      * @return 用户名
      */
      */
     String getUsernameByUserId(Long userId);
     String getUsernameByUserId(Long userId);
+
+    /**
+     * 注销用户
+     * @param loginUserId 用户id
+     */
+    void deleteUserById(Long loginUserId);
 }
 }

+ 5 - 0
feifan-module-member/feifan-module-member-biz/src/main/java/cn/newfeifan/mall/module/member/service/user/MemberUserServiceImpl.java

@@ -520,6 +520,11 @@ public class MemberUserServiceImpl implements MemberUserService {
         return null;
         return null;
     }
     }
 
 
+    @Override
+    public void deleteUserById(Long loginUserId) {
+        memberUserMapper.deleteById(loginUserId);
+    }
+
     private Boolean isSubscribe(String openid, int maxRetries) {
     private Boolean isSubscribe(String openid, int maxRetries) {
         String requestUrl = StrUtil.format("https://api.weixin.qq.com/cgi-bin/user/info?access_token={}&openid={}&lang=zh_CN", getAccessToken(), openid);
         String requestUrl = StrUtil.format("https://api.weixin.qq.com/cgi-bin/user/info?access_token={}&openid={}&lang=zh_CN", getAccessToken(), openid);
         String returnMsg = HttpUtil.get(requestUrl);
         String returnMsg = HttpUtil.get(requestUrl);