From b353876b481c1213e5bea53c8cb96059ca5b1c9a Mon Sep 17 00:00:00 2001 From: tamguo Date: Fri, 20 Jul 2018 18:33:32 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/tamguo/config/WebConfig.java | 11 +++ .../config/shiro/ShiroConfiguration.java | 4 +- .../sys/interceptor/SettingsInterceptor.java | 39 ++++++++ .../com/tamguo/modules/sys/utils/Setting.java | 5 + .../modules/sys/web/ValidCodeController.java | 11 +++ .../src/main/resources/application.properties | 2 + .../resources/static/modules/sys/sysLogin.js | 34 +++++-- .../main/resources/templates/sysLogin.html | 92 ++++++++----------- 8 files changed, 137 insertions(+), 61 deletions(-) create mode 100644 tamguo-oms/src/main/java/com/tamguo/modules/sys/interceptor/SettingsInterceptor.java diff --git a/tamguo-oms/src/main/java/com/tamguo/config/WebConfig.java b/tamguo-oms/src/main/java/com/tamguo/config/WebConfig.java index 73b06a2..f14b0d7 100644 --- a/tamguo-oms/src/main/java/com/tamguo/config/WebConfig.java +++ b/tamguo-oms/src/main/java/com/tamguo/config/WebConfig.java @@ -1,20 +1,31 @@ package com.tamguo.config; import java.util.Properties; + +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import com.google.code.kaptcha.impl.DefaultKaptcha; import com.google.code.kaptcha.util.Config; +import com.tamguo.modules.sys.interceptor.SettingsInterceptor; @Configuration public class WebConfig implements WebMvcConfigurer { @Value("${file.storage.path}") private String fileStoragePath; + @Autowired + private SettingsInterceptor settingsInterceptor; + + @Override + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(settingsInterceptor).addPathPatterns("/**"); + } @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { diff --git a/tamguo-oms/src/main/java/com/tamguo/config/shiro/ShiroConfiguration.java b/tamguo-oms/src/main/java/com/tamguo/config/shiro/ShiroConfiguration.java index d5d5622..e9bb779 100644 --- a/tamguo-oms/src/main/java/com/tamguo/config/shiro/ShiroConfiguration.java +++ b/tamguo-oms/src/main/java/com/tamguo/config/shiro/ShiroConfiguration.java @@ -80,12 +80,12 @@ public class ShiroConfiguration { filterChainDefinitionMap.put("/my97/**", "anon"); filterChainDefinitionMap.put("/select2/**", "anon"); filterChainDefinitionMap.put("/sysLogin/**", "anon"); - filterChainDefinitionMap.put("/sysIndex/**", "anon"); filterChainDefinitionMap.put("/validCode", "anon"); + filterChainDefinitionMap.put("/checkCode", "anon"); filterChainDefinitionMap.put("/wdScrollTab/**", "anon"); filterChainDefinitionMap.put("/jquery-timeago/**", "anon"); - // filterChainDefinitionMap.put("/**", "authc"); + filterChainDefinitionMap.put("/**", "authc"); shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap); return shiroFilterFactoryBean; } diff --git a/tamguo-oms/src/main/java/com/tamguo/modules/sys/interceptor/SettingsInterceptor.java b/tamguo-oms/src/main/java/com/tamguo/modules/sys/interceptor/SettingsInterceptor.java new file mode 100644 index 0000000..d0c947a --- /dev/null +++ b/tamguo-oms/src/main/java/com/tamguo/modules/sys/interceptor/SettingsInterceptor.java @@ -0,0 +1,39 @@ +package com.tamguo.modules.sys.interceptor; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.stereotype.Component; +import org.springframework.web.servlet.HandlerInterceptor; +import org.springframework.web.servlet.ModelAndView; + +import com.tamguo.modules.sys.utils.Setting; + +@Component +public class SettingsInterceptor implements HandlerInterceptor { + + @Resource + private Setting setting; + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) + throws Exception { + //在请求处理之前进行调用(Controller方法调用之前) + return true; + } + + @Override + public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, + ModelAndView modelAndView) throws Exception { + // 设置系统变量 + request.setAttribute("setting", setting); + } + + @Override + public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) + throws Exception { + //在整个请求结束之后被调用,也就是在DispatcherServlet 渲染了对应的视图之后执行(主要是用于进行资源清理工作) + } + +} diff --git a/tamguo-oms/src/main/java/com/tamguo/modules/sys/utils/Setting.java b/tamguo-oms/src/main/java/com/tamguo/modules/sys/utils/Setting.java index e7e9987..e1eb604 100644 --- a/tamguo-oms/src/main/java/com/tamguo/modules/sys/utils/Setting.java +++ b/tamguo-oms/src/main/java/com/tamguo/modules/sys/utils/Setting.java @@ -15,6 +15,11 @@ public final class Setting { /** 域名 */ @Value(value="${domain.name}") public String domain; + /** 静态资源地址*/ + @Value(value="${static.domain}") + public String staticDomain; + @Value(value="${version}") + public String version; /** 真题 */ public final String PAPER_TYPE_ZHENTI = "1"; /** 模拟*/ diff --git a/tamguo-oms/src/main/java/com/tamguo/modules/sys/web/ValidCodeController.java b/tamguo-oms/src/main/java/com/tamguo/modules/sys/web/ValidCodeController.java index 156d3c2..f6aa5b4 100644 --- a/tamguo-oms/src/main/java/com/tamguo/modules/sys/web/ValidCodeController.java +++ b/tamguo-oms/src/main/java/com/tamguo/modules/sys/web/ValidCodeController.java @@ -11,6 +11,7 @@ import javax.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; import com.google.code.kaptcha.Constants; import com.google.code.kaptcha.Producer; @@ -36,4 +37,14 @@ public class ValidCodeController { ImageIO.write(image, "jpg", out); } + @RequestMapping("checkCode") + @ResponseBody + public Boolean checkCode(String validCode) throws ServletException, IOException { + String kaptcha = ShiroUtils.getKaptcha(Constants.KAPTCHA_SESSION_KEY); + if (!validCode.equalsIgnoreCase(kaptcha)) { + return true; + } + return false; + } + } diff --git a/tamguo-oms/src/main/resources/application.properties b/tamguo-oms/src/main/resources/application.properties index d8832b7..4cd3267 100644 --- a/tamguo-oms/src/main/resources/application.properties +++ b/tamguo-oms/src/main/resources/application.properties @@ -1,4 +1,6 @@ domain.name=http://localhost/ +static.domain=http://localhost/ +version=V1.0.0 server.port=80 jasypt.encryptor.password=tamguo diff --git a/tamguo-oms/src/main/resources/static/modules/sys/sysLogin.js b/tamguo-oms/src/main/resources/static/modules/sys/sysLogin.js index 37d84ed..3e54b3c 100644 --- a/tamguo-oms/src/main/resources/static/modules/sys/sysLogin.js +++ b/tamguo-oms/src/main/resources/static/modules/sys/sysLogin.js @@ -1,7 +1,27 @@ -/*! - * Copyright (c) 2013-Now http://jeesite.com All rights reserved. - * - * @author ThinkGem - * @version 2017-4-18 - */ -$("#username, #password").on("focus blur",function(){var a=this;setTimeout(function(){var b=$(a).css("borderColor");if(b!=""){$(a).prev().css("color",b)}},100)}).blur();$("#loginForm").validate({submitHandler:function(c){var d=$("#username").val(),a=$("#password").val(),b=$("#validCode").val();if(secretKey!=""){$("#username").val(DesUtils.encode(d,secretKey));$("#password").val(DesUtils.encode(a,secretKey));$("#validCode").val(DesUtils.encode(b,secretKey))}js.ajaxSubmitForm($(c),function(f,e,g){if(f.isValidCodeLogin==true){$("#isValidCodeLogin").show();$("#validCodeRefresh").click()}if(f.result=="false"&&f.message.length>0){js.showMessage(f.message)}else{js.loading($("#btnSubmit").data("loading"));location=ctx+"/index"}},"json",true,$("#btnSubmit").data("loginValid"));$("#username").val(d);$("#password").val(a).select().focus();$("#validCode").val(b)}}); \ No newline at end of file +$("#username, #password").on("focus blur", function() { + var a = this; + setTimeout(function() { + var b = $(a).css("borderColor"); + if (b != "") { + $(a).prev().css("color", b) + } + }, 100) +}).blur(); +$("#loginForm").validate({ + submitHandler: function(c) { + var d = $("#username").val() + , a = $("#password").val() + , b = $("#validCode").val(); + js.ajaxSubmitForm($(c), function(f, e, g) { + if (f.result == "false" && f.message.length > 0) { + js.showMessage(f.message) + } else { + js.loading($("#btnSubmit").data("loading")); + location = ctx + "/index" + } + }, "json", true, $("#btnSubmit").data("loginValid")); + $("#username").val(d); + $("#password").val(a).select().focus(); + $("#validCode").val(b) + } +}); diff --git a/tamguo-oms/src/main/resources/templates/sysLogin.html b/tamguo-oms/src/main/resources/templates/sysLogin.html index 5824f90..993b0d3 100644 --- a/tamguo-oms/src/main/resources/templates/sysLogin.html +++ b/tamguo-oms/src/main/resources/templates/sysLogin.html @@ -1,44 +1,38 @@ - - + + - - - + + + - + 登录 - Tamguo OMS - - + + - - - - - - - + + + + + + +
- - - - - + + +
- - - - - - - - - - - - - - - - \ No newline at end of file + + + + + + + + + + + + + + + + \ No newline at end of file