我正在尝试通过 cookie 管理我的用户。这并不容易,因为绝对没有关于这个主题的文档。
在示例“zentask”的帮助下,我做了这个:
session("username", filledForm.field("username").value());
public class Secured{
public static Session getSession() {
return Context.current().session();
}
public static String getUsername() {
return getSession().get("username");
}
public static boolean isAuthorized() throws Exception {
String username = getUsername();
if (username == null)
return false;
long userCount = DatabaseConnect.getInstance().getDatastore()
.createQuery(User.class).field("username").equal(username)
.countAll();
if (userCount == 1)
return true;
return false;
}
我这样使用它:
public static Result blank() throws Exception {
if (Secured.isAuthorized())
return ok(Secured.getUsername());
else
return ok(views.html.login.form.render(loginForm));
}
现在我有几个问题/问题:
1.) Cookie 没有被删除,并且看起来总是一样的。例如 bdb7f592f9d54837995f816498c0474031d44c1a-username%3Akantaki
2.) Security.Authenticator 类做什么?
3.) 我认为通过 cookie 进行用户管理是一个很常见的问题,play!2.0 是否为我提供了完整的解决方案?或者至少有一些文件?