本文整理汇总了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);
}