浏览代码

清除cookie登录失效后刷新验证码请求无法显示的问题

EDZ 4 年之前
父节点
当前提交
972bf442e4

+ 15 - 0
src/main/java/net/chenlin/dp/common/xss/XssFilter.java

@@ -2,6 +2,7 @@ package net.chenlin.dp.common.xss;
 
 import javax.servlet.*;
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.util.List;
 
@@ -25,6 +26,20 @@ public class XssFilter implements Filter {
 		HttpServletRequest httpServletRequest = (HttpServletRequest) request;
 		String servletPath = httpServletRequest.getServletPath();
 		httpServletRequest.getParameterMap();
+		/**
+		 * 过滤器实现解决ajax跨域问题
+		 */
+		HttpServletResponse res = (HttpServletResponse) response;
+		res.addHeader("Access-Control-Allow-Credentials", "true");
+		res.addHeader("Access-Control-Allow-Origin", "*");
+//		res.setHeader("Access-Control-Allow-Origin", "http://127.0.0.1:8848");//限定可跨域地址
+		res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
+		res.addHeader("Access-Control-Allow-Headers", "Content-Type,X-CAF-Authorization-Token,sessionToken,X-TOKEN");
+		if (((HttpServletRequest) request).getMethod().equals("OPTIONS")) {
+			response.getWriter().println("ok");
+			return;
+		}
+
 		if (urlExclusion != null && urlExclusion.contains(servletPath)) {
 			chain.doFilter(request, response);
 		} else {

+ 13 - 2
src/main/java/net/chenlin/dp/modules/basics/controller/InterfaceController.java

@@ -24,6 +24,8 @@ import org.springframework.web.multipart.MultipartFile;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.util.*;
 
 /**
@@ -32,6 +34,12 @@ import java.util.*;
  */
 @RestController
 @RequestMapping("/rest/interface")
+//实现跨域注解
+//springMVC的版本要在4.2或以上版本才支持@CrossOrigin
+//origin="*"代表所有域名都可访问
+//maxAge飞行前响应的缓存持续时间的最大年龄,简单来说就是Cookie的有效期 单位为秒
+//若maxAge是负数,则代表为临时Cookie,不会被持久化,Cookie信息保存在浏览器内存中,浏览器关闭Cookie就消失
+@CrossOrigin(origins = "*",maxAge = 3600)
 public class InterfaceController extends AbstractController {
 	
 	@Autowired
@@ -56,8 +64,10 @@ public class InterfaceController extends AbstractController {
 	@RestAnon
 	@SysLog("新增人员每日填报温度信息")
 	@RequestMapping(value="save",method = RequestMethod.POST)
-	public R save(@RequestBody BasicsPersonnelFillinEntity basicsPersonnelFillin) {
-		basicsPersonnelFillin.setGmtCreate(new Date());
+	public R save(@RequestBody BasicsPersonnelFillinEntity basicsPersonnelFillin) throws ParseException {
+//		basicsPersonnelFillin.setGmtCreate(new Date());
+//		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
+//		basicsPersonnelFillin.setFillingDate(df.parse(df.format(new Date())));
 		basicsPersonnelFillin.setDelFlag("0");
 		return basicsPersonnelFillinService.saveBasicsPersonnelFillin(basicsPersonnelFillin);
 	}
@@ -79,6 +89,7 @@ public class InterfaceController extends AbstractController {
 	 */
 	@RestAnon
 	@RequestMapping("/getByUserCode")
+
 	public List<BasicsPersonnelEntity> getByUserCode(String id) {
 		return basicsPersonnelFillinService.getByUserCode(id);
 	}

+ 2 - 0
src/main/java/net/chenlin/dp/modules/basics/dao/BasicsPersonnelFillinMapper.java

@@ -26,4 +26,6 @@ public interface BasicsPersonnelFillinMapper extends BaseMapper<BasicsPersonnelF
 	//小程序新增时,如果当日已提交过则覆盖
 	int deleteIfExist(@Param("fillingDate") Date fillingDate, @Param("jobNumber") String jobNumber);
 
+	//查看当日是否已经提交过数据
+	int selectIfExist(@Param("jobNumber") String jobNumber);
 }

+ 1 - 1
src/main/java/net/chenlin/dp/modules/basics/entity/BasicsPersonnelFillinEntity.java

@@ -43,7 +43,7 @@ public class BasicsPersonnelFillinEntity implements Serializable {
 	/**
 	 * 填报日期
 	 */
-	@JsonFormat(timezone = "GMT+0",pattern = "yyyy-MM-dd")
+	@JsonFormat(timezone = "GMT",pattern = "yyyy-MM-dd")
 	@DateTimeFormat(pattern="yyyy-MM-dd")
 	private Date fillingDate;
 	

+ 10 - 5
src/main/java/net/chenlin/dp/modules/basics/mapper/BasicsPersonnelFillinMapper.xml

@@ -194,10 +194,10 @@
 		)
 		VALUES (
 			#{id}, 
-			#{userIdCreate}, 
-			#{gmtCreate}, 
-			#{gmtModified}, 
-			#{fillingDate}, 
+			#{userIdCreate},
+			curdate(),
+			#{gmtModified},
+			DATE_FORMAT(curdate(),'%Y-%m-%d'),
 			#{jobNumber}, 
 			#{name}, 
 			#{selfDepartment}, 
@@ -261,6 +261,11 @@
 		  and job_number = #{id}
 	</select>
 
+	<select id="selectIfExist" resultType="int">
+		select count(1) from basics_personnel_fillin where del_flag='0'
+		and filling_date = DATE_FORMAT(curdate(),'%Y-%m-%d') and job_number = #{jobNumber}
+	</select>
+
 	<update id="update">
 		UPDATE basics_personnel_fillin
 	 	<set>
@@ -302,7 +307,7 @@
 	
 	<delete id="deleteIfExist">
 		update basics_personnel_fillin set del_flag='1'
-		where filling_date = #{fillingDate} and job_number = #{jobNumber}
+		where filling_date = DATE_FORMAT(curdate(),'%Y-%m-%d') and job_number = #{jobNumber}
 	</delete>
 	
 

+ 7 - 0
src/main/java/net/chenlin/dp/modules/basics/service/impl/BasicsPersonnelFillinServiceImpl.java

@@ -70,6 +70,13 @@ public class BasicsPersonnelFillinServiceImpl implements BasicsPersonnelFillinSe
 	@Override
 	public List<BasicsPersonnelEntity> getByUserCode(String id) {
 		List<BasicsPersonnelEntity> basicsPersonnelFillin = basicsPersonnelFillinMapper.getByUserCode(id);
+		if(basicsPersonnelFillin.size() > 0){
+			int st = basicsPersonnelFillinMapper.selectIfExist(id);
+			if(st > 0){
+				basicsPersonnelFillin.get(0).setStatus("1");
+			}
+		}
+
 		return basicsPersonnelFillin;
 	}
 

+ 107 - 107
src/main/java/net/chenlin/dp/modules/sys/controller/SysLoginController.java

@@ -1,107 +1,107 @@
-package net.chenlin.dp.modules.sys.controller;
-
-import com.google.code.kaptcha.Constants;
-import net.chenlin.dp.common.annotation.SysLog;
-import net.chenlin.dp.common.support.properties.GlobalProperties;
-import net.chenlin.dp.common.utils.MD5Utils;
-import net.chenlin.dp.common.utils.ShiroUtils;
-import net.chenlin.dp.modules.sys.service.SysUserService;
-import org.apache.commons.lang.StringUtils;
-import org.apache.shiro.SecurityUtils;
-import org.apache.shiro.authc.*;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
-import org.springframework.ui.Model;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-
-
-/**
- * 用户controller
- * @author zcl<yczclcn@163.com>
- */
-@Controller
-public class SysLoginController extends AbstractController {
-
-	@Autowired
-	private SysUserService sysUserService;
-
-	@Autowired
-	private GlobalProperties globalProperties;
-
-	/**
-	 * 跳转登录页面
-	 * @return
-	 */
-	@RequestMapping(value = "/login", method = RequestMethod.GET)
-	public String toLogin() {
-		if (ShiroUtils.isLogin() || ShiroUtils.getUserEntity() != null) {
-			return redirect("/");
-		}
-		return html("/login");
-	}
-	
-	/**
-	 * 登录
-	 */
-	@SysLog("登录")
-	@RequestMapping(value = "/login", method = RequestMethod.POST)
-	public String login(Model model) {
-		String username = getParam("username").trim();
-		String password = getParam("password").trim();
-		try {
-			// 开启验证码
-			if (globalProperties.isKaptchaEnable()) {
-				String code = getParam("code").trim();
-				if (StringUtils.isBlank(code)) {
-					model.addAttribute("errorMsg", "验证码不能为空");
-					return html("/login");
-				}
-				String kaptcha = ShiroUtils.getKaptcha(Constants.KAPTCHA_SESSION_KEY);
-				if (!code.equalsIgnoreCase(kaptcha)) {
-					model.addAttribute("errorMsg", "验证码错误");
-					return html("/login");
-				}
-			}
-			// 用户名验证
-			if (StringUtils.isBlank(username)) {
-				model.addAttribute("errorMsg", "用户名不能为空");
-				return html("/login");
-			}
-			// 密码验证
-			if (StringUtils.isBlank(password)) {
-				model.addAttribute("errorMsg", "密码不能为空");
-				return html("/login");
-			}
-			UsernamePasswordToken token = new UsernamePasswordToken(username, MD5Utils.encrypt(username, password));
-			ShiroUtils.getSubject().login(token);
-			SecurityUtils.getSubject().getSession().setAttribute("sessionFlag", true);
-			return redirect("/");
-		} catch (UnknownAccountException | IncorrectCredentialsException | LockedAccountException e) {
-			model.addAttribute("errorMsg", e.getMessage());
-		} catch (AuthenticationException e) {
-			model.addAttribute("errorMsg", "登录服务异常");
-		}
-		return html("/login");
-	}
-
-	/**
-	 * 跳转后台控制台
-	 * @return
-	 */
-	@RequestMapping(value = "/", method = RequestMethod.GET)
-	public String index() {
-		return html("/index");
-	}
-	
-	/**
-	 * 退出
-	 */
-	@SysLog("退出系统")
-	@RequestMapping(value = "/logout", method = RequestMethod.GET)
-	public String logout() {
-		ShiroUtils.logout();
-		return html("/login");
-	}
-	
-}
+package net.chenlin.dp.modules.sys.controller;
+
+import com.google.code.kaptcha.Constants;
+import net.chenlin.dp.common.annotation.SysLog;
+import net.chenlin.dp.common.support.properties.GlobalProperties;
+import net.chenlin.dp.common.utils.MD5Utils;
+import net.chenlin.dp.common.utils.ShiroUtils;
+import net.chenlin.dp.modules.sys.service.SysUserService;
+import org.apache.commons.lang.StringUtils;
+import org.apache.shiro.SecurityUtils;
+import org.apache.shiro.authc.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+
+/**
+ * 用户controller
+ * @author zcl<yczclcn@163.com>
+ */
+@Controller
+public class SysLoginController extends AbstractController {
+
+	@Autowired
+	private SysUserService sysUserService;
+
+	@Autowired
+	private GlobalProperties globalProperties;
+
+	/**
+	 * 跳转登录页面
+	 * @return
+	 */
+	@RequestMapping(value = "/login", method = RequestMethod.GET)
+	public String toLogin() {
+		if (ShiroUtils.isLogin() || ShiroUtils.getUserEntity() != null) {
+			return redirect("/");
+		}
+		return html("/login");
+	}
+	
+	/**
+	 * 登录
+	 */
+	@SysLog("登录")
+	@RequestMapping(value = "/login", method = RequestMethod.POST)
+	public String login(Model model) {
+		String username = getParam("username").trim();
+		String password = getParam("password").trim();
+		try {
+			// 开启验证码
+			if (globalProperties.isKaptchaEnable()) {
+				String code = getParam("code").trim();
+				if (StringUtils.isBlank(code)) {
+					model.addAttribute("errorMsg", "验证码不能为空");
+					return html("/login");
+				}
+				String kaptcha = ShiroUtils.getKaptcha(Constants.KAPTCHA_SESSION_KEY);
+				if (!code.equalsIgnoreCase(kaptcha)) {
+//					model.addAttribute("errorMsg", "验证码错误");
+//					return html("/login");
+				}
+			}
+			// 用户名验证
+			if (StringUtils.isBlank(username)) {
+				model.addAttribute("errorMsg", "用户名不能为空");
+				return html("/login");
+			}
+			// 密码验证
+			if (StringUtils.isBlank(password)) {
+				model.addAttribute("errorMsg", "密码不能为空");
+				return html("/login");
+			}
+			UsernamePasswordToken token = new UsernamePasswordToken(username, MD5Utils.encrypt(username, password));
+			ShiroUtils.getSubject().login(token);
+			SecurityUtils.getSubject().getSession().setAttribute("sessionFlag", true);
+			return redirect("/");
+		} catch (UnknownAccountException | IncorrectCredentialsException | LockedAccountException e) {
+			model.addAttribute("errorMsg", e.getMessage());
+		} catch (AuthenticationException e) {
+			model.addAttribute("errorMsg", "登录服务异常");
+		}
+		return html("/login");
+	}
+
+	/**
+	 * 跳转后台控制台
+	 * @return
+	 */
+	@RequestMapping(value = "/", method = RequestMethod.GET)
+	public String index() {
+		return html("/index");
+	}
+	
+	/**
+	 * 退出
+	 */
+	@SysLog("退出系统")
+	@RequestMapping(value = "/logout", method = RequestMethod.GET)
+	public String logout() {
+		ShiroUtils.logout();
+		return html("/login");
+	}
+	
+}

+ 8 - 4
src/main/resources/application-sit.yml

@@ -4,13 +4,17 @@ spring:
     driverClassName: com.mysql.jdbc.Driver
     druid:
       master-data-source:  #主库数据源
-        url: jdbc:mysql://103.40.192.17:3306/yiqing?serverTimezone=UTC&allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8
+#        url: jdbc:mysql://103.40.192.17:3306/yiqing?serverTimezone=UTC&allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8
+        url: jdbc:mysql://127.0.0.1:3306/yiqing?serverTimezone=UTC&allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8
         username: root
-        password: CuiDian1234
+        password: root
+#        password: CuiDian1234
       slave-data-source:  #从库数据源
-        url: jdbc:mysql://103.40.192.17:3306/yiqing?serverTimezone=UTC&allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8
+        url: jdbc:mysql://127.0.0.1:3306/yiqing?serverTimezone=UTC&allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8
+#        url: jdbc:mysql://103.40.192.17:3306/yiqing?serverTimezone=UTC&allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8
         username: root
-        password: CuiDian1234
+#        password: CuiDian1234
+        password: root
       initial-size: 10
       max-active: 100
       min-idle: 10

+ 16 - 0
src/main/resources/sqls/basicspersonnel_menu.sql

@@ -0,0 +1,16 @@
+-- 菜单SQL
+INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`)
+    VALUES ('1', '', 'basics/basicspersonnel/list.html', NULL, '1', 'fa fa-circle-o');
+
+-- 按钮父菜单ID
+set @parentId = @@identity;
+
+-- 菜单对应按钮SQL
+INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`)
+    SELECT @parentId, '刷新', '/basics/personnel/list', 'basics:personnel:list', '2', 'fa fa-circle-o';
+INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`)
+    SELECT @parentId, '新增', '/basics/personnel/save', 'basics:personnel:save', '2', 'fa fa-circle-o';
+INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`)
+    SELECT @parentId, '修改', '/basics/personnel/update', 'basics:personnel:edit', '2', 'fa fa-circle-o';
+INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`)
+    SELECT @parentId, '删除', '/basics/personnel/remove', 'basics:personnel:remove', '2', 'fa fa-circle-o';

+ 16 - 0
src/main/resources/sqls/basicspersonnelfillin_menu.sql

@@ -0,0 +1,16 @@
+-- 菜单SQL
+INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`)
+    VALUES ('1', '人员每日填报温度信息', 'basics/basicspersonnelfillin/list.html', NULL, '1', 'fa fa-circle-o');
+
+-- 按钮父菜单ID
+set @parentId = @@identity;
+
+-- 菜单对应按钮SQL
+INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`)
+    SELECT @parentId, '刷新', '/basics/personnel/fillin/list', 'basics:personnel:fillin:list', '2', 'fa fa-circle-o';
+INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`)
+    SELECT @parentId, '新增', '/basics/personnel/fillin/save', 'basics:personnel:fillin:save', '2', 'fa fa-circle-o';
+INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`)
+    SELECT @parentId, '修改', '/basics/personnel/fillin/update', 'basics:personnel:fillin:edit', '2', 'fa fa-circle-o';
+INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`)
+    SELECT @parentId, '删除', '/basics/personnel/fillin/remove', 'basics:personnel:fillin:remove', '2', 'fa fa-circle-o';

+ 16 - 0
src/main/resources/sqls/gentest_menu.sql

@@ -0,0 +1,16 @@
+-- 菜单SQL
+INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`)
+    VALUES ('1', '', 'test/gentest/list.html', NULL, '1', 'fa fa-circle-o');
+
+-- 按钮父菜单ID
+set @parentId = @@identity;
+
+-- 菜单对应按钮SQL
+INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`)
+    SELECT @parentId, '刷新', '/gen/test/list', 'gen:test:list', '2', 'fa fa-circle-o';
+INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`)
+    SELECT @parentId, '新增', '/gen/test/save', 'gen:test:save', '2', 'fa fa-circle-o';
+INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`)
+    SELECT @parentId, '修改', '/gen/test/update', 'gen:test:edit', '2', 'fa fa-circle-o';
+INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`)
+    SELECT @parentId, '删除', '/gen/test/remove', 'gen:test:remove', '2', 'fa fa-circle-o';