Package welcome.client.ui.auth

Source Code of welcome.client.ui.auth.AuthForm

package welcome.client.ui.auth;

import welcome.client.LoginService;
import welcome.client.LoginServiceAsync;
import welcome.client.ui.Content;
import welcome.client.ui.ContentContainer;
import welcome.shared.login.LoginInfo;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.CaptionPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Grid;

public class AuthForm extends Content {

  private Anchor logHyperlink = new Anchor();

//  private LoginInfo loginInfo = null;
  private CaptionPanel userPanel;
  private Grid grid;
  private Label statusLabel;
//  private Hyperlink logHyperlink;

  public AuthForm() {
   
    this.userPanel = new CaptionPanel("User Info");
    initWidget(this.userPanel);
    this.userPanel.setSize("188px", "59px");
   
    this.grid = new Grid(1, 2);
    this.userPanel.setContentWidget(this.grid);
    this.grid.setSize("100%", "100%");
   
    this.statusLabel = new Label();
    this.grid.setWidget(0, 0, this.statusLabel);
   
    this.grid.setWidget(0, 1, this.logHyperlink);

    // Check login status using login service.
    LoginServiceAsync loginService = GWT.create(LoginService.class);
    loginService.login(GWT.getHostPageBaseURL(), new AsyncCallback<LoginInfo>() {
      public void onFailure(Throwable caught) {
        Window.alert(caught.getMessage());
      }

      public void onSuccess(LoginInfo result) {
        ContentContainer.setUser(result);
        if (ContentContainer.getUser().isLoggedIn()) {
         
          statusLabel.setText("Welcome " + result.getNickname());
          logHyperlink.setHref(result.getLogoutUrl());
          logHyperlink.setHTML("Log-out");
        } else {
          statusLabel.setText("You're off line");
          logHyperlink.setHref(result.getLoginUrl());
          logHyperlink.setHTML("Log-in");
        }
      }
    });

  }

}
TOP

Related Classes of welcome.client.ui.auth.AuthForm

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.