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