本文整理匯總了Java中com.google.appengine.api.users.UserService.getCurrentUser方法的典型用法代碼示例。如果您正苦於以下問題:Java UserService.getCurrentUser方法的具體用法?Java UserService.getCurrentUser怎麽用?Java UserService.getCurrentUser使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.appengine.api.users.UserService
的用法示例。
在下文中一共展示了UserService.getCurrentUser方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: newSharedProduct
import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
@POST
@Produces(MediaType.TEXT_HTML)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public void newSharedProduct(@FormParam("productID") String productID,
@FormParam("productName") String productName,
@Context HttpServletResponse servletResponse) throws Exception {
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
if (user == null) {
System.out.println("Login first");
return;
}
DatastoreService datastore = DatastoreServiceFactory
.getDatastoreService();
Entity entity = new Entity("SharedList", productID);
entity.setProperty("email", user.getEmail());
entity.setProperty("productName", productName);
entity.setProperty("sharedDate", new Date());
datastore.put(entity);
servletResponse.getWriter().println(productName + " has been added.");
servletResponse.flushBuffer();
}
示例2: doPost
import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
@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);
if (user != null) {
greeting.setProperty("author_id", user.getUserId());
greeting.setProperty("author_email", user.getEmail());
}
greeting.setProperty("date", date);
greeting.setProperty("content", content);
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
datastore.put(greeting);
resp.sendRedirect("/guestbook.jsp?guestbookName=" + guestbookName);
}
示例3: doGet
import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
@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()));
}
}
}
示例4: doPost
import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
Greeting greeting;
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser(); // Find out who the user is.
String guestbookName = req.getParameter("guestbookName");
String content = req.getParameter("content");
if (user != null) {
greeting = new Greeting(guestbookName, content, user.getUserId(), user.getEmail());
} else {
greeting = new Greeting(guestbookName, content);
}
// Use Objectify to save the greeting and now() is used to make the call synchronously as we
// will immediately get a new page using redirect and we want the data to be present.
ObjectifyService.ofy().save().entity(greeting).now();
resp.sendRedirect("/guestbook.jsp?guestbookName=" + guestbookName);
}
示例5: login
import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
public LoginInfo login(String requestUri) {
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
LoginInfo loginInfo = new LoginInfo();
if (user != null) {
Objectify ofy = Dao.getInstance().getObjectify();
loginInfo.setLoggedIn(true);
loginInfo.setEmailAddress(user.getEmail());
loginInfo.setNickname(user.getNickname());
loginInfo.setLogoutUrl(userService.createLogoutURL(requestUri));
Collection<UserFavouritePosition> favs = Dao.getInstance().getUserFavouritePositions(user, ofy);
if(favs != null && favs.size() > 0) {
List<UserFavouritePositionProxy> favourites = new LinkedList<UserFavouritePositionProxy>();
for(UserFavouritePosition fav : favs) {
favourites.add(new UserFavouritePositionProxy(fav.getName(), fav.getPos().getLatitude(), fav.getPos().getLongitude(), fav.getId().toString()));
}
loginInfo.setFavourites(favourites);
}
} else {
loginInfo.setLoggedIn(false);
loginInfo.setLoginUrl(userService.createLoginURL(requestUri));
}
return loginInfo;
}
示例6: getMiscFunctionInfoList
import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
@Override
public RpcResult< List< MiscFunctionInfo > > getMiscFunctionInfoList() {
LOGGER.fine( "" );
final UserService userService = UserServiceFactory.getUserService();
final User user = userService.getCurrentUser();
if ( user == null )
return RpcResult.createNotLoggedInErrorResult();
if ( !userService.isUserAdmin() )
return RpcResult.createNoPermissionErrorResult();
final List< MiscFunctionInfo > miscFunctionInfoList = new ArrayList< MiscFunctionInfo >( miscFunctionMap.size() );
for ( final Entry< String, DatastoreTask > entry : miscFunctionMap.entrySet() )
miscFunctionInfoList.add( new MiscFunctionInfo( entry.getKey(), entry.getValue().getParamNames() ) );
Collections.sort( miscFunctionInfoList, new Comparator< MiscFunctionInfo >() {
@Override
public int compare( final MiscFunctionInfo i1, final MiscFunctionInfo i2 ) {
return i1.getName().compareTo( i2.getName() );
}
} );
return new RpcResult< List< MiscFunctionInfo > >( miscFunctionInfoList );
}
示例7: doGet
import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
@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);
}
示例8: doPost
import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
@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);
}
示例9: doGet
import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String redirect = req.getParameter(Constants.LOGIN_REDIRECT_KEY);
if (redirect == null) {
redirect = "/requests";
}
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
if (user == null) {
req.setAttribute(Constants.LOGIN_REDIRECT_KEY, redirect);
req.getRequestDispatcher("/WEB-INF/login.jsp").forward(req, resp);
} else {
resp.sendRedirect(redirect);
}
}
示例10: sign
import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
@POST
@Path("/sign")
@Produces(MediaType.TEXT_HTML)
public Response sign(
@Context HttpServletRequest request,
@FormParam("guestbookName") @DefaultValue("default") String guestbookName,
@FormParam("content") String content) {
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
Key guestbookKey = KeyFactory.createKey("Guestbook", guestbookName);
Entity greeting = new Entity("Greeting", guestbookKey);
greeting.setProperty("user", user);
greeting.setProperty("date", new Date());
greeting.setProperty("content", content);
DatastoreService datastore = DatastoreServiceFactory
.getDatastoreService();
datastore.put(greeting);
Map<String, Object> model = buildModel(request, guestbookName);
return Response.ok(new Viewable("/guestbook", model)).build();
}
示例11: doStartTag
import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
public int doStartTag() throws JspException {
UserService userService = UserServiceFactory.getUserService();
if (userService.isUserLoggedIn()==false) {
throw new JspException("User is not logged in");
}
User usr = userService.getCurrentUser();
PersistenceManager em = getPM();
try {
JPAUser dbUser = DAO.getUsersDAO().findOrCreateUser(em, usr);
//update last time of visit
dbUser.setLastVisit(new Date());
} catch (Exception e) {
e.printStackTrace();
log.log(Level.SEVERE,e.getMessage());
log.log(Level.SEVERE,e.getStackTrace().toString());
throw new JspException(e);
}
return SKIP_BODY;
}
示例12: doPost
import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
Greeting greeting;
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
String guestbookName = req.getParameter("guestbookName");
String content = req.getParameter("content");
if (user != null) {
greeting = new Greeting(guestbookName, content, user.getUserId(), user.getEmail());
} else {
greeting = new Greeting(guestbookName, content);
}
// Use Objectify to save the greeting and now() is used to make the call synchronously as we
// will immediately get a new page using redirect and we want the data to be present.
ObjectifyService.ofy().save().entity(greeting).now();
resp.sendRedirect("/guestbook.jsp?guestbookName=" + guestbookName);
}
開發者ID:GoogleCloudPlatform,項目名稱:appengine-maven-archetypes-java,代碼行數:22,代碼來源:SignGuestbookServlet.java
示例13: doGet
import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
@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()));
}
}
}
示例14: doPost
import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
Greeting greeting;
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser(); // Find out who the user is.
String guestbookName = req.getParameter("guestbookName");
String content = req.getParameter("content");
if (user != null) {
greeting = new Greeting(guestbookName, content, user.getUserId(), user.getEmail());
} else {
greeting = new Greeting(guestbookName, content);
}
// Use Objectify to save the greeting and now() is used to make the call synchronously as we
// will immediately get a new page using redirect and we want the data to be present.
ObjectifyService.ofy().save().entity(greeting).now();
resp.sendRedirect("/guestbook.jsp?guestbookName=" + guestbookName);
}
開發者ID:GoogleCloudPlatform,項目名稱:appengine-java-guestbook-multiphase,代碼行數:22,代碼來源:SignGuestbookServlet.java
示例15: doPost
import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
String firstName = req.getParameter("firstName");
Key firstKey = KeyFactory.createKey("Guestbook", firstName);
String content = req.getParameter("content");
Date date = new Date();
Entity greeting = new Entity("Greeting", firstKey);
greeting.setProperty("user", user);
greeting.setProperty("date", date);
greeting.setProperty("content", content);
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
datastore.put(greeting);
resp.sendRedirect("/welcome.jsp?firstName=" + firstName);
}