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


Java UserService.isUserLoggedIn方法代碼示例

本文整理匯總了Java中com.google.appengine.api.users.UserService.isUserLoggedIn方法的典型用法代碼示例。如果您正苦於以下問題:Java UserService.isUserLoggedIn方法的具體用法?Java UserService.isUserLoggedIn怎麽用?Java UserService.isUserLoggedIn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.appengine.api.users.UserService的用法示例。


在下文中一共展示了UserService.isUserLoggedIn方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doFilter

import com.google.appengine.api.users.UserService; //導入方法依賴的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");
  }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:getting-started-java,代碼行數:17,代碼來源:LogoutFilter.java

示例2: doGet

import com.google.appengine.api.users.UserService; //導入方法依賴的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";
    }

    logger.log(Level.INFO, "logging destination " + destination);
    resp.sendRedirect(destination);
  } else {
    resp.sendRedirect(userService.createLoginURL("/login"));
    logger.log(Level.INFO, "logging destination /login");
  }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:getting-started-java,代碼行數:24,代碼來源:LoginServlet.java

示例3: doFilter

import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
@Override
public void doFilter(ServletRequest servletReq, ServletResponse servletResp, FilterChain chain)
    throws IOException, ServletException {
  HttpServletRequest req = (HttpServletRequest) servletReq;
  HttpServletResponse resp = (HttpServletResponse) servletResp;

  // [START logStuff]
  String instanceId = System.getenv().containsKey("GAE_MODULE_INSTANCE")
      ? System.getenv("GAE_MODULE_INSTANCE") : "-1";
  logger.log(
      Level.INFO,
      "ListByUserFilter processing new request for path: " + req.getRequestURI()
      + " and instance: " + instanceId);
  // [END logStuff]

  UserService userService = UserServiceFactory.getUserService();
  if (userService.isUserLoggedIn()) {
    chain.doFilter(servletReq, servletResp);
  } else {
    logger.log(Level.INFO, "Not logged in, setting loginDestination to /books/mine");
    req.getSession().setAttribute("loginDestination", "/books/mine");
    resp.sendRedirect(userService.createLoginURL("/login"));
  }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:getting-started-java,代碼行數:25,代碼來源:ListByUserFilter.java

示例4: doGet

import com.google.appengine.api.users.UserService; //導入方法依賴的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"));
  }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:getting-started-java,代碼行數:22,代碼來源:LoginServlet.java

示例5: PackageVersion

import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
/**
 * tags = "not-reviewed"
 *
 * @param package_ full internal package name
 * @param version version number
 */
public PackageVersion(String package_, String version) {
    this.name = package_ + "@" + version;
    this.package_ = package_;
    this.version = version;
    UserService us = UserServiceFactory.getUserService();
    if (us.isUserLoggedIn()) {
        this.lastModifiedBy = us.getCurrentUser();
    } else {
        this.lastModifiedBy =
                new User(NWUtils.THE_EMAIL, "gmail.com");
    }
    this.createdBy = this.lastModifiedBy;
    tags = new ArrayList<String>();
    tags.add("not-reviewed");

    this.detectPackageNames = new ArrayList<>();
    this.detectPackageVersions = new ArrayList<>();
}
 
開發者ID:tim-lebedkov,項目名稱:npackd-gae-web,代碼行數:25,代碼來源:PackageVersion.java

示例6: getUser

import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
public JPAUser getUser(HttpServletRequest req,HttpServletResponse resp) throws LogicException {
	//for Google App Engines
	UserService userService = UserServiceFactory.getUserService();
	if (userService.isUserLoggedIn()) {
		User usr = userService.getCurrentUser();
		PersistenceManager em = getPM(req);
		JPAUser user = DAO.getUsersDAO().findOrCreateUser(em, usr);
		if (user != null && user.isLocked()) {
			//this book is locked
			throw new LogicException(getAppConstants(req,resp).serverAccountLocked());
		}
		return user;
		} else {
			throw new LogicException(getAppConstants(req,resp).serverNotLoggedIn());
		}
}
 
開發者ID:Antokolos,項目名稱:iambookmaster,代碼行數:17,代碼來源:AbstractServlet.java

示例7: 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");
	}
	try {
		PersistenceManager em = getPM();
		JPAUser user = DAO.getUsersDAO().findOrCreateUser(em, userService.getCurrentUser());
		//store results
		setObjectByName(user);
		return SKIP_BODY;
	} catch (Exception e) {
		e.printStackTrace();
		throw new JspException(e);
	}
}
 
開發者ID:Antokolos,項目名稱:iambookmaster,代碼行數:17,代碼來源:CurrentUserTag.java

示例8: 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

示例9: doFilter

import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
    FilterChain filterChain) throws IOException, ServletException {
  UserService userService = UserServiceFactory.getUserService();
  HttpServletRequest request = (HttpServletRequest) servletRequest;
  HttpServletResponse response = (HttpServletResponse) servletResponse;

  if (!userService.isUserLoggedIn()) {
    String redirectUrl = request.getHeader(GaeHelper.REDIRECT_URL_HTTP_HEADER_NAME);
    if (redirectUrl == null || redirectUrl.length() == 0) {
      // Default to the root page if the redirecturl isn't specified in the request.
      redirectUrl = "/";
    }
    response.setHeader("login", userService.createLoginURL(redirectUrl));
    response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
    return;
  }

  filterChain.doFilter(request, response);
}
 
開發者ID:Peergos,項目名稱:Peergos,代碼行數:21,代碼來源:GaeAuthFilter.java

示例10: sendError

import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
private void sendError(HttpServletRequest req, HttpServletResponse response, Level logLevel,
  int errorCode, String publicMessage, Throwable t) throws IOException {
  boolean isOverQuota = isOverQuota(t);
  log.log(logLevel,
      t.getClass().getSimpleName() + "; overQuota=" + isOverQuota
          + "; sending " + errorCode + ": " + publicMessage,
      t);
  try {
    log.info("Trust status: " + trusted.get());
    boolean isTrusted = trusted.get() == UserTrustStatus.TRUSTED
        && req.getParameter("simulateUntrusted") == null;
    response.setStatus(errorCode);
    UserService service = userService.get();
    String userEmail = service.isUserLoggedIn()
        ? service.getCurrentUser().getEmail() : "(not logged in)";
    pageSkinWriter.get().write("Error " + errorCode, userEmail,
        ErrorPage.getGxpClosure(userEmail, "" + errorCode, isOverQuota, isTrusted, publicMessage,
            renderInternalMessage(Throwables.getStackTraceAsString(t))));
    log.info("Successfully sent GXP error page");
  } catch (RuntimeException e) {
    // This can happen if the uncaught exception t occurred after the servlet
    // had already called response.setContentType().  In that case, jetty
    // throws an IllegalStateException("STREAM") when we call
    // response.getWriter() above.
    log.log(Level.SEVERE, "RuntimeException trying to serve error page", e);
    // Try a more primitive mechanism.
    response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
        "An error occurred while reporting an error, see logs.  Original error:  "
        + errorCode + " " + publicMessage);
    log.info("Successfully sent primitive error page");
  }
}
 
開發者ID:ArloJamesBarnes,項目名稱:walkaround,代碼行數:33,代碼來源:ServerExceptionFilter.java

示例11: doFilter

import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
@Override
public void doFilter(ServletRequest servletReq, ServletResponse servletResp, FilterChain chain)
    throws IOException, ServletException {
  HttpServletRequest req = (HttpServletRequest) servletReq;
  HttpServletResponse resp = (HttpServletResponse) servletResp;

  UserService userService = UserServiceFactory.getUserService();
  if (userService.isUserLoggedIn()) {
    chain.doFilter(servletReq, servletResp);
  } else {
    req.getSession().setAttribute("loginDestination", "/books/mine");
    resp.sendRedirect(userService.createLoginURL("/login"));
  }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:getting-started-java,代碼行數:15,代碼來源:ListByUserFilter.java

示例12: Package

import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
/**
 * @param name full internal name of the package
 */
public Package(String name) {
    final UserService us = UserServiceFactory.getUserService();
    if (us.isUserLoggedIn()) {
        this.lastModifiedBy = us.getCurrentUser();
    } else {
        this.lastModifiedBy =
                new User(NWUtils.THE_EMAIL, "gmail.com");
    }

    createdBy = lastModifiedBy;
    this.name = name;
    this.permissions.add(createdBy);
}
 
開發者ID:tim-lebedkov,項目名稱:npackd-gae-web,代碼行數:17,代碼來源:Package.java

示例13: PackageVersionPage

import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
/**
 * -
 */
public PackageVersionPage() {
    this.packageName = "";
    this.version = "";
    this.url = "";
    this.sha = "";
    this.dependencyPackages = new ArrayList<String>();
    this.dependencyVersionRanges = new ArrayList<String>();
    this.dependencyEnvVars = new ArrayList<String>();
    this.oneFile = false;
    this.tags = new ArrayList<String>();
    this.tags.add("not-reviewed");
    this.importantFilePaths = new ArrayList<String>();
    this.importantFileTitles = new ArrayList<String>();
    this.cmdFilePaths = new ArrayList<String>();
    this.filePaths = new ArrayList<String>();
    this.fileContents = new ArrayList<String>();
    this.lastModifiedAt = null;

    UserService us = UserServiceFactory.getUserService();
    if (us.isUserLoggedIn()) {
        this.lastModifiedBy = us.getCurrentUser();
    } else {
        this.lastModifiedBy =
                new User(NWUtils.THE_EMAIL, "gmail.com");
    }
    this.createdBy = this.lastModifiedBy;
}
 
開發者ID:tim-lebedkov,項目名稱:npackd-gae-web,代碼行數:31,代碼來源:PackageVersionPage.java

示例14: printGaeProperties

import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
private void printGaeProperties(StringBuilder sb)
{
	sb.append("<h2>GAE Properties</h2>");
	Environment env = ApiProxy.getCurrentEnvironment();
	Iterator<Entry<String, Object>> iter = env.getAttributes().entrySet().iterator();
	sb.append("<table><tr><th>Name</th><th>Value</th></tr>");
	sb.append("<tr><td>").append("getAppId()").append("</td><td>").append(env.getAppId()).append("</td></tr>");
	sb.append("<tr><td>").append("getVersionId()").append("</td><td>").append(env.getVersionId()).append("</td></tr>");
	sb.append("<tr><td>").append("getModuleId()").append("</td><td>").append(env.getModuleId()).append("</td></tr>");
	sb.append("<tr><td>").append("getAuthDomain()").append("</td><td>").append(env.getAuthDomain()).append("</td></tr>");
	sb.append("<tr><td>").append("getEmail()").append("</td><td>").append(env.getEmail()).append("</td></tr>");

	UserService userService = UserServiceFactory.getUserService();
	boolean userLoggedIn = userService.isUserLoggedIn();
	sb.append("<tr><td>").append("isUserLoggedIn()").append("</td><td>").append(userLoggedIn).append("</td></tr>");
	if (userLoggedIn)
	{
		String logoutUrl = "Click <a href=\"" + userService.createLogoutURL(request.getRequestURI()) + "\">here</a> to Logout";
		sb.append("<tr><td>").append("createLogoutURL()").append("</td><td>").append(logoutUrl).append("</td></tr>");
	}
	else
	{
		String loginUrl = "Click <a href=\"" + userService.createLoginURL(request.getRequestURI()) + "\">here</a> to Login";
		sb.append("<tr><td>").append("createLoginURL()").append("</td><td>").append(loginUrl).append("</td></tr>");
	}

	while (iter.hasNext())
	{
		Entry<String, Object> entry = iter.next();
		String paramName = entry.getKey();
		String paramValue = entry.getValue().toString();
		sb.append("<tr><td>").append(paramName).append("</td><td>").append(paramValue).append("</td></tr>");
	}
	sb.append("</table>");
}
 
開發者ID:zach-m,項目名稱:gae-jersey-guice-jsf,代碼行數:36,代碼來源:InfoAPI.java

示例15: admin

import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
protected boolean admin() {
	Boolean status = (Boolean)pageContext.getAttribute(STATUS);
	if (status == null) {
		//no status - define it
		UserService userService = UserServiceFactory.getUserService();
		status = userService.isUserLoggedIn() && userService.isUserAdmin();
		pageContext.setAttribute(STATUS, status);
	}
	return status.booleanValue();
}
 
開發者ID:Antokolos,項目名稱:iambookmaster,代碼行數:11,代碼來源:UserIsNotAdminTag.java


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