【问题标题】:GWTP Gatekeeper and the UserServiceGWTP 网守和用户服务
【发布时间】:2024-01-16 11:58:01
【问题描述】:

我在使用 GWTP 的 Gatekeeper 功能时遇到问题。 按照示例gwtp-sample-tab,我创建了客户端代码。但是现在我仍然想知道如果用户成功登录,如何通知客户端? (我正在使用 Google UserService。)

谁能给我一个小例子?

非常感谢!

【问题讨论】:

    标签: gwt gwt-platform


    【解决方案1】:

    不确定我是否正确理解了您的问题,因为 GWTP 网关守卫只是出于安全目的而存在(阻止其他用户的管理页面或类似的东西)。使用@UseGatekeeper( LoggedInGatekeeper.class ) 注释演示者,gwtp 将让它只显示给注册用户,所有其他人将被重定向到主页/错误页面。

    无论如何,如果您的网站使用 GAE 用户 API(userservice),那么用户必须前往 google 的登录页面进行授权,然后返回您的网站。您的站点页面将完全刷新,因此使用this technique and jsp 您可以将用户信息直接保存到主机 jsp 页面中。

    然后在主演示者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 
    

    【讨论】:

    最近更新 更多