Search in sources :

Example 1 with UserService

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()));
        }
    }
}
Also used : User(com.google.appengine.api.users.User) UserService(com.google.appengine.api.users.UserService) Properties(java.util.Properties)

Example 2 with UserService

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);
}
Also used : Entity(com.google.appengine.api.datastore.Entity) User(com.google.appengine.api.users.User) UserService(com.google.appengine.api.users.UserService) DatastoreService(com.google.appengine.api.datastore.DatastoreService) Key(com.google.appengine.api.datastore.Key) Date(java.util.Date)

Example 3 with UserService

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;
    }
}
Also used : User(com.google.appengine.api.users.User) UserService(com.google.appengine.api.users.UserService)

Example 4 with UserService

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);
}
Also used : UserService(com.google.appengine.api.users.UserService) GuestbookResponse(com.google.appengine.samples.angularjs_guestbook.domain.GuestbookResponse)

Example 5 with UserService

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()));
}
Also used : UserService(com.google.appengine.api.users.UserService)

Aggregations

UserService (com.google.appengine.api.users.UserService)5 User (com.google.appengine.api.users.User)3 DatastoreService (com.google.appengine.api.datastore.DatastoreService)1 Entity (com.google.appengine.api.datastore.Entity)1 Key (com.google.appengine.api.datastore.Key)1 GuestbookResponse (com.google.appengine.samples.angularjs_guestbook.domain.GuestbookResponse)1 Date (java.util.Date)1 Properties (java.util.Properties)1