@RequestMapping(value = "/show", method = RequestMethod.POST) public ModelAndView show(@ModelAttribute ReportForm reportForm) { // always from the first day Calendar calendarFrom = new GregorianCalendar(reportForm.getFromYear(), reportForm.getFromMonth(), 1); Calendar calendarUntil = new GregorianCalendar(reportForm.getUntilYear(), reportForm.getUntilMonth(), 1); // input trasverse are also supported Date from, until; if (calendarFrom.after(calendarUntil)) { from = calendarUntil.getTime(); until = calendarFrom.getTime(); } else { from = calendarFrom.getTime(); until = calendarUntil.getTime(); } Report report = reportService.generate( UserServiceFactory.getUserService().getCurrentUser().getEmail(), UserServiceFactory.getUserService().getCurrentUser().getNickname(), from, until); return new ModelAndView().addObject("report", report).addObject("mailerService", mailerService); }
public static boolean authenticate(String ownerId) { User currentUser = UserServiceFactory.getUserService().getCurrentUser(); if (currentUser != null) { String currentUID = UserServiceFactory.getUserService().getCurrentUser().getUserId(); return currentUID.equals(ownerId); } return false; }
public class Authenticator { private UserService userService = UserServiceFactory.getUserService(); public boolean isValidEmail(String fromAddress, DataStorage dataStore) { // Whitelist all @songkick.com email addresses if (fromAddress.contains("@songkick.com")) { return true; } List<com.songkick.snippets.model.User> users = dataStore.getCurrentUsers(); // Whitelist all existing users for (com.songkick.snippets.model.User user : users) { if (user.matchesEmail(fromAddress)) { return true; } } return false; } public User getUser() { return userService.getCurrentUser(); } public boolean isSongkickUser(DataStorage dataStore) { // Check this is a songkick.com user User user = getUser(); if (user == null) { Debug.error("Could not get current user during authentication"); return false; } return isValidEmail(user.getEmail(), dataStore); } public String isSongkickAdmin(String redirectURL, DataStorage dataStore) { User user = getUser(); if (user == null) { Debug.error("Authenticator.isSongkickAdmin: no user found, could not authenticate"); return userService.createLoginURL(redirectURL); } // Whitelist admin users if (user.getEmail().equals("*****@*****.**")) { return null; } List<com.songkick.snippets.model.User> users = dataStore.getCurrentUsers(); for (com.songkick.snippets.model.User modelUser : users) { if (modelUser.matchesEmail(user.getEmail()) && modelUser.isAdmin()) { return null; } } return userService.createLoginURL(redirectURL); } }
@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(); 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"); }
@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 req, HttpServletResponse resp) throws IOException { if (req.getParameter("sid") != null) { Session session; long sid; try { sid = Long.parseLong(req.getParameter("sid")); } catch (NumberFormatException e) { Send.Error(resp, "sid parse error"); Log.sidInvalid(req); return; } try { session = new Session(sid, req); } catch (SecurityException e) { Send.Error(resp, e); Log.append(sid, e); return; } session.abandon(); } Send.Data( resp, "{\"logout\":\"" + UserServiceFactory.getUserService().createLogoutURL("close.html") + "\"}"); return; }
private boolean persistNoteImage(String contentType, byte[] bytes, String noteKey) { Store.Api api = store.getApi(); User user = UserServiceFactory.getUserService().getCurrentUser(); // NoteImage image = new NoteImage(bytes, contentType, user.getEmail(), new Date(), new Date()); try { Author me = api.getOrCreateNewAuthor(user); Transaction tx = api.begin(); Note note = api.getNote(KeyFactory.stringToKey(noteKey)); if (!note.getAuthorEmail().equalsIgnoreCase(me.getEmail())) { return false; } Transform resize = ImagesServiceFactory.makeResize(400, 400); ImagesService imagesService = ImagesServiceFactory.getImagesService(); Image oldImage = ImagesServiceFactory.makeImage(bytes); Image newImage = imagesService.applyTransform(resize, oldImage, OutputEncoding.JPEG); note.setImageData(new Blob(newImage.getImageData())); note.setContentType(contentType); api.saveNote(note); tx.commit(); log.debug("Persisted image with for note: " + note.getKey()); } catch (Exception ex) { log.error(ex.getMessage(), ex); return false; } finally { api.close(); } return true; }
@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 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 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 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(); 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 getAndPost(HttpServletRequest req, HttpServletResponse resp) { UserService userService = UserServiceFactory.getUserService(); if (userService.isUserLoggedIn()) { returnContent("{\"status\":\"yes\"}", resp); } returnContent("{\"status\":\"no\"}", resp); }
private String getAccountName() { UserService userService = UserServiceFactory.getUserService(); User user = userService.getCurrentUser(); if (user == null) { throw new RuntimeException("No one logged in"); } return user.getEmail(); }
public enum CommonViewUtil { ; private static UserService userService = UserServiceFactory.getUserService(); public static String createLogoutURL() { return userService.createLogoutURL("../"); } }
public static String getLogoutURL(String returnURL) { UserService userService = UserServiceFactory.getUserService(); String URL = userService.createLogoutURL(returnURL); if (AppEngineUtil.isDevelopment()) { URL = JEUtils.getRequestServer() + URL; } return URL; }
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"); }
@RequestMapping(value = "/logout", method = RequestMethod.GET) public void logout(HttpServletRequest request, HttpServletResponse response) throws IOException { SecurityContextHolder.clearContext(); request.getSession().invalidate(); String logoutUrl = UserServiceFactory.getUserService().createLogoutURL("/loggedout"); response.sendRedirect(logoutUrl); }
@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 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())); } }
@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())); } }
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; }
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; }
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 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é"); }