From a5a2ef8a6269dc0ad7a18b041385df66091e1ba1 Mon Sep 17 00:00:00 2001 From: aoshiguchen <1052045476@qq.com> Date: Tue, 2 Aug 2022 00:03:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=80=80=E5=87=BA=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/IndexController.java | 35 ++++++------------ .../server/controller/req/LogoutReq.java | 34 ++++++++++++++++++ .../server/controller/res/LogoutRes.java | 36 +++++++++++++++++++ .../proxy/server/service/UserService.java | 33 ++++++++++++++--- 4 files changed, 108 insertions(+), 30 deletions(-) create mode 100644 neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/LogoutReq.java create mode 100644 neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/LogoutRes.java diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/IndexController.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/IndexController.java index 399eea75..3e246ce3 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/IndexController.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/IndexController.java @@ -27,17 +27,14 @@ import fun.asgc.neutrino.core.web.annotation.PostMapping; import fun.asgc.neutrino.core.web.annotation.RequestBody; import fun.asgc.neutrino.core.web.annotation.RequestMapping; import fun.asgc.neutrino.core.web.annotation.RestController; +import fun.asgc.neutrino.proxy.server.base.rest.Authorization; import fun.asgc.neutrino.proxy.server.controller.req.LoginReq; +import fun.asgc.neutrino.proxy.server.controller.req.LogoutReq; import fun.asgc.neutrino.proxy.server.controller.res.LoginRes; -import fun.asgc.neutrino.proxy.server.dal.entity.UserDO; -import fun.asgc.neutrino.proxy.server.dal.entity.UserTokenDO; +import fun.asgc.neutrino.proxy.server.controller.res.LogoutRes; import fun.asgc.neutrino.proxy.server.service.UserService; -import fun.asgc.neutrino.proxy.server.util.Md5Util; import fun.asgc.neutrino.proxy.server.util.ParamCheckUtil; -import java.util.Date; -import java.util.UUID; - /** * * @author: aoshiguchen @@ -50,31 +47,19 @@ public class IndexController { @Autowired private UserService userService; + @Authorization(login = false) @PostMapping("login") public LoginRes login(@RequestBody LoginReq req) { ParamCheckUtil.checkNotEmpty(req.getLoginName(), "loginName"); ParamCheckUtil.checkNotEmpty(req.getLoginPassword(), "loginPassword"); - UserDO userDO = userService.findByLoginName(req.getLoginName()); - if (null == userDO || !Md5Util.encode(req.getLoginPassword()).equals(userDO.getLoginPassword())) { - // TODO 抛出异常 - } - String token = UUID.randomUUID().toString().replaceAll("-", ""); + return userService.login(req); + } - Date now = new Date(); - // TODO 计算过期时间 - userService.addUserToken(new UserTokenDO() - .setToken(token) - .setUserId(userDO.getId()) - .setExpirationTime(now) - .setCreateTime(now) - .setUpdateTime(now) - ); - - return new LoginRes() - .setToken(token) - .setUserId(userDO.getId()) - .setUserName(userDO.getName()); + @PostMapping("logout") + public LogoutRes logout(@RequestBody LogoutReq req) { + // TODO + return null; } } diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/LogoutReq.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/LogoutReq.java new file mode 100644 index 00000000..616ef5f0 --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/LogoutReq.java @@ -0,0 +1,34 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.proxy.server.controller.req; + +import lombok.Data; + +/** + * 退出登录请求参数 + * @author: aoshiguchen + * @date: 2022/8/1 + */ +@Data +public class LogoutReq { + +} diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/LogoutRes.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/LogoutRes.java new file mode 100644 index 00000000..232f2ac7 --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/LogoutRes.java @@ -0,0 +1,36 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.proxy.server.controller.res; + +import lombok.Data; +import lombok.experimental.Accessors; + +/** + * 退出登录响应参数 + * @author: aoshiguchen + * @date: 2022/8/2 + */ +@Accessors(chain = true) +@Data +public class LogoutRes { + +} diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/UserService.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/UserService.java index e047fda9..187c2920 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/UserService.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/UserService.java @@ -23,10 +23,17 @@ package fun.asgc.neutrino.proxy.server.service; import fun.asgc.neutrino.core.annotation.Autowired; import fun.asgc.neutrino.core.annotation.Component; +import fun.asgc.neutrino.core.web.annotation.RequestBody; +import fun.asgc.neutrino.proxy.server.controller.req.LoginReq; +import fun.asgc.neutrino.proxy.server.controller.res.LoginRes; import fun.asgc.neutrino.proxy.server.dal.UserMapper; import fun.asgc.neutrino.proxy.server.dal.UserTokenMapper; import fun.asgc.neutrino.proxy.server.dal.entity.UserDO; import fun.asgc.neutrino.proxy.server.dal.entity.UserTokenDO; +import fun.asgc.neutrino.proxy.server.util.Md5Util; + +import java.util.Date; +import java.util.UUID; /** * @@ -40,13 +47,29 @@ public class UserService { @Autowired private UserTokenMapper userTokenMapper; + public LoginRes login(LoginReq req) { + UserDO userDO = userMapper.findByLoginName(req.getLoginName()); + if (null == userDO || !Md5Util.encode(req.getLoginPassword()).equals(userDO.getLoginPassword())) { + // TODO 抛出异常 + } + String token = UUID.randomUUID().toString().replaceAll("-", ""); - public UserDO findByLoginName(String loginName) { - return userMapper.findByLoginName(loginName); - } + Date now = new Date(); + // TODO 计算过期时间 + userTokenMapper.add(new UserTokenDO() + .setToken(token) + .setUserId(userDO.getId()) + .setExpirationTime(now) + .setCreateTime(now) + .setUpdateTime(now) + ); - public void addUserToken(UserTokenDO userTokenDO) { - userTokenMapper.add(userTokenDO); + // TODO 新增登录日志 + + return new LoginRes() + .setToken(token) + .setUserId(userDO.getId()) + .setUserName(userDO.getName()); } }