Search in sources :

Example 21 with User

use of com.google.appengine.api.users.User in project java-docs-samples by GoogleCloudPlatform.

the class ChatServlet method doGet.

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    final UserService userService = UserServiceFactory.getUserService();
    User currentUser = userService.getCurrentUser();
    String room = req.getParameter("room");
    // Show login link if user is not logged in.
    if (currentUser == null) {
        String loginUrl = userService.createLoginURL(getUriWithChatRoom(req, room));
        resp.getWriter().println("<p>Please <a href=\"" + loginUrl + "\">sign in</a>.</p>");
        return;
    }
    // user is already logged in
    if (room != null) {
        req.setAttribute("room", room);
    }
    getServletContext().getRequestDispatcher("/WEB-INF/view/chat.jsp").forward(req, resp);
}
Also used : User(com.google.appengine.api.users.User) UserService(com.google.appengine.api.users.UserService)

Example 22 with User

use of com.google.appengine.api.users.User in project java-docs-samples by GoogleCloudPlatform.

the class Greeting method create.

static Greeting create(Entity entity) {
    User user = (User) entity.getProperty("user");
    Instant date = new Instant((Date) entity.getProperty("date"));
    String content = (String) entity.getProperty("content");
    return new AutoValue_Greeting(user, date, content);
}
Also used : User(com.google.appengine.api.users.User) Instant(org.joda.time.Instant)

Example 23 with User

use of com.google.appengine.api.users.User in project appengine-angular-guestbook-java by googlearchive.

the class Greeting method fromEntity.

public static Greeting fromEntity(Entity greetingEntity) {
    String author;
    User user = (User) greetingEntity.getProperty("user");
    if (user == null) {
        author = "an anonymous user";
    } else {
        author = user.getEmail();
    }
    return new Greeting((String) greetingEntity.getProperty("content"), (Date) greetingEntity.getProperty("date"), author);
}
Also used : User(com.google.appengine.api.users.User)

Example 24 with User

use of com.google.appengine.api.users.User in project appengine-guestbook-java by googlearchive.

the class SignGuestbookServletTest method testDoPost.

@Test
public void testDoPost() throws IOException, EntityNotFoundException {
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    String guestbookName = "TestGuestbook";
    String testContent = "Test Content";
    when(request.getParameter("guestbookName")).thenReturn(guestbookName);
    when(request.getParameter("content")).thenReturn(testContent);
    Date priorToRequest = new Date();
    signGuestbookServlet.doPost(request, response);
    Date afterRequest = new Date();
    verify(response).sendRedirect("/guestbook.jsp?guestbookName=TestGuestbook");
    User currentUser = UserServiceFactory.getUserService().getCurrentUser();
    Entity greeting = DatastoreServiceFactory.getDatastoreService().prepare(new Query()).asSingleEntity();
    assertEquals(guestbookName, greeting.getKey().getParent().getName());
    assertEquals(testContent, greeting.getProperty("content"));
    assertEquals(currentUser, greeting.getProperty("user"));
    Date date = (Date) greeting.getProperty("date");
    assertTrue("The date in the entity [" + date + "] is prior to the request being performed", priorToRequest.before(date) || priorToRequest.equals(date));
    assertTrue("The date in the entity [" + date + "] is after to the request completed", afterRequest.after(date) || afterRequest.equals(date));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Entity(com.google.appengine.api.datastore.Entity) User(com.google.appengine.api.users.User) Query(com.google.appengine.api.datastore.Query) HttpServletResponse(javax.servlet.http.HttpServletResponse) Date(java.util.Date) Test(org.junit.Test)

Aggregations

User (com.google.appengine.api.users.User)24 UserService (com.google.appengine.api.users.UserService)8 HashMap (java.util.HashMap)4 Date (java.util.Date)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 Entity (com.google.appengine.api.datastore.Entity)2 Pusher (com.pusher.rest.Pusher)2 PresenceUser (com.pusher.rest.data.PresenceUser)2 Result (com.pusher.rest.data.Result)2 PrintWriter (java.io.PrintWriter)2 Test (org.junit.Test)2 GaeUser (samples.gae.users.GaeUser)2 DatastoreService (com.google.appengine.api.datastore.DatastoreService)1 Key (com.google.appengine.api.datastore.Key)1 Query (com.google.appengine.api.datastore.Query)1 OAuthRequestException (com.google.appengine.api.oauth.OAuthRequestException)1 OAuthService (com.google.appengine.api.oauth.OAuthService)1 Document (com.google.appengine.api.search.Document)1 StringWriter (java.io.StringWriter)1