コード例 #1
0
 @RequestMapping(value = "/login", method = RequestMethod.POST)
 public void login(
     @ModelAttribute("user") User user,
     HttpSession session,
     HttpServletRequest request,
     HttpServletResponse response,
     @RequestParam(value = "userId", required = true) String userId,
     @RequestParam(value = "passwd", required = true) String passwd)
     throws Exception {
   user = this.userService.getUser(userId, passwd);
   PrintWriter pw = response.getWriter();
   if (user != null) {
     Cookie cookie = new Cookie(Constants.BRUSERID, user.getId());
     cookie.setPath("/");
     cookie.setMaxAge(10 * 365 * 24 * 3600);
     response.addCookie(cookie);
     WebContextThreadLocal.setCurrentUser(user);
     LoggerUtil.info(this.getClass(), "当前登录用户为:" + user.getUserName());
     AuthenticateRole.authenticate(request, user, (String) request.getAttribute("userIdRuleReg"));
     request.setAttribute("user", user);
     session.setAttribute("user", user);
     this.userService.flush();
     pw.write(
         "{\"login\" : true ,\"user\":\""
             + user.getUserName()
             + "\",\"isTeacher\":\""
             + request.getAttribute("isTeacher")
             + "\"}");
   } else {
     LoggerUtil.debug(this.getClass(), "用户名或密码错误!");
     pw.write("{\"login\":false}");
   }
   pw.close();
 }
コード例 #2
0
  @RequestMapping("/my_configure")
  public ModelAndView my_configure() throws Exception {
    ModelAndView mav = new ModelAndView();
    User user = WebContextThreadLocal.getCurrentUser();
    if (user != null) {
      int role = user.getRole();
      HashMapReduce<Major, Course> hashMapReduce = new HashMapReduce<Major, Course>();
      String id = user.getId();
      user = this.userService.getUserByUserId(id);
      WebContextThreadLocal.setCurrentUser(user);
      Set<Course> courseSet = user.getCourses();
      HashMapReduce<String, Set<DoubanJson>> recommendBooks =
          new HashMapReduce<String, Set<DoubanJson>>();
      for (Course course : courseSet) {
        hashMapReduce.put(course.getMajor(), course);
        Set<DoubanJson> recommendBook = new HashSet<DoubanJson>();
        if (course.getDoubanJsons().size() == 0) {
          String str = null;
          if (course.getSearchKeyword() == null)
            str = this.academyService.wordAnalyzer(course.getName(), course);
          else {
            str = course.getSearchKeyword();
            String[] strs = str.split(" ");
            boolean first = true;
            for (int i = 0; i < strs.length; i++) {
              if (first) {
                String para = java.net.URLEncoder.encode(strs[i], "UTF-8");
                str = para;
                first = false;
              } else {
                String para = java.net.URLEncoder.encode(strs[i], "UTF-8");
                str = str + ',' + para;
              }
            }
          }
          // String str =
          // "https://api.douban.com/v2/book/search?apikey=00e256c12217228802a7044366456798&q="+course.getName();
          recommendBook = this.bookJsonService.getJsonString(str, course.getId());
        } else {
          recommendBook = course.getDoubanJsons();
        }
        recommendBooks.put(course.getName(), recommendBook);
      }
      // String str = this.academyService.wordAnalyzer("Java课程设计");

      List<Invite> inviteList = this.inviteService.getInviteByUserId();
      HashMap<String, List<DoubanJson>> bookList = new HashMap<String, List<DoubanJson>>();
      for (Invite invite : inviteList) {
        Course course = invite.getCourse();
        List<DoubanJson> bookInfos = this.bookJsonService.getBookByCourse(course.getId());
        bookList.put(course.getName(), bookInfos);
      }
      mav.getModel().put("bookList", bookList);

      mav.getModel().put("majorMap", hashMapReduce.getMap());

      // ArrayList<DoubanJson> recommendBooks = this.bookJsonService.getJsonString(str);
      mav.getModel().put("recommendBooks", recommendBooks.getMap());
      // unactiveCommunities对于老师指的是没有创建的社区,对于学生指的是没有加入,但已经存在的社区
      Set<Community> unactiveCommunities = new HashSet<Community>();
      if (role == 1) {
        unactiveCommunities = this.communityService.getAllCommunitiesByCurrentUserRole();
      } else if (role == 0) {
        for (Course course : courseSet) {
          Set<Community> communities = course.getCommunities();
          for (Community community : communities) {
            if (community.getState() == 1 && !user.getCommunities().contains(community)) {
              unactiveCommunities.add(community);
            }
          }
        }
      }
      mav.getModel().put("unactiveCommunities", unactiveCommunities);
      mav.getModel().put("invitedCommunities", this.inviteService.getInviteCommunities());
      if (role == 2) {
        Pager<Resource> pager = this.resourceOperationService.getReviewResource(1);
        mav.getModel().put("pager", pager);
        mav.getModel().put("htmlTag", 1);
        mav.setViewName("admin/reviewResource");
        return mav;
      }
    }

    mav.setViewName("user/myConfigure");
    return mav;
  }