From c837ebf94960a25aa36a460b7565b02b841dfb88 Mon Sep 17 00:00:00 2001 From: zhanghaining <2218834824@qq.com> Date: Sun, 15 Oct 2023 10:35:04 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"=E5=AE=8C=E5=96=84=E5=9F=BA=E6=9C=AC?= =?UTF-8?q?=E6=9D=83=E9=99=90=E9=89=B4=E5=AE=9A"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 1bf068db954f2d1b71d26b77696aaf9d9a2722fb. --- .../auth/controller/UserController.java | 38 ------- .../health/auth/feign/AuthFeignSystem.java | 25 ----- .../com/health/auth/service/UserService.java | 31 ------ .../auth/service/impl/UserServiceImpl.java | 98 ------------------- .../java/com/health/common/domain/User.java | 19 ---- .../health/common/domain/req/ReqLogin.java | 16 --- .../health/common/domain/resp/RespJWT.java | 13 --- 7 files changed, 240 deletions(-) delete mode 100644 health_auth/src/main/java/com/health/auth/controller/UserController.java delete mode 100644 health_auth/src/main/java/com/health/auth/feign/AuthFeignSystem.java delete mode 100644 health_auth/src/main/java/com/health/auth/service/UserService.java delete mode 100644 health_auth/src/main/java/com/health/auth/service/impl/UserServiceImpl.java delete mode 100644 health_common/src/main/java/com/health/common/domain/User.java delete mode 100644 health_common/src/main/java/com/health/common/domain/req/ReqLogin.java delete mode 100644 health_common/src/main/java/com/health/common/domain/resp/RespJWT.java diff --git a/health_auth/src/main/java/com/health/auth/controller/UserController.java b/health_auth/src/main/java/com/health/auth/controller/UserController.java deleted file mode 100644 index 25f40ed..0000000 --- a/health_auth/src/main/java/com/health/auth/controller/UserController.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.health.auth.controller; - -import com.health.auth.service.UserService; -import com.health.common.domain.User; -import com.health.common.domain.req.ReqLogin; -import com.health.common.domain.resp.RespJWT; -import com.health.common.result.Result; -import lombok.AllArgsConstructor; -import org.springframework.web.bind.annotation.*; - -import javax.servlet.http.HttpServletRequest; - -/** - * @author Administrator - */ -@RestController -@RequestMapping("/admin") -@AllArgsConstructor -public class UserController { - private final UserService userService; - - @PostMapping("/login") - public Result login(@RequestBody ReqLogin reqLogin){ - return userService.login(reqLogin); - } - - - @GetMapping("/user/info") - Result userinfo(HttpServletRequest request){ - return userService.userinfo(request); - - } - - - - - -} diff --git a/health_auth/src/main/java/com/health/auth/feign/AuthFeignSystem.java b/health_auth/src/main/java/com/health/auth/feign/AuthFeignSystem.java deleted file mode 100644 index 8be3a75..0000000 --- a/health_auth/src/main/java/com/health/auth/feign/AuthFeignSystem.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.health.auth.feign; - -import com.health.common.domain.User; -import com.health.common.result.Result; -import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; - - -/** - * @author Administrator - */ -@FeignClient("base_system") -public interface AuthFeignSystem { - - /** - * 到系统模块去查找用户 - * @param userName - * @return result风格的user对象(用户信息) - */ - @GetMapping("/user/byUserName/{userName}") - Result byUserName(@PathVariable String userName); - - -} diff --git a/health_auth/src/main/java/com/health/auth/service/UserService.java b/health_auth/src/main/java/com/health/auth/service/UserService.java deleted file mode 100644 index 3030b2b..0000000 --- a/health_auth/src/main/java/com/health/auth/service/UserService.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.health.auth.service; - -import com.health.common.domain.User; -import com.health.common.domain.req.ReqLogin; -import com.health.common.domain.resp.RespJWT; -import com.health.common.result.Result; - -import javax.servlet.http.HttpServletRequest; - -/** - * @author Administrator - */ -public interface UserService { - - - /** - * 登录方法--获取token - * @param reqLogin - * @return 返回result格式的jwt包含:(token,过期时间) - */ - Result login(ReqLogin reqLogin); - - /** - * 每次都对请求做权限判断 - * @param request - * @return 返回result格式的User对象包含:(用户信息) - */ - Result userinfo(HttpServletRequest request); - - -} diff --git a/health_auth/src/main/java/com/health/auth/service/impl/UserServiceImpl.java b/health_auth/src/main/java/com/health/auth/service/impl/UserServiceImpl.java deleted file mode 100644 index c2d5928..0000000 --- a/health_auth/src/main/java/com/health/auth/service/impl/UserServiceImpl.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.health.auth.service.impl; - -import com.alibaba.fastjson.JSONObject; -import com.health.auth.feign.AuthFeignSystem; -import com.health.auth.service.UserService; -import com.health.common.constants.JwtConstants; -import com.health.common.constants.TokenConstants; -import com.health.common.domain.User; -import com.health.common.domain.req.ReqLogin; -import com.health.common.domain.resp.RespJWT; -import com.health.common.result.Result; -import com.health.common.utils.JwtUtils; -import com.health.common.utils.StringUtils; -import lombok.AllArgsConstructor; -import lombok.extern.log4j.Log4j2; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Service; - -import javax.servlet.http.HttpServletRequest; -import java.util.HashMap; -import java.util.UUID; -import java.util.concurrent.TimeUnit; - -/** - * 用户登录业务层 - * @author Administrator - * @date 2023年10月15日 09点48分 - */ -@Service -@Log4j2 -@AllArgsConstructor -public class UserServiceImpl implements UserService { - - private final AuthFeignSystem authFeignSystem; - private final RedisTemplate redisTemplate; - - - /** - * 登录方法--获取token - * - * @param reqLogin - * @return 返回result格式的jwt包含:(token,过期时间) - */ - @Override - public Result login(ReqLogin reqLogin) { - if (StringUtils.isEmpty(reqLogin.getUsername())){ - return Result.error("用户名为空!"); - } - if (StringUtils.isEmpty(reqLogin.getPassword())){ - return Result.error("密码为空!"); - - } - String username = reqLogin.getUsername(); - - - Result userResult = authFeignSystem.byUserName(username); - User data = userResult.getData(); - if (null == data) { - return Result.error("先注册手机号,在登录"); - } - HashMap map = new HashMap<>(); - String userkey = UUID.randomUUID().toString().replaceAll("-", ""); - map.put(JwtConstants.USER_KEY, userkey); - map.put(JwtConstants.DETAILS_USER_ID, data.getId()); - String token = JwtUtils.createToken(map); - redisTemplate.opsForValue().set( - TokenConstants.LOGIN_TOKEN_KEY + userkey, - JSONObject.toJSONString(data), - TokenConstants.EXPIRATION, - TimeUnit.MINUTES - ); - RespJWT respJWT = new RespJWT(); - respJWT.setToken(token); - respJWT.setEidTime("720MIN"); - - return Result.success(respJWT); - - } - - /** - * 每次都对请求做权限判断 - * - * @param request - * @return 返回result格式的User对象包含:(用户信息) - */ - @Override - public Result userinfo(HttpServletRequest request) { - - String token = request.getHeader(TokenConstants.TOKEN); - String userKey = JwtUtils.getUserKey(token); - String s = redisTemplate.opsForValue().get( - TokenConstants.LOGIN_TOKEN_KEY + userKey - ); - User user = JSONObject.parseObject(s, User.class); - return Result.success(user); - - } -} diff --git a/health_common/src/main/java/com/health/common/domain/User.java b/health_common/src/main/java/com/health/common/domain/User.java deleted file mode 100644 index 377029a..0000000 --- a/health_common/src/main/java/com/health/common/domain/User.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.health.common.domain; - -import lombok.Data; - -/** - * @author Administrator - */ -@Data -public class User { - - private Integer id; - private String username; - private String password; - private String emil; - - - - -} diff --git a/health_common/src/main/java/com/health/common/domain/req/ReqLogin.java b/health_common/src/main/java/com/health/common/domain/req/ReqLogin.java deleted file mode 100644 index c6f852f..0000000 --- a/health_common/src/main/java/com/health/common/domain/req/ReqLogin.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.health.common.domain.req; - -import lombok.Data; - -/** - * @author Administrator - */ -@Data -public class ReqLogin { - private Integer id; - private String username; - private String password; - private String emil; - - -} diff --git a/health_common/src/main/java/com/health/common/domain/resp/RespJWT.java b/health_common/src/main/java/com/health/common/domain/resp/RespJWT.java deleted file mode 100644 index b9a3a74..0000000 --- a/health_common/src/main/java/com/health/common/domain/resp/RespJWT.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.health.common.domain.resp; - -import lombok.Data; - -/** - * @author Administrator - */ -@Data -public class RespJWT { - - private String token; - private String eidTime; -}