本文整理汇总了Java中play.mvc.Http.Session方法的典型用法代码示例。如果您正苦于以下问题:Java Http.Session方法的具体用法?Java Http.Session怎么用?Java Http.Session使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类play.mvc.Http
的用法示例。
在下文中一共展示了Http.Session方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validate
import play.mvc.Http; //导入方法依赖的package包/类
public String validate() {
User user = UserUtil.authenticate(userDao.findUserByUsername(username), password);
if (user == null) {
return "Invalid username or password";
} else if (!user.isActive()) {
return "User account is currently inactive. An admin will activate your account shortly.";
} else {
Http.Session session = Http.Context.current().session();
session.clear();
session.put("uid", Long.toString(user.getId()));
session.put("user_role", user.getRoles().get(0).getName());
session.put("username", user.getUsername());
// TODO: token based auth and session timeout
}
return null;
}
示例2: isResponseSuccessful
import play.mvc.Http; //导入方法依赖的package包/类
private boolean isResponseSuccessful(Http.Session session, WSResponse wsResponse) {
if (wsResponse.getStatus() >= 400) {
if (wsResponse.getStatus() == 401) {
System.out.println("Invalid TOKEN redirecting to GitHub Auth");
session.remove(TOKEN_KEY);
}
return false;
}
return true;
}
示例3: saveSkuInSession
import play.mvc.Http; //导入方法依赖的package包/类
static void saveSkuInSession(final Http.Session session, final String sku) {
final List<String> skuList = findLastViewedProductsSkuInSession(session);
skuList.remove(sku);
skuList.add(sku);
while (skuList.size() > MAX_CAPACITY) {
skuList.remove(0);
}
try {
session.put(SESSION_KEY, Json.mapper().writeValueAsString(skuList));
LOGGER_SAVER.debug("Saved product with SKU {} to session: {}", sku, skuList);
} catch (JsonProcessingException e) {
LOGGER_SAVER.error("Could not serialize SKU list {} into JSON", skuList, e);
}
}
开发者ID:commercetools,项目名称:commercetools-sunrise-java-training,代码行数:15,代码来源:LastViewedProductUtils.java
示例4: findLastViewedProductsSkuInSession
import play.mvc.Http; //导入方法依赖的package包/类
static List<String> findLastViewedProductsSkuInSession(final Http.Session session) {
final List<String> skuList = new LinkedList<>();
Json.parse(session.getOrDefault(SESSION_KEY, "[]")).elements()
.forEachRemaining(node -> skuList.add(node.asText()));
return skuList;
}
开发者ID:commercetools,项目名称:commercetools-sunrise-java-training,代码行数:7,代码来源:LastViewedProductUtils.java