From 47d39878f7f166a2ef4fcfd905f7bbb0622a39bd Mon Sep 17 00:00:00 2001 From: aoshiguchen <1052045476@qq.com> Date: Tue, 2 Aug 2022 22:39:58 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E9=A1=B5=E9=9D=A2=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=AF=B9=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../neutrino/core/web/HttpRequestHandler.java | 7 +++ neutrino-proxy-admin/src/api/system.js | 9 ++++ .../src/views/login/index.vue | 18 ++++--- .../server/controller/IndexController.java | 2 - .../server/controller/Test1Controller.java | 51 ------------------- .../proxy/server/dal/UserTokenMapper.java | 1 + .../proxy/server/service/Test1Service.java | 21 -------- 7 files changed, 29 insertions(+), 80 deletions(-) create mode 100644 neutrino-proxy-admin/src/api/system.js delete mode 100644 neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/Test1Controller.java delete mode 100644 neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/Test1Service.java diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/HttpRequestHandler.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/HttpRequestHandler.java index 3d9de77c..95737cbb 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/HttpRequestHandler.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/HttpRequestHandler.java @@ -72,12 +72,19 @@ public class HttpRequestHandler { public void handle() { ChannelHandlerContext context = HttpContextHolder.getChannelHandlerContext(); HttpRequestWrapper requestParser = HttpContextHolder.getHttpRequestWrapper(); + HttpResponseWrapper responseWrapper = HttpContextHolder.getHttpResponseWrapper(); log.info("HttpRequest method:{} url:{} query:{}", requestParser.getMethod().name(), requestParser.getUrl(), requestParser.getQueryParamMap()); try { String routePath = requestParser.getRoutePath(); HttpMethod httpMethod = HttpMethod.of(requestParser.getMethod().name()); if (httpMethod == HttpMethod.OPTIONS) { + responseWrapper.headers().add("Access-Control-Allow-Origin", "*"); + responseWrapper.headers().add("Access-Control-Allow-Methods", "POST, GET, OPTIONS"); + responseWrapper.headers().add("Access-Control-Max-Age", "86400"); + responseWrapper.headers().add("Access-Control-Allow-Headers", "*"); + responseWrapper.headers().add("Access-Control-Allow-Credentials", "true"); + responseWrapper.headers().add("XDomainRequestAllowed", "1"); HttpServerUtil.sendResponse(HttpResponseStatus.OK); return; } diff --git a/neutrino-proxy-admin/src/api/system.js b/neutrino-proxy-admin/src/api/system.js new file mode 100644 index 00000000..68e60b3b --- /dev/null +++ b/neutrino-proxy-admin/src/api/system.js @@ -0,0 +1,9 @@ +import request from '@/utils/request' + +export function login(data) { + return request({ + url: '/login', + method: 'post', + data + }) +} diff --git a/neutrino-proxy-admin/src/views/login/index.vue b/neutrino-proxy-admin/src/views/login/index.vue index 9bd2d7a5..df761c74 100644 --- a/neutrino-proxy-admin/src/views/login/index.vue +++ b/neutrino-proxy-admin/src/views/login/index.vue @@ -36,6 +36,7 @@ import { isvalidUsername } from '@/utils/validate' import LangSelect from '@/components/LangSelect' import SocialSign from './socialsignin' +import { login } from '@/api/system' export default { components: { LangSelect, SocialSign }, @@ -58,7 +59,7 @@ export default { return { loginForm: { username: 'admin', - password: '1111111' + password: '123456' }, loginRules: { username: [{ required: true, trigger: 'blur', validator: validateUsername }], @@ -81,11 +82,16 @@ export default { this.$refs.loginForm.validate(valid => { if (valid) { this.loading = true - this.$store.dispatch('LoginByUsername', this.loginForm).then(() => { - this.loading = false - this.$router.push({ path: '/' }) - }).catch(() => { - this.loading = false + login({ + loginName: this.loginForm.username, + loginPassword: this.loginForm.password + }).then(() => { + this.$store.dispatch('LoginByUsername', this.loginForm).then(() => { + this.loading = false + this.$router.push({ path: '/' }) + }).catch(() => { + this.loading = false + }) }) } else { console.log('error submit!!') 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 95293af6..c02634ab 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 @@ -29,9 +29,7 @@ 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.controller.res.LogoutRes; import fun.asgc.neutrino.proxy.server.service.UserService; import fun.asgc.neutrino.proxy.server.util.ParamCheckUtil; diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/Test1Controller.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/Test1Controller.java deleted file mode 100644 index 4dcea204..00000000 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/Test1Controller.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * 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; - -import fun.asgc.neutrino.core.annotation.Autowired; -import fun.asgc.neutrino.core.web.annotation.GetMapping; -import fun.asgc.neutrino.core.web.annotation.RequestMapping; -import fun.asgc.neutrino.core.web.annotation.RestController; -import fun.asgc.neutrino.core.web.context.HttpContextHolder; -import fun.asgc.neutrino.proxy.server.service.Test1Service; - -/** - * - * @author: aoshiguchen - * @date: 2022/7/17 - */ -@RestController -@RequestMapping("/test1") -public class Test1Controller { - @Autowired - private Test1Service test1Service; - - @GetMapping("hello") - public String hello() { - System.out.println("拿到参数 a = " + HttpContextHolder.getHttpRequestWrapper().getParameter("a")); - if ("aaa".equals(HttpContextHolder.getHttpRequestWrapper().getParameter("a"))) { - throw new RuntimeException("hhhh 异常了!"); - } - return test1Service.hello(); - } - -} diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/UserTokenMapper.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/UserTokenMapper.java index 9545e243..4d995e92 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/UserTokenMapper.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/UserTokenMapper.java @@ -48,6 +48,7 @@ public interface UserTokenMapper extends SqlMapper { /** * 根据token查询单条记录 * @param token + * @param time * @return */ @Select("select * from user_token where token = ? and expiration_time > ?") diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/Test1Service.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/Test1Service.java deleted file mode 100644 index 41a57574..00000000 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/Test1Service.java +++ /dev/null @@ -1,21 +0,0 @@ -package fun.asgc.neutrino.proxy.server.service; - -import fun.asgc.neutrino.core.annotation.Component; - -import java.text.SimpleDateFormat; -import java.util.Date; - -/** - * - * @author: aoshiguchen - * @date: 2022/7/20 - */ -@Component -public class Test1Service { - private static final SimpleDateFormat SDF = new SimpleDateFormat( "yyyy-MM-dd :HH:mm:ss"); - - public String hello() { - return "hello 现在时间是:" + SDF.format(new Date()); - } - -}