Skip to content
Browse files

able to sign in with Google account.

  • Loading branch information...
1 parent 4a4b61f commit bca63416812381a5fe88d7d8f5959bfc400d84f2 @critical-bug committed Jul 10, 2011
View
22 server_gae/src/ydeb_a10/Server_gaeServlet.java
@@ -1,11 +1,27 @@
package ydeb_a10;
+
import java.io.IOException;
+import java.security.Principal;
+
import javax.servlet.http.*;
+import com.google.appengine.api.users.UserService;
+import com.google.appengine.api.users.UserServiceFactory;
@SuppressWarnings("serial")
public class Server_gaeServlet extends HttpServlet {
- public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
- resp.setContentType("text/plain");
- resp.getWriter().println("Hello, world");
+ @Override
+ public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
+ final UserService userService = UserServiceFactory.getUserService();
+ Principal user = request.getUserPrincipal();
+
+ final String thisUri = request.getRequestURI();
+ final String pageHtml;
+ if (user != null) {
+ pageHtml = "<p>Hello, " + user.getName() + "! You can <a href=\"" + userService.createLogoutURL(thisUri) + "\">sign out</a>.</p>";
+ } else {
+ pageHtml = "<p>Please <a href=\"" + userService.createLoginURL(thisUri) + "\">sign in</a>.</p>";
+ }
+ response.setContentType("text/html; charset=utf-8");
+ response.getWriter().println(pageHtml);
}
}
View
BIN server_gae/war/WEB-INF/classes/ydeb_a10/Server_gaeServlet.class
Binary file not shown.

0 comments on commit bca6341

Please sign in to comment.
Something went wrong with that request. Please try again.