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"); }
@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 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); } }
@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)); } } }
@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"); } } }
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()))); } }
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("/"); }
public static String getLogoutURL(String returnURL) { UserService userService = UserServiceFactory.getUserService(); String URL = userService.createLogoutURL(returnURL); if (AppEngineUtil.isDevelopment()) { URL = JEUtils.getRequestServer() + URL; } return URL; }
private String getAccountName() { UserService userService = UserServiceFactory.getUserService(); User user = userService.getCurrentUser(); if (user == null) { throw new RuntimeException("No one logged in"); } return user.getEmail(); }
@Override protected void getAndPost(HttpServletRequest req, HttpServletResponse resp) { UserService userService = UserServiceFactory.getUserService(); if (userService.isUserLoggedIn()) { returnContent("{\"status\":\"yes\"}", resp); } returnContent("{\"status\":\"no\"}", resp); }
public void commence( HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { UserService userService = UserServiceFactory.getUserService(); response.sendRedirect(userService.createLoginURL(request.getRequestURI())); }
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { Owner owner = DatastoreManager.getCurrentOwner(); if (owner == null) { UserService userService = UserServiceFactory.getUserService(); resp.sendRedirect(userService.createLoginURL(req.getRequestURI())); return; } resp.sendRedirect("/driverselection.jsp"); }
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; }
@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); }
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; }
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())); } }
private String getUserLink(String href) { UserService userService = UserServiceFactory.getUserService(); User user = getUser(); String ret = ""; if (user == null) { ret = "<a href=" + userService.createLoginURL(href) + ">Login here</a>"; } else if (isAdmin(user)) { ret = "<a href=\"admin\">Administration</a>"; } else { ret = "<a href=\"" + userService.createLogoutURL(href) + "\">Sign Out</a>"; } return ret; }
@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())); } }
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?"); }
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())); } }
/** * 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 } }
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())); } }
public void serv(HttpServletRequest req, HttpServletResponse resp) throws IOException { UserService userService = UserServiceFactory.getUserService(); resp.setContentType("text/html"); if (req.getUserPrincipal() != null) { resp.getWriter() .println( "<p>Hello, " + req.getUserPrincipal().getName() + "! You can <a href=\"" + userService.createLogoutURL("/") + "\">sign out</a>.</p>"); } else { resp.getWriter() .println( "<p>Please <a href=\"" + userService.createLoginURL("/") + "\">sign in</a>.</p>"); } }
@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; }
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); }
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é"); }