开发者

GWTP Gatekeeper and the UserService

I am having a problem using the Gatekeeper feature of GWTP. Following the开发者_如何学Go example gwtp-sample-tab I have created the client code. But now I am still wondering how to notify the client side if the user has successfully logged in? (I am using the Google UserService.)

Could anybody please provide me a litte example?

Thank you very much!


Not sure if i correctly understand your question because GWTP gatekeppers exists just for security purposes(block admin pages from other users or something similar). Annotate presenters with @UseGatekeeper( LoggedInGatekeeper.class ) and gwtp will let it show only to registered users all others will be redirected to home/error page.

Anyway, if your site using GAE Users API(userservice) then users will have to go to google's sign-in page for authorization and then return back to your site. Your site's page will be completely refreshed, so using this technique and jsp you can save user's info straight into host jsp-page.

Then in main presenter onReset() method get those data using Dictionary class or JSNI and do something like this:

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 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜