protected static boolean checkIdle(final Point p) throws NimbitsException {
   final Calendar c = Calendar.getInstance();
   c.add(Calendar.SECOND, p.getIdleSeconds() * -1);
   boolean retVal = false;
   final List<Entity> result =
       EntityServiceFactory.getInstance()
           .getEntityByKey(
               UserServiceFactory.getServerInstance().getAdmin(), p.getOwner(), EntityType.user);
   if (!result.isEmpty()) {
     final User u = (User) result.get(0);
     final List<Value> v = ValueServiceFactory.getInstance().getCurrentValue(p);
     if (p.getIdleSeconds() > 0
         && !v.isEmpty()
         && v.get(0).getTimestamp().getTime() <= c.getTimeInMillis()
         && !p.getIdleAlarmSent()) {
       p.setIdleAlarmSent(true);
       EntityServiceFactory.getInstance().addUpdateEntity(u, p);
       // PointServiceFactory.getInstance().updatePoint(u, p);
       final Value va = ValueFactory.createValueModel(v.get(0), AlertType.IdleAlert);
       SubscriptionServiceFactory.getInstance().processSubscriptions(u, p, va);
       retVal = true;
     }
   }
   return retVal;
 }
Exemple #2
0
 private User getUser() {
   try {
     return UserServiceFactory.getServerInstance()
         .getHttpRequestUser(this.getThreadLocalRequest());
   } catch (NimbitsException e) {
     return UserServiceFactory.getServerInstance().getAnonUser();
   }
 }
Exemple #3
0
  public void doGet(HttpServletRequest req, HttpServletResponse res)
      throws IOException, ServletException {
    UserService userService = UserServiceFactory.getUserService();
    String retUrl = req.getParameter("url");
    if (retUrl == null) retUrl = "/";

    String pathInfo = req.getPathInfo();
    if (pathInfo.equals("/current")) {
      User user = userService.getCurrentUser();
      if (user == null) {
        res.setStatus(401);
        res.setContentType("text/plain; charset=utf-8");
        res.getWriter().write("Not login");
        return;
      }

      UserBean ub = getByEmail(user.getEmail());

      res.setContentType("application/json; charset=utf-8");
      res.setHeader("Cache-control", "no-cache");
      res.getWriter().write("{\"email\":\"" + user.getEmail() + "\"");
      if (ub != null) {
        res.getWriter().write(",\"nickName\":\"" + ub.getNickName() + "\"");
        res.getWriter().write(",\"isRegister\":true");
      } else {
        String nn = user.getNickname();
        if (nn == null) nn = user.getEmail();
        res.getWriter().write(",\"nickName\":\"" + nn + "\"");
        res.getWriter().write(",\"isRegister\":false");
      }
      res.getWriter().write("}");

    } else if (pathInfo.equals("/login")) {
      String url = userService.createLoginURL(retUrl);
      res.sendRedirect(url);
    } else if (pathInfo.equals("/logout")) {
      String url = userService.createLogoutURL(retUrl);
      res.sendRedirect(url);
    } else if (pathInfo.equals("/register")) {
      User user = userService.getCurrentUser();
      if (user == null) {
        res.setStatus(401);
        res.setContentType("text/plain; charset=utf-8");
        res.getWriter().write("Not login");
        return;
      }

      String nickName = req.getParameter("nickName");
      UserBean ub = getByNeckName(nickName);
      if (ub != null) {
        res.setStatus(403);
        res.setContentType("text/plain; charset=utf-8");
        res.getWriter().write("ニックネーム(" + nickName + ")は既に使われています。");
        return;
      }

      ub = new UserBean();
      ub.setEmail(user.getEmail());
      ub.setNickName(nickName);
      usbs.put(user.getEmail(), ub);
      ursbs.put(nickName, ub);

      FileBean fb = new FileBean();
      fb.setParentName("");
      fb.setLastName(nickName);
      fb.setDirectory(true);
      fb.setLastModified(System.currentTimeMillis());
      fb.setOwner(user.getEmail());
      fb.setNickName(nickName);
      sbs.put("/" + nickName, fb);

      res.sendRedirect(retUrl);
    }
  }