本文整理汇总了Java中com.google.appengine.api.users.UserServiceFactory.getUserService方法的典型用法代码示例。如果您正苦于以下问题:Java UserServiceFactory.getUserService方法的具体用法?Java UserServiceFactory.getUserService怎么用?Java UserServiceFactory.getUserService使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.appengine.api.users.UserServiceFactory
的用法示例。
在下文中一共展示了UserServiceFactory.getUserService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import com.google.appengine.api.users.UserServiceFactory; //导入方法依赖的package包/类
@Override
public void process() {
UserService userService = UserServiceFactory.getUserService();
// Step 1: Add Text into DB.
Entity textEntity = getNewEntity();
textEntity.setProperty("rawText", new Text(text));
textEntity.setProperty("user",
userService.getCurrentUser().getNickname());
textEntity.setProperty("date", new Date());
putIntoDatabase(textEntity);
Key parentKey = textEntity.getKey();
factory.setParentKey(parentKey);
// Step 2: Call other processors.
factory.createTypePredictor().process();
factory.createKnowledgeGraphBuilder().process();
factory.createSummaryGenerator().process();
}
示例2: newSharedProduct
import com.google.appengine.api.users.UserServiceFactory; //导入方法依赖的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();
}
示例3: doGet
import com.google.appengine.api.users.UserServiceFactory; //导入方法依赖的package包/类
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
UserService userService = UserServiceFactory.getUserService();
String url = "";
String urlLinktext = "Login";
String user = "";
EntityManager em = EMFService.get().createEntityManager();
String email = (String) req.getSession().getAttribute("login");
UsuariosModel usuario;
if (email != null) {
UsuariosDAOImpl udao = UsuariosDAOImpl.getInstance();
usuario = udao.readUserByEmail(em, email);
em.close();
user = usuario.getName();
url = "/logout";
urlLinktext = "Logout";
}
req.getSession().setAttribute("user", user);
req.getSession().setAttribute("url", url);
req.getSession().setAttribute("urlLinktext", urlLinktext);
RequestDispatcher view = req.getRequestDispatcher("contact.jsp");
view.forward(req, resp);
}
示例4: setUp
import com.google.appengine.api.users.UserServiceFactory; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
action.enabled = true;
action.logoFilename = "logo.png";
action.productName = "Nomulus";
action.integrationEmail = "[email protected]";
action.supportEmail = "[email protected]";
action.announcementsEmail = "[email protected]";
action.supportPhoneNumber = "1 (888) 555 0123";
action.technicalDocsUrl = "http://example.com/technical-docs";
action.req = request;
action.response = response;
action.sessionUtils = sessionUtils;
action.userService = UserServiceFactory.getUserService();
action.xsrfTokenManager = new XsrfTokenManager(new FakeClock(), action.userService);
UserAuthInfo userAuthInfo = UserAuthInfo.create(user, false);
action.authResult = AuthResult.create(AuthLevel.USER, userAuthInfo);
when(sessionUtils.checkRegistrarConsoleLogin(request, userAuthInfo)).thenReturn(true);
when(sessionUtils.getRegistrarClientId(request)).thenReturn("TheRegistrar");
}
示例5: doPost
import com.google.appengine.api.users.UserServiceFactory; //导入方法依赖的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);
}
示例6: doFilter
import com.google.appengine.api.users.UserServiceFactory; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest servletReq, ServletResponse servletResp, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) servletReq;
HttpServletResponse resp = (HttpServletResponse) servletResp;
String path = req.getRequestURI();
chain.doFilter(servletReq, servletResp);
UserService userService = UserServiceFactory.getUserService();
if (userService.isUserLoggedIn()) {
resp.sendRedirect(userService.createLogoutURL("/logout"));
} else if (path.startsWith("/logout")) {
resp.sendRedirect("/books");
}
}
示例7: doGet
import com.google.appengine.api.users.UserServiceFactory; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException, ServletException {
UserService userService = UserServiceFactory.getUserService();
if (userService.isUserLoggedIn()) {
// Save the relevant profile info and store it in the session.
User user = userService.getCurrentUser();
req.getSession().setAttribute("userEmail", user.getEmail());
req.getSession().setAttribute("userId", user.getUserId());
String destination = (String) req.getSession().getAttribute("loginDestination");
if (destination == null) {
destination = "/books";
}
resp.sendRedirect(destination);
} else {
resp.sendRedirect(userService.createLoginURL("/login"));
}
}
示例8: doPost
import com.google.appengine.api.users.UserServiceFactory; //导入方法依赖的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);
}
示例9: getApiKey
import com.google.appengine.api.users.UserServiceFactory; //导入方法依赖的package包/类
@Override
public RpcResult< String > getApiKey( final String sharedApiAccount ) {
LOGGER.fine( "sharedApiAccount: " + sharedApiAccount );
final UserService userService = UserServiceFactory.getUserService();
final User user = userService.getCurrentUser();
if ( user == null )
return RpcResult.createNotLoggedInErrorResult();
PersistenceManager pm = null;
try {
pm = PMF.get().getPersistenceManager();
final ApiAccount apiAccount = getApiAccount( pm, sharedApiAccount, user );
if ( apiAccount == null )
return RpcResult.createNoPermissionErrorResult();
else
return new RpcResult< String >( apiAccount.getApiKey() );
} finally {
if ( pm != null )
pm.close();
}
}
示例10: doGet
import com.google.appengine.api.users.UserServiceFactory; //导入方法依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
UserService userService = UserServiceFactory.getUserService();
String thisUrl = req.getRequestURI();
resp.setContentType("text/html");
if (req.getUserPrincipal() != null) {
resp.getWriter().println("<p>Hello, "
+ req.getUserPrincipal().getName()
+ "! You can <a href=\""
+ userService.createLogoutURL(thisUrl)
+ "\">sign out</a>.</p>");
} else {
resp.getWriter().println("<p>Please <a href=\""
+ userService.createLoginURL(thisUrl)
+ "\">sign in</a>.</p>");
}
}
示例11: performImplictFlow
import com.google.appengine.api.users.UserServiceFactory; //导入方法依赖的package包/类
@Override
protected void performImplictFlow(Oauth2Request oauth2, HttpServletRequest req, HttpServletResponse resp)
throws IOException {
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
// Check if the user is signed in to your service. If the user
// isn't signed in, complete service's sign-in or sign-up
// flow.
if (user == null) {
if (req.getQueryString() != null)
resp.sendRedirect(
userService.createLoginURL(req.getRequestURI().concat("?").concat(req.getQueryString())));
else
resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
} else {
TokenPayload t = new TokenPayload();
t.setType(TokenType.ACCESS_TOKEN);
t.setUserId(user.getUserId());
String token;
try {
/*
* TODO: we need to genereta a token here, we need to manage a
* key or generete a random numer. We use "null" as third
* parameter just to avoid compiler errors, but you need to
* change this code.
*/
token = TokenGenerator.generate(gson, t, null);
} catch (Exception e) {
sendError(resp, Oauth2Error.INVALID_GRANT);
log.log(Level.SEVERE, "Token generation error: " + e.getMessage(), e);
return;
}
resp.sendRedirect(oauth2.getResponseUri(token));
}
}
示例12: performAuthFlow
import com.google.appengine.api.users.UserServiceFactory; //导入方法依赖的package包/类
@Override
protected void performAuthFlow(Oauth2Request oauth2, HttpServletRequest req, HttpServletResponse resp)
throws IOException {
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
// Check if the user is signed in to your service. If the user
// isn't signed in, complete service's sign-in or sign-up
// flow.
if (user == null) {
if (req.getQueryString() != null)
resp.sendRedirect(
userService.createLoginURL(req.getRequestURI().concat("?").concat(req.getQueryString())));
else
resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
} else {
TokenPayload t = new TokenPayload();
t.setType(TokenType.AUTH_TOKEN);
t.setExpirationTime(System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(10));
t.setUserId(user.getUserId());
String token;
try {
/*
* TODO: we need to genereta a token here, we need to manage a
* key or generete a random numer. We use "null" as third
* parameter just to avoid compiler errors, but you need to
* change this code.
*/
token = TokenGenerator.generate(gson, t, null);
} catch (Exception e) {
sendError(resp, Oauth2Error.INVALID_GRANT);
log.log(Level.SEVERE, "Token generation error: " + e.getMessage(), e);
return;
}
resp.sendRedirect(oauth2.getResponseUri(token));
}
}
示例13: checkUser
import com.google.appengine.api.users.UserServiceFactory; //导入方法依赖的package包/类
protected boolean checkUser() {
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
String authDomain = user.getAuthDomain();
if (authDomain.contains("google.com")) {
return true;
} else {
return false;
}
}
示例14: getEntitiesBrowser
import com.google.appengine.api.users.UserServiceFactory; //导入方法依赖的package包/类
@GET
@Produces(MediaType.TEXT_XML)
public List<WishlistProduct> getEntitiesBrowser() {
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
if (user == null) {
System.out.println("Login first");
return null;
}
List<WishlistProduct> list = new ArrayList<WishlistProduct>();
DatastoreService datastore = DatastoreServiceFactory
.getDatastoreService();
Query query = new Query(user.getEmail());
query.addSort(Entity.KEY_RESERVED_PROPERTY, SortDirection.ASCENDING);
List<Entity> results = datastore.prepare(query).asList(
FetchOptions.Builder.withDefaults());
for (Entity entity : results) {
String productID = (String) entity.getKey().getName();
String productName = (String) entity.getProperty("productName");
double currentPrice = (double) entity.getProperty("currentPrice");
double lowestPrice = (double) entity.getProperty("lowestPrice");
Date lowestDate = (Date) entity.getProperty("lowestDate");
list.add(new WishlistProduct(productID, productName, currentPrice,
lowestPrice, lowestDate));
}
return list;
}
示例15: getEntities
import com.google.appengine.api.users.UserServiceFactory; //导入方法依赖的package包/类
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public List<WishlistProduct> getEntities() {
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
if (user == null) {
System.out.println("Login first");
return null;
}
List<WishlistProduct> list = new ArrayList<WishlistProduct>();
DatastoreService datastore = DatastoreServiceFactory
.getDatastoreService();
Query query = new Query(user.getEmail());
query.addSort(Entity.KEY_RESERVED_PROPERTY, SortDirection.ASCENDING);
List<Entity> results = datastore.prepare(query).asList(
FetchOptions.Builder.withDefaults());
for (Entity entity : results) {
String productID = (String) entity.getKey().getName();
String productName = (String) entity.getProperty("productName");
double currentPrice = (double) entity.getProperty("currentPrice");
double lowestPrice = (double) entity.getProperty("lowestPrice");
Date lowestDate = (Date) entity.getProperty("lowestDate");
list.add(new WishlistProduct(productID, productName, currentPrice,
lowestPrice, lowestDate));
}
return list;
}