當前位置: 首頁>>代碼示例>>Java>>正文


Java UserService.getCurrentUser方法代碼示例

本文整理匯總了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();
}
 
開發者ID:fasthall,項目名稱:amazon-price-tracker,代碼行數:24,代碼來源:Sharedlist.java

示例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);
}
 
開發者ID:luisibanez,項目名稱:running-with-zebras-101,代碼行數:24,代碼來源:SignGuestbookServlet.java

示例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()));
    }
  }
}
 
開發者ID:luisibanez,項目名稱:running-with-zebras-101,代碼行數:22,代碼來源:GuestbookServlet.java

示例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);
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:22,代碼來源:SignGuestbookServlet.java

示例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;
}
 
開發者ID:Hellek1,項目名稱:viaja-facil,代碼行數:26,代碼來源:ExtractedFunctions.java

示例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 );
}
 
開發者ID:icza,項目名稱:sc2gears,代碼行數:26,代碼來源:AdminServiceImpl.java

示例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);
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:20,代碼來源:ChatServlet.java

示例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);
}
 
開發者ID:bickeylam,項目名稱:guestbook-bilibalam,代碼行數:21,代碼來源:SignGuestbookServlet.java

示例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);
	}
}
 
開發者ID:hasier,項目名稱:voxpopuli,代碼行數:17,代碼來源:Login.java

示例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();
}
 
開發者ID:gconcon,項目名稱:appengine-guestbookwithguice-java,代碼行數:24,代碼來源:GuestbookResource.java

示例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;
}
 
開發者ID:Antokolos,項目名稱:iambookmaster,代碼行數:21,代碼來源:UpdateUserBasicAccountInfoTag.java

示例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()));
    }
  }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-maven-archetypes-java,代碼行數:22,代碼來源:GuestbookServlet.java

示例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);
}
 
開發者ID:karask,項目名稱:quotes-appengine,代碼行數:21,代碼來源:SignGuestbookServlet.java


注:本文中的com.google.appengine.api.users.UserService.getCurrentUser方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。