@SuppressWarnings("unchecked") @RequestMapping(value = "/userInfo", method = RequestMethod.GET) @ResponseBody public String getUserInfo(User user, HttpServletRequest request, HttpServletResponse response) { String users_id = user.getUsers_id(); Map<String, Object> u = new HashMap<String, Object>(); if (users_id != null && !users_id.equals("")) { u = userService.getUserById(users_id); } else { u = (Map<String, Object>) SessionUtil.getUser(request); } return Object2JsonUtil.Object2Json(u); }
@RequestMapping(value = "/issysn", method = RequestMethod.GET) @ResponseBody public String isSysn(User user, HttpServletRequest request, HttpServletResponse response) { Map<String, String> map = new HashMap<String, String>(); // 判断该用户在数据库中是否存在 int isExist = userService.isUserExist(user.getStudent_id(), user.getSchool()); // 0,表示存在 1,表示不存在 ,2,表示数据库异常 switch (isExist) { case 0: map.put("state", "0"); map.put("msg", "存在"); break; case 1: String codeUrl = CodeFactory.getCode(Integer.parseInt(user.getSchool())); if (codeUrl != null) { String fileName = user.getSchool() + user.getStudent_id() + ".jpg"; boolean flag = CodeUtil.downloadImage(codeUrl, fileName, request); if (flag) { map.put("state", "1"); map.put("msg", "用户不存在,code下载成功"); map.put("mcode", fileName); } else { map.put("state", "3"); map.put("msg", "用户不存在,code下载失败"); } } else { map.put("state", "1"); map.put("msg", "用户不存在,无验证码"); } break; case 2: map.put("state", "2"); map.put("msg", "网络异常"); break; } return Object2JsonUtil.Object2Json(map); }
/** * @param user * @param txtSecretCode * @param cookie * @param request * @param response * @return state <br> * 没有:成功<br> * 1:请登录教务系统完成教师评价后在登录!!<br> * 2:网络异常<br> * 3:验证码不正确!!<br> * 4:用户名不存在或未按照要求参加教学活动!!<br> * 5:密码错误!!<br> */ @SuppressWarnings("unchecked") @RequestMapping(value = "/login", method = RequestMethod.GET) @ResponseBody public String login( User user, String code, String issysn, HttpServletRequest request, HttpServletResponse response) { // 1表示用户名或密码错误,2表示数据库异常 // 判断该用户在数据库中是否存在 /* * int isExist = userService.isUserExist(user.getStudent_id(), * user.getSchool()); */ Map<String, Object> returnMap = new HashMap<String, Object>(); // 该用户在数据库中存在,即已经同步过 if (issysn.equals("1")) { log.debug("login from database ..."); returnMap = userService.login(user.getStudent_id(), user.getPwd(), user.getSchool()); Map<String, Object> u = (Map<String, Object>) returnMap.get("user"); SessionUtil.setUser(request, u); returnMap.remove("user"); // 还未同步过 } else if (issysn.equals("2")) { // 该用户在数据库中不存在,到教务系统中获取用户信息保存到数据库中 Sysn sysn = SysnFac.getConn(user.getSchool(), user.getStudent_id(), user.getPwd(), code); Map<String, String> stuInfo = null; try { log.debug("login from net ..."); stuInfo = sysn.login(request); // 删除验证码,同步完成后 String fileName = user.getSchool() + user.getStudent_id() + ".jpg"; File file = new File( request.getSession().getServletContext().getRealPath("/image/code") + "/" + fileName); if (file.exists()) { file.delete(); } // 该用户在教务系统中登录失败,表示用户名或密码错误。 if (stuInfo.get("isLogined").equals("true")) { log.debug("login from net succeed"); stuInfo.put("pwd", user.getPwd()); stuInfo.put("school", user.getSchool()); stuInfo.put("users_id", util.getUUID()); // 该用户在教务系统中的信息保存到数据库中 log.debug("save user ..."); if (userService.saveUserInfo(stuInfo)) { log.debug("save user succeed"); returnMap = userService.login(user.getStudent_id(), user.getPwd(), user.getSchool()); Map<String, Object> u = (Map<String, Object>) returnMap.get("user"); SessionUtil.setUser(request, u); returnMap.remove("user"); } else { log.debug("save user failed"); returnMap.put("isLogined", "false"); returnMap.put("state", "2"); // 2 表示数据库异常 } } else { log.debug("login from net failed"); returnMap.putAll(stuInfo); // returnMap.put("isLogined", "false"); // returnMap.put("state", "1"); // 1 用户名密码错误 } } catch (IOException e) { log.debug("login from net failed in catch"); e.printStackTrace(); returnMap.put("isLogined", "false"); returnMap.put("state", "2"); // 2 表示数据库异常 } } /* * else if (isExist == 2) { returnMap.put("isLogined", "false"); * returnMap.put("state", "2"); // 2 表示数据库异常 } */ return Object2JsonUtil.Object2Json(returnMap); }