@Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {

    // get the tickerStr
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();

    // get the user and check for non null
    if (user != null) {
      PersistenceManager pm = PMF.get().getPersistenceManager();
      Collection<UserComparisonTickers> comparisonTickersCollection = null;
      try {
        comparisonTickersCollection =
            getComparisonTickersService().getComparisonTickers(user.getEmail());
      } catch (Exception e) {
        log.logp(
            Level.SEVERE,
            GetComparisonTickersServlet.class.getName(),
            "method",
            "UserComparisonTickers could not be fetched from persistence storage",
            e);
      } finally {
        pm.close();
      }
      if (comparisonTickersCollection != null) {
        resp.getWriter().write(getComparisonTickersService().getJson(comparisonTickersCollection));
      }
    }
  }
  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>");
  }
  public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {

    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();

    ObjectifyService.register(Subscriber.class);
    Subscriber newSubscriber = new Subscriber(user.getEmail());
    ofy().save().entity(newSubscriber).now();

    // MailUpdate.subscribers.add(user);

    System.out.println(user.getEmail() + " has subscribed");
    List<Subscriber> subscribers = ObjectifyService.ofy().load().type(Subscriber.class).list();
    // for (Subscriber subscriber : subscribers){
    // ofy().delete().entity(subscriber);
    // }
    Collections.sort(subscribers);
    System.out.println("size" + subscribers.size());
    for (Subscriber subscriber : subscribers) {
      System.out.println(subscriber.getEmail());
    }
    // try{
    // RequestDispatcher view = req.getRequestDispatcher("");
    // view.forward(req, resp);

    // } catch (Exception e){}
    resp.sendRedirect("/");
  }
示例#4
0
  public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {

    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();

    boolean lock = true;

    if (user == null) {
      resp.sendRedirect("/");
      return;
    }

    if (0 == user.getEmail().compareTo("*****@*****.**")) lock = false;
    if (0 == user.getEmail().compareTo("*****@*****.**")) lock = false;

    if (lock) {
      resp.sendRedirect("/");
      return;
    }

    String albumid = req.getParameter("albumid");
    List<ECPhoto> photos = Dao.INSTANCE.getECPhotos(albumid);
    for (ECPhoto photo : photos) Dao.INSTANCE.removeECPhoto(photo.getId());
    resp.sendRedirect("/ECPhotoApplication.jsp");
  }
示例#5
0
  @Override
  public void doGet(HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException {
    Long orderId = Long.parseLong(req.getParameter("orderid"));
    Status status = Status.valueOf(req.getParameter("status"));

    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    if (AdminAuthenticator.isAdmin(user)) {

      PersistenceManager pm = PMF.get().getPersistenceManager();

      String select_query = "select from " + Order.class.getName();
      Query query = pm.newQuery(select_query);
      query.setFilter("id == paramId");
      query.declareParameters("java.lang.Long paramId");
      // execute
      List<Order> orders = (List<Order>) query.execute(orderId);

      if (!orders.isEmpty()) {
        // should be only one - safety check here
        Order order = orders.get(0);
        order.setStatus(status);
        pm.close();
        res.sendRedirect("/home.html");
      }
    }
  }
 @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;
 }
示例#7
0
  public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {

    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();

    String message_type = req.getParameter("type");
    String user_name = user.getNickname();

    String userId = user.getUserId();

    if (message_type.compareTo("message") == 0) {
      String message = req.getParameter("text");
      String chat_message = chatMessage(user_name, message);
      sendChannelMessageToAll(user_name, chat_message);
      addMessageToCache(chat_message);
    } else if (message_type.compareTo("get_token") == 0) {
      // generate and give token to user
      ChannelService channelService = ChannelServiceFactory.getChannelService();
      String token = channelService.createChannel(userId);
      addToCacheList(_tokenKey, userId);

      resp.setCharacterEncoding("UTF-8");
      resp.setContentType("text/html");
      PrintWriter out = resp.getWriter();
      out.print(tokenMessage(user_name, token));
    } else if (message_type.compareTo("leave") == 0) {
      removeFromCacheList(_tokenKey, userId);
    }
  }
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    response.setContentType("text/html");
    PrintWriter out = new PrintWriter(response.getWriter());

    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    if (user != null) {
      out.println("<html>");
      out.println("<head>");
      out.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
      out.println("<title>expressFlow - Mobile Human Task</title>");
      out.println("<link rel=\"stylesheet\" href=\"/css/sencha-touch.css\" type=\"text/css\">");
      out.println("<script type=\"text/javascript\" src=\"/js/sencha-touch.js\"></script>");
      out.println("<script type=\"text/javascript\" src=\"/js/manageprocess.js\"></script>");
      out.println(
          "<style type=\"text/css\">.demos-loading {  background: rgba(0,0,0,.3) url(../resources/shared/loading.gif) center center no-repeat;  display: block;  width: 10em;  height: 10em;  position: absolute;  top: 50%;  left: 50%;  margin-left: -5em;  margin-top: -5em; -webkit-border-radius: .5em; color: #fff; text-shadow: #000 0 1px 1px; text-align: center; padding-top: 8em; font-weight: bold;}</style>");
      out.println("</head>");
      out.println("<body>");
      out.println("</body>");
      out.println("</html>");
    } else {
      response.sendRedirect(
          response.encodeRedirectURL(userService.createLoginURL(request.getRequestURI())));
    }
  }
示例#9
0
 private String getAccountName() {
   UserService userService = UserServiceFactory.getUserService();
   User user = userService.getCurrentUser();
   if (user == null) {
     throw new RuntimeException("No one logged in");
   }
   return user.getEmail();
 }
 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");
   }
 }
 @RequestMapping(value = "/mobileform/{id}", method = RequestMethod.GET)
 public Entity getMobileFormById(@PathVariable String id) throws EntityNotFoundException {
   UserService userService = UserServiceFactory.getUserService();
   User user = userService.getCurrentUser();
   if (user != null) {
     DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
     Key key = KeyFactory.createKey("MobileForm", id);
     Entity result = datastore.get(key);
     return result;
   } else return null;
 }
  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();

    if (user != null) {
      // resp.setContentType("text/plain");
      // resp.getWriter().println("Hello, " + user.getNickname());
      resp.sendRedirect("/pages/guestbook.jsp");
    } else {
      resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
    }
  }
 public static String getMessage() {
   UserService userService = UserServiceFactory.getUserService();
   User user = userService.getCurrentUser();
   String message;
   if (user == null) {
     message = "No one is logged in!\nSent from App Engine at " + new Date();
   } else {
     message = "Hello, " + user.getEmail() + "!\nSent from App Engine at " + new Date();
   }
   log.info("Returning message \"" + message + "\"");
   return message;
 }
  @Override
  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String gameId = request.getParameter("gameKey");
    Objectify ofy = ObjectifyService.ofy();
    Game game = ofy.load().type(Game.class).id(gameId).safe();

    UserService userService = UserServiceFactory.getUserService();
    String currentUserId = userService.getCurrentUser().getUserId();

    // TODO(you): In practice, first validate that the user has permission to delete the Game
    game.deleteChannel(currentUserId);
  }
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();

    if (user != null) {
      resp.setContentType("text/plain");
      resp.getWriter().println("Hello, " + user.getNickname());
    } else {
      resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
    }
  }
示例#16
0
  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();

    if (user != null) {
      // This is a bit horrible, should probably just redirect to a JSP?
      resp.setContentType("text/html");
      resp.getWriter()
          .println(
              "<html><head><link rel=\"icon\" type=\"image/png\" href=\"images/icon16.png\"><meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\"><title>TabCloud</title></head><body><div style=\"margin: 40px auto; width: 600px;\"><img style=\"float: left; padding-right: 20px;\" src=\"images/tabcloud200.png\" alt=\"TabCloud\" /><div style=\"font-family:sans-serif; font-size: 1.8em; text-align: center; padding-top: 50px;\"><strong>You are now logged in.</strong><br />Click the TabCloud menu icon to access TabCloud.</div></div></body></html>");
    } else {
      resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
    }
  }
  public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();

    // String guestbookName = req.getParameter("guestbookName");
    // Key guestbookKey = KeyFactory.createKey("Guestbook", guestbookName);
    String title = req.getParameter("title");
    String content = req.getParameter("content");
    Greeting greeting = new Greeting(user, content, title);

    ofy().save().entity(greeting).now();

    resp.sendRedirect("/ofyguestbook.jsp?");
  }
 /**
  * Get the user using the UserService.
  *
  * <p>If not logged in, return an error message.
  *
  * @return user, or null if not logged in.
  * @throws IOException
  */
 static User checkUser(
     HttpServletRequest req, HttpServletResponse resp, boolean errorIfNotLoggedIn)
     throws IOException {
   User user = null;
   UserService userService = UserServiceFactory.getUserService();
   user = userService.getCurrentUser();
   if (user == null && errorIfNotLoggedIn) {
     // TODO: redirect to OAuth/user service login, or send the URL
     // TODO: 401 instead of 400
     resp.setStatus(400);
     resp.getWriter().println(ERROR_STATUS + " (Not authorized)");
   }
   return user;
 }
  @Override
  public void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    // Create an instance of GoogleOAuthParameters
    GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
    oauthParameters.setOAuthConsumerKey(Constants.CONSUMER_KEY);
    oauthParameters.setOAuthConsumerSecret(Constants.CONSUMER_SECRET);

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

    // Remember the token secret that we stashed? Let's get it back
    // now. We need to add it to oauthParameters
    String oauthTokenSecret = (String) req.getSession().getAttribute("oauthTokenSecret");
    oauthParameters.setOAuthTokenSecret(oauthTokenSecret);

    // The query string should contain the oauth token, so we can just
    // pass the query string to our helper object to correctly
    // parse and add the parameters to our instance of oauthParameters
    oauthHelper.getOAuthParametersFromCallback(req.getQueryString(), oauthParameters);

    try {

      // Now that we have all the OAuth parameters we need, we can
      // generate an access token and access token secret. These
      // are the values we want to keep around, as they are
      // valid for all API calls in the future until a user revokes
      // our access.
      String accessToken = oauthHelper.getAccessToken(oauthParameters);
      String accessTokenSecret = oauthParameters.getOAuthTokenSecret();

      PersistenceManager pm = PMF.get().getPersistenceManager();
      UserService users = UserServiceFactory.getUserService();
      User user = users.getCurrentUser();

      if (user != null) {
        AuthenticatedUser authUser = new AuthenticatedUser();
        authUser.setAuthToken(accessToken);
        authUser.setAuthTokenSecret(accessTokenSecret);
        authUser.setEmailAddress(user.getEmail());
        authUser.setUserId(user.getUserId());
        pm.makePersistent(authUser);
      }

      resp.sendRedirect("/");
    } catch (OAuthException e) {
      // Something went wrong. Usually, you'll end up here if we have invalid
      // oauth tokens
    }
  }
示例#20
0
  public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();

    if (user != null && AtcUser.GetUser(user.getNickname()) != null) {
      boolean saveMode = req.getParameter("saveRoute") != null;
      String routeStr = req.getParameter("data");

      try {
        JSONObject obj = new JSONObject(new JSONTokener(routeStr));
        if (!saveMode) {
          Route route = Route.ParseRouteByWaypoints(obj.getJSONArray("route"), "");
          Transponder transponder = Transponder.Parse(obj.getLong("transponder"));
          if (route == null) {
            resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid Route");
          } else if (transponder == null) {
            resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Transponder Code out of range");
            return;
          } else {
            transponder.setRoute(route);
            resp.setStatus(HttpServletResponse.SC_OK);
          }
        } else {
          String routeName = obj.getString("routeName");
          String airportName = obj.getString("airport");
          Route route = Route.ParseRouteByWaypoints(obj.getJSONArray("route"), routeName);
          if (route == null) {
            resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid Route");
          } else if (routeName == null || routeName.isEmpty()) {
            resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid Route Name");
          } else if (airportName == null || airportName.isEmpty()) {
            resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid Airport Name");
          } else {
            FavoriteRoutes favs = ofy().load().type(FavoriteRoutes.class).id(airportName).get();
            if (favs == null) {
              favs = new FavoriteRoutes(airportName);
            }
            favs.addRoute(route);
            ofy().save().entity(favs).now();
          }
        }
      } catch (JSONException e) {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage());
      }
    } else {
      resp.setStatus(HttpServletResponse.SC_FORBIDDEN);
    }
  }
  public LoginInfo login(String requestUri) {
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    LoginInfo loginInfo = new LoginInfo();

    if (user != null) {
      loginInfo.setLoggedIn(true);
      loginInfo.setEmailAddress(user.getEmail());
      loginInfo.setNickname(user.getNickname());
      loginInfo.setLogoutUrl(userService.createLogoutURL(requestUri));
    } else {
      loginInfo.setLoggedIn(false);
      loginInfo.setLoginUrl(userService.createLoginURL(requestUri));
    }
    return loginInfo;
  }
  @Override
  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    UserService userService = UserServiceFactory.getUserService();
    User currentUser = userService.getCurrentUser();

    if (req.getRequestURI().equals("/favicon.ico")) return;

    if (currentUser != null) {
      resp.setContentType("text/plain");
      PrintWriter pw = resp.getWriter();
      pw.println("Hello, " + currentUser.getNickname());
      pw.println("You have visited " + getAndUpdateVisit(currentUser.getUserId()));
      pw.close();
    } else {
      resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
    }
  }
 @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;
 }
  @Override
  public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();

    String code = (String) req.getParameter("ccode");
    String captcha = (String) req.getSession().getAttribute("captcha");
    if (captcha != null && code != null) {
      if (!captcha.trim().equalsIgnoreCase(code)) {
        resp.getWriter()
            .println(
                "<html><head><title>error</title></head><body>error in captcha."
                    + "<br/><a href='/guestbook.jsp'>Try again</a>.</body></html>");
        return;
      }
    } else {
      resp.getWriter().println("error in captcha");
      return;
    }

    String guestbookName = req.getParameter("guestbookName");
    Key guestbookKey = KeyFactory.createKey("Guestbook", guestbookName);
    String content = req.getParameter("content");
    Date date = new Date();
    Entity greeting = new Entity("Greeting", guestbookKey);
    greeting.setProperty("user", user);
    greeting.setProperty("date", date);
    content = content.substring(0, Math.min(content.length(), 490));
    greeting.setProperty("content", content);

    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    datastore.put(greeting);

    // resp.sendRedirect("/guestbook.jsp?guestbookName=" + guestbookName);
    resp.getWriter()
        .println(
            "<html><head><meta http-equiv='refresh' content='0; url=/guestbook.jsp?guestbookName="
                + guestbookName
                + "'></head></html>");
  }
示例#25
0
  // TODO put in meta information?
  // list all users
  @RequestMapping(method = RequestMethod.GET, value = "")
  @ResponseBody
  public Map<String, List<UserDto>> listUsers(
      @RequestParam(value = "currUser", defaultValue = "") String currUser) {
    final Map<String, List<UserDto>> response = new HashMap<String, List<UserDto>>();
    List<UserDto> results = new ArrayList<UserDto>();

    // TODO check if this part works
    if ("true".equals(currUser)) {
      com.google.appengine.api.users.UserService userService = UserServiceFactory.getUserService();
      com.google.appengine.api.users.User currentUser = userService.getCurrentUser();
      if (currentUser != null) {
        UserDto dto = new UserDto();
        dto.setEmailAddress(currentUser.getEmail());
        dto.setUserName(currentUser.getFederatedIdentity());
        results.add(dto);
      }

    } else {
      List<User> users = userDao.list(Constants.ALL_RESULTS);
      if (users != null) {
        for (User u : users) {
          if ("0".equals(u.getPermissionList()) || Boolean.TRUE.equals(u.isSuperAdmin())) {
            continue;
          }
          UserDto dto = new UserDto();
          BeanUtils.copyProperties(u, dto, new String[] {"config"});
          if (u.getKey() != null) {
            dto.setKeyId(u.getKey().getId());
          }
          results.add(dto);
        }
      }
    }

    response.put("users", results);
    return response;
  }
示例#26
0
  public static Momin findOrCreateUser(Momin user) throws TaskException {

    TaskDao dao = new TaskDao();

    Momin m = dao.getMomin(user.getId());

    // utilisateur n'existe pas dans la base
    if (m == null) {
      if (user.getId().charAt(0) != 'f') {
        UserService usrSrvc = UserServiceFactory.getUserService();
        User u = usrSrvc.getCurrentUser();
        user.setEmail(u.getEmail());
        //				user.setId(u.getUserId());
        user.setName(u.getNickname());
      }
      dao.save(user);
      m = user;
      MailService mailService = MailServiceFactory.getMailService();
      Message message =
          new Message(
              "*****@*****.**",
              "*****@*****.**",
              "Un nouveau utilisateur ",
              user.getEmail()
                  + " "
                  + user.getName()
                  + " a accéder à l'application pour la première fois");
      try {
        mailService.send(message);
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    m = m.clon();
    //
    //	m.setFriendsCalendar(Arrays.asList("105208827974973865566&#0&#naitsoft","110949677754069966012&#0&#sharpensoul","18580476422013912411&#0&#test","11701531798136846518&#0&#test1"));
    return m;
  }
  public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();

    // We have one entity group per Guestbook with all Greetings residing
    // in the same entity group as the Guestbook to which they belong.
    // This lets us run a transactional ancestor query to retrieve all
    // Greetings for a given Guestbook.  However, the write rate to each
    // Guestbook should be limited to ~1/second.
    String guestbookName = req.getParameter("guestbookName");
    Key guestbookKey = KeyFactory.createKey("Guestbook", guestbookName);
    String content = req.getParameter("content");
    Date date = new Date();
    Entity greeting = new Entity("Greeting", guestbookKey);
    greeting.setProperty("user", user);
    greeting.setProperty("date", date);
    greeting.setProperty("content", content);

    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    datastore.put(greeting);

    resp.sendRedirect("/guestbook.jsp?guestbookName=" + guestbookName);
  }
  @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
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    if (!Authenticator.isAuthenticated()) {
      response.sendRedirect("/");
      return;
    }

    // Get the user account
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    request.setAttribute("user", user);

    // Get the logout URL
    String logoutURL = userService.createLogoutURL(request.getRequestURI());
    request.setAttribute("logoutURL", logoutURL);

    // Get the login URL
    String loginURL = userService.createLoginURL(request.getRequestURI());
    request.setAttribute("loginURL", loginURL);

    request.getRequestDispatcher("monitor.jsp").forward(request, response);
  }
示例#30
-3
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    StringBuffer jb = new StringBuffer();
    String line = null;
    try {
      BufferedReader reader = request.getReader();
      while ((line = reader.readLine()) != null) jb.append(line);
    } catch (Exception e) {
      System.out.println("Erreur");
    }
    JSONObject json = new JSONObject(jb.toString());
    System.out.println(jb.toString());

    Petition p = new Petition();

    p.setTitle(json.getValue("title"));
    p.setDescription(json.getValue("text"));
    response.getWriter().println(p.toString());

    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    // Récupération de l'utilisateur google courant

    if (user != null) {
      System.out.println(user.toString());
    } else {
      System.out.println("user null");
    }

    ObjectifyService.ofy().save().entities(p).now();
    response.getWriter().println("Ajout effectué");
  }