Procházet zdrojové kódy

子公司页面修改

anderx před 4 roky
rodič
revize
91e6998b26

+ 40 - 0
src/main/java/com/kede/core/shiro/filter/DeviceFilter.java

@@ -0,0 +1,40 @@
+package com.kede.core.shiro.filter;
+
+import com.kede.common.utils.LoggerUtils;
+import org.apache.shiro.web.filter.AccessControlFilter;
+import org.apache.shiro.web.util.WebUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+
+public class DeviceFilter extends  AccessControlFilter{
+
+	@Autowired
+	private ShiroFilterUtils shiroFilterUtils;
+	
+
+	private static String mobileWebsite="m.kedexinxi.com";
+	
+	@Override
+	protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue)
+			throws Exception {
+		if (!shiroFilterUtils.isFromAPP((HttpServletRequest)request) && shiroFilterUtils.isMobileDevice((HttpServletRequest)request) 
+				&& !request.getServerName().startsWith("m")){
+			return false;
+		}
+		return true;
+	}
+
+	@Override
+	protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
+		if (!shiroFilterUtils.isFromAPP((HttpServletRequest)request) && shiroFilterUtils.isMobileDevice((HttpServletRequest)request)
+				&& !request.getServerName().startsWith("m")){
+			LoggerUtils.debug(getClass(), "当前访问为移动设备");
+			WebUtils.issueRedirect(request, response, mobileWebsite,null,false);
+		}
+		return false;
+	}
+}

+ 18 - 0
src/main/java/com/kede/core/shiro/filter/ShiroFilterUtils.java

@@ -33,6 +33,24 @@ public class ShiroFilterUtils {
 	}
 
 	/**
+	 * 判断是否来自移动设备
+	 * @param request
+	 * @return
+	 */
+	public boolean isMobileDevice(HttpServletRequest request) {
+		String[] deviceArray = new String[]{"android","blackBerry","windows phone","iphone","ipod","ipad"};
+		if(request.getHeader("User-Agent") != null){
+			String agent = request.getHeader("User-Agent");
+			for(int i = 0; i<deviceArray.length; i++){
+				if(agent.toLowerCase().indexOf(deviceArray[i]) >0 ){
+					return true;
+				}
+			}
+		}
+		return false;
+	}
+
+	/**
 	 * 
 	 * @param request
 	 * @return true if App request

+ 2 - 4
src/main/resources/props/config_local.properties

@@ -60,13 +60,11 @@ template.cacheable=false
 
 avatar.upload.host=//172.16.0.255:3000/upload
 #连接开�
-#portal.host=//kedejs.jishutao.com/portal/1.0.11
+portal.host=//kedejs.jishutao.com/portal/1.0.16
 static.host=//kedejs.jishutao.com/client/1.0.4
 avatar.host=//172.16.0.255:3000
 
-#连生产
-portal.host=//172.16.0.74/portal/1.0.16
-#static.host=//s.kedexinxi.com/1.1.06
+
 
 upload.path=F:/data/public/upload
 upload.private.path=F:/data/private/upload

+ 1 - 3
src/main/resources/props/config_prod.properties

@@ -67,9 +67,7 @@ static.host=//kedejs.jishutao.com/client/1.0.4
 avatar.host=//kedejs.jishutao.com
 avatar.upload.host=//kedejs.jishutao.com/upload
 
-#连生产
-#avatar.host=//static.kedexinxi.com
-#static.host=//s.kedexinxi.com/1.1.06
+
 
 
 upload.path=/data/kede/public/upload

+ 1 - 1
src/main/resources/shiro_base_auth.ini

@@ -16,7 +16,7 @@
 /mregister=anon
 /favicon.ico=anon
 /static/**=anon
-/portal/**=anon
+/portal/**=device
 /api/portal/**=anon
 /api/admin/**=admin
 /api/user/**=user

+ 3 - 0
src/main/resources/spring/spring-shiro.xml

@@ -148,6 +148,9 @@
 						<property name="loginUrl" value="/error" />
 					</bean>
 				</entry>
+				<entry key="device">
+					<bean id="device" class="com.kede.core.shiro.filter.DeviceFilter"></bean>
+				</entry>
 			</util:map>
 		</property>
 	</bean>

+ 5 - 10
src/main/webapp/WEB-INF/views/common.html

@@ -609,16 +609,11 @@
         var _hmt = _hmt || [];
         (function() {
             var hm = document.createElement("script");
-            hm.src = "https://hm.baidu.com/hm.js?e20e700f2bb1656e3253cb466c60f15b";
-            var s = document.getElementsByTagName("script")[0];
-            s.parentNode.insertBefore(hm, s);
-        })();
-    </script>
-    <script  th:if="${type}!='houtai'">
-        var _hmt = _hmt || [];
-        (function() {
-            var hm = document.createElement("script");
-            hm.src = "https://hm.baidu.com/hm.js?449ffa31018ec643cfeb386fb4978746";
+            if((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
+                hm.src = "https://hm.baidu.com/hm.js?c2a7fd3c1093d8dbd0be9106b4027797"; //移动
+            }else{
+                hm.src = "https://hm.baidu.com/hm.js?e20e700f2bb1656e3253cb466c60f15b"; //pc
+            }
             var s = document.getElementsByTagName("script")[0];
             s.parentNode.insertBefore(hm, s);
         })();