我在使用GWTP的Gatekeeper功能时遇到问题。按照示例gwtp-sample-tab,我已经创建了客户端代码。但是现在我还在想,如果用户成功登录了,该如何通知客户端?(我正在使用谷歌的UserService。)
有人能给我举个小例子吗?
非常感谢!
发布于 2011-06-05 04:49:48
我不确定我是否正确理解了您的问题,因为GWTP gatekeppers的存在只是出于安全目的(阻止来自其他用户或类似用户的管理页面)。使用@UseGatekeeper( LoggedInGatekeeper.class )和gwtp的Annotate将只向注册用户显示,所有其他用户将被重定向到主页/错误页面。
无论如何,如果您的站点使用GAE用户API(userservice),那么用户必须转到google的登录页面进行授权,然后返回到您的站点。您的站点页面将完全刷新,因此您可以使用this technique and jsp将用户信息直接保存到主机jsp-page中。
然后,在主presenter onReset()方法中,使用Dictionary类或JSNI获取这些数据,并执行以下操作:
email = JSNIUtils.getEmail();
// or
// Dictionary info = Dictionary.getDictionary("info");
// String email = info.get("email");
loginUrl = JSNIUtils.getLogInUrl();
logoutUrl = JSNIUtils.getLogOutUrl();
if (email != null && logoutUrl != null) {
// user logged in -> show his email & log out link
getView().getUserNameAnchor().setText(email);
getView().getLogInOutAnchor().setText("Log out");
getView().getLogInOutAnchor().setHref(logoutUrl);
} else if (loginUrl != null) {
// unknown user -> show welcome & log in link
getView().getUserNameAnchor().setText("Hello Stranger");
getView().getLogInOutAnchor().setText("Log in");
getView().getLogInOutAnchor().setHref(loginUrl);
} // something else https://stackoverflow.com/questions/6173347
复制相似问题