当前位置: 首页>>代码示例>>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;未经允许,请勿转载。