use of com.google.appengine.api.users.UserService in project appengine-guestbook-java by googlearchive.
the class GuestbookServlet method doGet.
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
if (req.getParameter("testing") == null) {
resp.setContentType("text/plain");
resp.getWriter().println("Hello, this is a testing servlet. \n\n");
Properties p = System.getProperties();
p.list(resp.getWriter());
} else {
UserService userService = UserServiceFactory.getUserService();
User currentUser = userService.getCurrentUser();
if (currentUser != null) {
resp.setContentType("text/plain");
resp.getWriter().println("Hello, " + currentUser.getNickname());
} else {
resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
}
}
}
use of com.google.appengine.api.users.UserService in project appengine-guestbook-java by googlearchive.
the class SignGuestbookServlet method doPost.
@Override
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 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);
}
use of com.google.appengine.api.users.UserService in project iosched by google.
the class BaseServlet method checkUser.
protected boolean checkUser() {
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
String authDomain = user.getAuthDomain();
if (authDomain.contains("google.com")) {
return true;
} else {
return false;
}
}
use of com.google.appengine.api.users.UserService in project appengine-angular-guestbook-java by googlearchive.
the class GuestbookResource method signGuestbook.
@POST
@Path("/{guestbookName}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public GuestbookResponse signGuestbook(@DefaultValue("default") @PathParam("guestbookName") final String guestbookName, final Map<String, String> postData) {
UserService userService = UserServiceFactory.getUserService();
DatastoreService datastoreService = DatastoreServiceFactory.getDatastoreService();
Key guestbookKey = KeyFactory.createKey("Guestbook", guestbookName);
// We set the above parent key on each Greeting entity in order to make the queries strong
// consistent. Please Note that as a trade off, we can not write to a single guestbook at a
// rate more than 1 write/second.
String content = postData.get("content");
if (content != null && content.length() > 0) {
Date date = new Date();
Entity greeting = new Entity("Greeting", guestbookKey);
greeting.setProperty("user", userService.getCurrentUser());
greeting.setProperty("date", date);
greeting.setProperty("content", content);
datastoreService.put(greeting);
}
return new GuestbookResponse(guestbookName, getGreetings(guestbookName), null);
}
use of com.google.appengine.api.users.UserService in project spring-security by spring-projects.
the class GoogleAccountsAuthenticationEntryPoint method commence.
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
UserService userService = UserServiceFactory.getUserService();
response.sendRedirect(userService.createLoginURL(request.getRequestURI()));
}
Aggregations