本文整理匯總了Java中play.mvc.Http.Cookie方法的典型用法代碼示例。如果您正苦於以下問題:Java Http.Cookie方法的具體用法?Java Http.Cookie怎麽用?Java Http.Cookie使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類play.mvc.Http
的用法示例。
在下文中一共展示了Http.Cookie方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: login
import play.mvc.Http; //導入方法依賴的package包/類
public static void login() throws Throwable {
Http.Cookie remember = request.cookies.get("rememberme");
if(remember != null) {
int firstIndex = remember.value.indexOf("-");
int lastIndex = remember.value.lastIndexOf("-");
if (lastIndex > firstIndex) {
String sign = remember.value.substring(0, firstIndex);
String restOfCookie = remember.value.substring(firstIndex + 1);
String username = remember.value.substring(firstIndex + 1, lastIndex);
String time = remember.value.substring(lastIndex + 1);
Date expirationDate = new Date(Long.parseLong(time)); // surround with try/catch?
Date now = new Date();
if (expirationDate == null || expirationDate.before(now)) {
logout();
}
if(Crypto.sign(restOfCookie).equals(sign)) {
session.put("username", username);
redirectToOriginalURL();
}
}
}
flash.keep("url");
render();
}
示例2: call
import play.mvc.Http; //導入方法依賴的package包/類
@Override
public CompletionStage<Result> call(Http.Context ctx) {
Http.Cookie ltat = ctx.request().cookie("ltat");
boolean valid = configuration.optional();
if(ltat != null) {
User user = jwtUtils.validateCookie(ltat.value());
if(user != null) {
if (user.isDisabled()) {
flash("error", "Your account was disabled.");
Http.Cookie ltatRemove = Http.Cookie.builder("ltat", "")
.withPath("/").withHttpOnly(true).withMaxAge(Duration.ZERO).build();
return CompletableFuture.completedFuture(redirect(routes.LoginController.get(null)).withCookies(ltatRemove));
}
if(!configuration.requireAdmin() || user.isAdmin()){
ctx = ctx.withRequest(ctx.request().addAttr(AuthorizationServerSecure.USER, user));
valid = true;
} else {
return CompletableFuture.completedFuture(unauthorized(Json.newObject()
.put("message", "you are not authorized for this operation")
));
}
}
}
if(!valid) {
return CompletableFuture.completedFuture(redirect(routes.LoginController.get(ctx.request().uri())));
} else { // pass on
return delegate.call(ctx);
}
}
示例3: prepareCookieThenRedirect
import play.mvc.Http; //導入方法依賴的package包/類
public Result prepareCookieThenRedirect(User user, String next){
Http.Cookie ltat = prepareCookie(user);
if(next != null && next.matches("^/.*$"))
return redirect(next).withCookies(ltat);
else
return redirect(routes.ProfileController.get()).withCookies(ltat);
}
示例4: prepareCookie
import play.mvc.Http; //導入方法依賴的package包/類
private Http.Cookie prepareCookie(User user){
return Http.Cookie.builder("ltat", prepareCookieValue(user)).withPath("/").withHttpOnly(true).withMaxAge(expireCookie).withSecure(useSecureSessionCookie).build();
}
示例5: show4
import play.mvc.Http; //導入方法依賴的package包/類
public Result show4(final String name) {
final Http.Cookie nameCookie = request().cookie("name");
response().setCookie(Http.Cookie.builder("name", name).build());
return ok("Hello " + name + "! Bye " + (nameCookie != null ? nameCookie.value() : "stranger"));
}