Example usage for com.google.gwt.accounts.client User login

List of usage examples for com.google.gwt.accounts.client User login

Introduction

In this page you can find the example usage for com.google.gwt.accounts.client User login.

Prototype

public static final native String login(String scope) ;

Source Link

Document

Retrieves a valid authentication token.

Usage

From source file:com.google.gwt.gdata.sample.hellogdata.client.AccountsAuthSubAuthenticationDemo.java

License:Apache License

/**
 * Display the AuthSub authentication statuses in a
 * tabular fashion with the help of a GWT FlexTable widget.
 * We initialize an array containing the name, scope, icon
 * and url for each of the supported GData systems.
 * For each system a table row is added displaying the name,
 * page, link and icon, in addition to the AuthSub status
 * and a hyperlink for logging in or logging, as appropriate.
 * The User class contains the getStatus method which is used
 * to retrieve the authentication status for the current user
 * and for a given system (scope).//from w ww.  j  a v  a 2 s .c o  m
 */
private void showAuthSubStatus() {
    String[][] systems = new String[][] {
            new String[] { "Google Analytics", "https://www.google.com/analytics/feeds/", "gdata-analytics.png",
                    "http://code.google.com/apis/analytics/" },
            new String[] { "Google Base", "http://www.google.com/base/feeds/", "gdata-base.png",
                    "http://code.google.com/apis/base/" },
            new String[] { "Google Blogger", "http://www.blogger.com/feeds/", "gdata-blogger.png",
                    "http://code.google.com/apis/blogger/" },
            new String[] { "Google Calendar", "http://www.google.com/calendar/feeds/", "gdata-calendar.png",
                    "http://code.google.com/apis/calendar/" },
            new String[] { "Google Contacts", "http://www.google.com/m8/feeds/", "gdata-contacts.png",
                    "http://code.google.com/apis/contacts/" },
            new String[] { "Google Finance", "http://finance.google.com/finance/feeds/", "gdata-finance.png",
                    "http://code.google.com/apis/finance/" },
            new String[] { "Google Maps", "http://maps.google.com/maps/feeds/", "gdata-maps.png",
                    "http://code.google.com/apis/maps/documentation/mapsdata/" },
            new String[] { "Google Sidewiki", "http://www.google.com/sidewiki/feeds/", "gdata-sidewiki.png",
                    "http://code.google.com/apis/sidewiki/" } };
    for (int i = 0; i < systems.length; i++) {
        String[] sys = systems[i];
        final String scope = sys[1];
        mainPanel.insertRow(i);
        mainPanel.addCell(i);
        mainPanel.addCell(i);
        mainPanel.addCell(i);
        mainPanel.addCell(i);
        Image icon = new Image(sys[2]);
        mainPanel.setWidget(i, 0, icon);
        Label name = new HTML("<a href=\"" + sys[3] + "\">" + sys[0] + "</a>");
        mainPanel.setWidget(i, 1, name);
        Label statusLabel = new Label();
        Anchor actionLink = new Anchor();
        AuthSubStatus status = User.getStatus(scope);
        if (status == AuthSubStatus.LOGGED_IN) {
            statusLabel.setText("Logged in");
            actionLink.setText("Log out");
            actionLink.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                    User.logout(scope);
                    refreshDemo();
                }
            });
        } else if (status == AuthSubStatus.LOGGED_OUT) {
            statusLabel.setText("Logged out");
            actionLink.setText("Log in");
            actionLink.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                    User.login(scope);
                }
            });
        }
        mainPanel.setWidget(i, 2, statusLabel);
        mainPanel.setWidget(i, 3, actionLink);
    }
}