@RequestMapping(value = "/mobileform/{id}", method = RequestMethod.POST)
 public MobileForm saveMobileForm(@RequestBody MobileForm mht) throws IOException {
   UserService userService = UserServiceFactory.getUserService();
   User user = userService.getCurrentUser();
   if (userService.isUserLoggedIn()) {
     PersistenceManager pm = PMF.get().getPersistenceManager();
     try {
       Date now = new Date();
       if (mht.getId().equalsIgnoreCase("123")) {
         mht.setId(KeyFactory.keyToString(KeyFactory.createKey(user.getEmail(), now.getTime())));
         mht.setCreator(user.getEmail());
         MobileForm mt = pm.makePersistent(mht);
         return mt;
       } else {
         Key k = KeyFactory.createKey(MobileForm.class.getSimpleName(), mht.getId());
         MobileForm m = pm.getObjectById(MobileForm.class, k);
         m.setMethod(mht.getMethod());
         return pm.makePersistent(m);
       }
     } finally {
       pm.close();
     }
   }
   return null;
 }
  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    resp.setContentType("text/html");
    PrintWriter out = resp.getWriter();

    UserService userService = UserServiceFactory.getUserService();
    if (userService.isUserLoggedIn()) {
      User user = userService.getCurrentUser();
      out.println("<p>You are signed in as " + user.getNickname() + ". ");
      if (userService.isUserAdmin()) {
        out.println("You are an administrator. ");
      }
      out.println("<a href=\"" + userService.createLogoutURL("/") + "\">Sign out</a>.</p>");
    } else {
      out.println(
          "<p>You are not signed in to Google Accounts. "
              + "<a href=\""
              + userService.createLoginURL(req.getRequestURI())
              + "\">Sign in</a>.</p>");
    }

    out.println(
        "<ul>"
            + "<li><a href=\"/\">/</a></li>"
            + "<li><a href=\"/required\">/required</a></li>"
            + "<li><a href=\"/admin\">/admin</a></li>"
            + "</ul>");

    SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSSSSS");
    fmt.setTimeZone(new SimpleTimeZone(0, ""));
    out.println("<p>The time is: " + fmt.format(new Date()) + "</p>");
  }
示例#3
0
 @Override
 protected void getAndPost(HttpServletRequest req, HttpServletResponse resp) {
   UserService userService = UserServiceFactory.getUserService();
   if (userService.isUserLoggedIn()) {
     returnContent("{\"status\":\"yes\"}", resp);
   }
   returnContent("{\"status\":\"no\"}", resp);
 }
 private void sendError(
     HttpServletRequest req,
     HttpServletResponse response,
     Level logLevel,
     int errorCode,
     String publicMessage,
     Throwable t)
     throws IOException {
   boolean isOverQuota = isOverQuota(t);
   log.log(
       logLevel,
       t.getClass().getSimpleName()
           + "; overQuota="
           + isOverQuota
           + "; sending "
           + errorCode
           + ": "
           + publicMessage,
       t);
   try {
     log.info("Trust status: " + trusted.get());
     boolean isTrusted =
         trusted.get() == UserTrustStatus.TRUSTED && req.getParameter("simulateUntrusted") == null;
     response.setStatus(errorCode);
     UserService service = userService.get();
     String userEmail =
         service.isUserLoggedIn() ? service.getCurrentUser().getEmail() : "(not logged in)";
     pageSkinWriter
         .get()
         .write(
             "Error " + errorCode,
             userEmail,
             ErrorPage.getGxpClosure(
                 userEmail,
                 "" + errorCode,
                 isOverQuota,
                 isTrusted,
                 publicMessage,
                 renderInternalMessage(Throwables.getStackTraceAsString(t))));
     log.info("Successfully sent GXP error page");
   } catch (RuntimeException e) {
     // This can happen if the uncaught exception t occurred after the servlet
     // had already called response.setContentType().  In that case, jetty
     // throws an IllegalStateException("STREAM") when we call
     // response.getWriter() above.
     log.log(Level.SEVERE, "RuntimeException trying to serve error page", e);
     // Try a more primitive mechanism.
     response.sendError(
         HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
         "An error occurred while reporting an error, see logs.  Original error:  "
             + errorCode
             + " "
             + publicMessage);
     log.info("Successfully sent primitive error page");
   }
 }
  public void doFilter(
      ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
      throws IOException, ServletException {
    UserService userService = UserServiceFactory.getUserService();
    HttpServletRequest request = (HttpServletRequest) servletRequest;
    HttpServletResponse response = (HttpServletResponse) servletResponse;

    if (!userService.isUserLoggedIn()) {
      String requestUrl = request.getHeader("requestUrl");
      if (requestUrl == null) {
        requestUrl = request.getRequestURI();
      }
      response.setHeader("login", userService.createLoginURL(requestUrl));
      response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
      return;
    }

    filterChain.doFilter(request, response);
  }
 @RequestMapping(value = "/mobileforms/", method = RequestMethod.GET)
 public List<MobileForm> getMobileForms() throws IOException {
   UserService userService = UserServiceFactory.getUserService();
   User user = userService.getCurrentUser();
   if (userService.isUserLoggedIn()) {
     PersistenceManager pm = PMF.getManager();
     Query query = pm.newQuery(MobileForm.class);
     query.setFilter("creator == creatorParam");
     query.declareParameters("String creatorParam");
     try {
       List<MobileForm> tasks = (List<MobileForm>) query.execute(user.getEmail());
       return tasks;
     } catch (Exception e) {
       logger.log(Level.ALL, e.getMessage());
       return null;
     }
   }
   return null;
 }
示例#7
0
  @Override
  public void doFilter(
      ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
      throws IOException, ServletException {
    UserService userService = UserServiceFactory.getUserService();
    HttpServletRequest request = (HttpServletRequest) servletRequest;
    HttpServletResponse response = (HttpServletResponse) servletResponse;

    if (!userService.isUserLoggedIn()) {
      String redirectUrl = request.getHeader(GaeHelper.REDIRECT_URL_HTTP_HEADER_NAME);
      if (redirectUrl == null || redirectUrl.length() == 0) {
        // Default to the root page if the redirecturl isn't specified in the request.
        redirectUrl = "/";
      }
      response.setHeader("login", userService.createLoginURL(redirectUrl));
      response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
      return;
    }

    filterChain.doFilter(request, response);
  }
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    UserService userService = UserServiceFactory.getUserService();

    RequestDispatcher disp = null;

    if (userService.isUserLoggedIn()) {

      String taskName = req.getParameter("taskName");
      String day = req.getParameter("day");
      String month = req.getParameter("month");
      String year = req.getParameter("year");
      String teamName = req.getParameter("teamsdropdown");

      Date d =
          new Date(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day) - 1900);

      CompositeTask ct =
          TaskDAO.createCompositeTask(
              taskName, d, teamName, userService.getCurrentUser().getEmail());

      if (ct == null) {
        req.setAttribute("err", "cannot persist composite task");
        disp = req.getRequestDispatcher("/err.jsp");
        disp.forward(req, resp);
      } else {
        disp = req.getRequestDispatcher("/tasks");
        disp.forward(req, resp);
      }

    } else {
      disp = req.getRequestDispatcher("/projectcontrol");
      disp.forward(req, resp);
    }
  }
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    String requestURL = req.getRequestURL().toString();
    if (!debug && !requestURL.startsWith(this.baseURL) && !requestURL.contains(".latest.")) {
      resp.sendRedirect(baseURL);
      return;
    }

    PersistenceManager pm = pmf.getPersistenceManager();
    try {
      req.setAttribute("recentScripts", getRecentScripts(pm));
      req.setAttribute("tagCloud", getTagCloud(pm));

      UserService userSvc = UserServiceFactory.getUserService();
      if (userSvc.isUserLoggedIn())
        req.setAttribute("logoutURL", userSvc.createLogoutURL(req.getRequestURI()));
      else req.setAttribute("loginURL", userSvc.createLoginURL(req.getRequestURI()));

      super.getServletContext().getRequestDispatcher("/index.jsp").forward(req, resp);
    } finally {
      pm.close();
    }
  }
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    UserService userService = UserServiceFactory.getUserService();

    RequestDispatcher disp = null;
    if (userService.isUserLoggedIn()) {
      User user = userService.getCurrentUser();

      PersistenceManager pm = PMF.get();
      ContactsToken token = null;
      try {
        token = pm.getObjectById(ContactsToken.class, user.getEmail());

        String teamName = req.getParameter("teamName");
        if (teamName != null) {
          Team team = TeamDAO.getTeam(teamName);

          if (team != null) {

            // Get contacts
            GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
            oauthParameters.setOAuthConsumerKey("anonymous");
            oauthParameters.setOAuthConsumerSecret("anonymous");
            oauthParameters.setOAuthToken(token.getToken());
            oauthParameters.setOAuthTokenSecret(token.getTokenSecret());
            OAuthSigner signer = new OAuthHmacSha1Signer();

            ContactsService service = new ContactsService("ContactFeedDemo");
            List<ContactEntry> result = null;
            List<String> mails = null;
            try {
              service.setOAuthCredentials(oauthParameters, signer);
              ContactFeed resultFeed =
                  service.getFeed(
                      new URL("https://www.google.com/m8/feeds/contacts/default/full"),
                      ContactFeed.class);

              result = new ArrayList<ContactEntry>(resultFeed.getEntries());
              mails = new ArrayList<String>();
              for (ContactEntry ce : result) {
                for (Email em : ce.getEmailAddresses()) {
                  mails.add(em.getAddress());
                }
              }
              for (TMember tm : team.getMembers()) {
                mails.remove(tm.getName());
              }

            } catch (OAuthException e) {
              e.printStackTrace();
            } catch (ServiceException e) {
              e.printStackTrace();
            }
            // end get contact list

            req.setAttribute("teamName", teamName);
            // req.setAttribute("teamMembers", teamMembers);
            req.setAttribute("contacts", mails);
            RequestDispatcher rd = req.getRequestDispatcher("/AddMember.jsp");
            rd.forward(req, resp);

          } else {
            String errText = "team with team name " + teamName + "doesnt exist.";
            req.setAttribute("err", errText);
            disp = req.getRequestDispatcher("err.jsp");
            disp.forward(req, resp);
          }

        } else {
          String errText = "parametru teamName is null";
          req.setAttribute("err", errText);
          disp = req.getRequestDispatcher("err.jsp");
          disp.forward(req, resp);
        }

      } catch (JDOObjectNotFoundException e) {
        String consumerKey = "anonymous";
        String consumerSecret = "anonymous";
        String scope = "https://www.google.com/m8/feeds";
        String callback = "http://vrchlpet-pc.appspot.com/callbackservlet";

        GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
        oauthParameters.setOAuthConsumerKey(consumerKey);
        oauthParameters.setOAuthConsumerSecret(consumerSecret);
        oauthParameters.setScope(scope);
        oauthParameters.setOAuthCallback(callback);

        OAuthSigner signer = new OAuthHmacSha1Signer();
        GoogleOAuthHelper oauthHelper = new GoogleOAuthHelper(signer);

        try {
          oauthHelper.getUnauthorizedRequestToken(oauthParameters);
          String approvalPageUrl = oauthHelper.createUserAuthorizationUrl(oauthParameters);
          req.getSession().setAttribute("tokenSecret", oauthParameters.getOAuthTokenSecret());
          resp.sendRedirect(approvalPageUrl);
          return;
        } catch (OAuthException ee) {
          ee.printStackTrace();
        }
      }

    } else {
      disp = req.getRequestDispatcher("/projectcontrol");
      disp.forward(req, resp);
    }
  }