// Path: src/main/java/com/nuvola/myproject/client/NameTokens.java
// public class NameTokens {
//     public static final String HOME = "/home";
//     public static final String LOGIN = "/login";
// 
//     public static String getHome() {
//         return HOME;
//     }
// 
//     public static String getLogin() {
//         return LOGIN;
//     }
// }
// 
// Path: src/main/java/com/nuvola/myproject/client/login/LoginPresenter.java
// @NameToken(NameTokens.LOGIN)
// @ProxyStandard
// @NoGatekeeper
// interface MyProxy extends ProxyPlace<LoginPresenter> {
// }
// 
// Path: src/main/java/com/nuvola/myproject/client/login/LoginPresenter.java
// interface MyView extends View, HasUiHandlers<LoginUiHandlers> {
// }
// 
// Path: src/main/java/com/nuvola/myproject/client/services/UserService.java
// @Path(ROOT)
// public interface UserService {
//     @POST
//     @Path(LOGIN)
//     @Consumes(APPLICATION_FORM_URLENCODED)
//     RestAction<Void> login(@FormParam(USERNAME) String username, @FormParam(PASSWORD) String password);
// 
//     @DELETE
//     @Path(LOGIN)
//     RestAction<Void> logout();
// 
//     @GET
//     @Path(LOGIN)
//     RestAction<Boolean> isCurrentUserLoggedIn();
// 
//     @GET
//     RestAction<User> getCurrentUser();
// }
// 
// Path: src/main/java/com/nuvola/myproject/client/security/CurrentUser.java
// public class CurrentUser {
//     private boolean loggedIn;
// 
//     public boolean isLoggedIn() {
//         return loggedIn;
//     }
// 
//     public void setLoggedIn(boolean loggedIn) {
//         this.loggedIn = loggedIn;
//     }
// }


import javax.inject.Inject;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.web.bindery.event.shared.EventBus;
import com.gwtplatform.dispatch.rest.client.RestDispatch;
import com.gwtplatform.mvp.client.HasUiHandlers;
import com.gwtplatform.mvp.client.Presenter;
import com.gwtplatform.mvp.client.View;
import com.gwtplatform.mvp.client.annotations.NameToken;
import com.gwtplatform.mvp.client.annotations.NoGatekeeper;
import com.gwtplatform.mvp.client.annotations.ProxyStandard;
import com.gwtplatform.mvp.client.proxy.PlaceManager;
import com.gwtplatform.mvp.client.proxy.ProxyPlace;
import com.gwtplatform.mvp.shared.proxy.PlaceRequest;
import com.nuvola.myproject.client.NameTokens;
import com.nuvola.myproject.client.login.LoginPresenter.MyProxy;
import com.nuvola.myproject.client.login.LoginPresenter.MyView;
import com.nuvola.myproject.client.services.UserService;
import com.nuvola.myproject.client.security.CurrentUser;
                   MyView view,
                   MyProxy proxy,
                   PlaceManager placeManager,
                   RestDispatch dispatcher,
                   UserService userService,
                   CurrentUser currentUser) {
        super(eventBus, view, proxy, RevealType.Root);

        this.placeManager = placeManager;
        this.dispatcher = dispatcher;
        this.userService = userService;
        this.currentUser = currentUser;

        getView().setUiHandlers(this);
    }

    @Override
    public void login(String login, String password) {
        sendLoginRequest(login, password);
    }

    private void sendLoginRequest(String username, String password) {
        dispatcher.execute(userService.login(username, password), new AsyncCallback<Void>() {
            @Override
            public void onSuccess(Void result) {
                onLoginSuccess();
            }

            @Override
            public void onFailure(Throwable caught) {
// Path: src/main/java/com/nuvola/myproject/client/NameTokens.java
// public class NameTokens {
//     public static final String HOME = "/home";
//     public static final String LOGIN = "/login";
// 
//     public static String getHome() {
//         return HOME;
//     }
// 
//     public static String getLogin() {
//         return LOGIN;
//     }
// }
// 
// Path: src/main/java/com/nuvola/myproject/client/login/LoginPresenter.java
// @NameToken(NameTokens.LOGIN)
// @ProxyStandard
// @NoGatekeeper
// interface MyProxy extends ProxyPlace<LoginPresenter> {
// }
// 
// Path: src/main/java/com/nuvola/myproject/client/login/LoginPresenter.java
// interface MyView extends View, HasUiHandlers<LoginUiHandlers> {
// }
// 
// Path: src/main/java/com/nuvola/myproject/client/services/UserService.java
// @Path(ROOT)
// public interface UserService {
//     @POST
//     @Path(LOGIN)
//     @Consumes(APPLICATION_FORM_URLENCODED)
//     RestAction<Void> login(@FormParam(USERNAME) String username, @FormParam(PASSWORD) String password);
// 
//     @DELETE
//     @Path(LOGIN)
//     RestAction<Void> logout();
// 
//     @GET
//     @Path(LOGIN)
//     RestAction<Boolean> isCurrentUserLoggedIn();
// 
//     @GET
//     RestAction<User> getCurrentUser();
// }
// 
// Path: src/main/java/com/nuvola/myproject/client/security/CurrentUser.java
// public class CurrentUser {
//     private boolean loggedIn;
// 
//     public boolean isLoggedIn() {
//         return loggedIn;
//     }
// 
//     public void setLoggedIn(boolean loggedIn) {
//         this.loggedIn = loggedIn;
//     }
// }


// Path: src/main/java/com/nuvola/myproject/client/login/LoginPresenter.java
import javax.inject.Inject;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.web.bindery.event.shared.EventBus;
import com.gwtplatform.dispatch.rest.client.RestDispatch;
import com.gwtplatform.mvp.client.HasUiHandlers;
import com.gwtplatform.mvp.client.Presenter;
import com.gwtplatform.mvp.client.View;
import com.gwtplatform.mvp.client.annotations.NameToken;
import com.gwtplatform.mvp.client.annotations.NoGatekeeper;
import com.gwtplatform.mvp.client.annotations.ProxyStandard;
import com.gwtplatform.mvp.client.proxy.PlaceManager;
import com.gwtplatform.mvp.client.proxy.ProxyPlace;
import com.gwtplatform.mvp.shared.proxy.PlaceRequest;
import com.nuvola.myproject.client.NameTokens;
import com.nuvola.myproject.client.login.LoginPresenter.MyProxy;
import com.nuvola.myproject.client.login.LoginPresenter.MyView;
import com.nuvola.myproject.client.services.UserService;
import com.nuvola.myproject.client.security.CurrentUser;

                   MyView view,
                   MyProxy proxy,
                   PlaceManager placeManager,
                   RestDispatch dispatcher,
                   UserService userService,
                   CurrentUser currentUser) {
        super(eventBus, view, proxy, RevealType.Root);

        this.placeManager = placeManager;
        this.dispatcher = dispatcher;
        this.userService = userService;
        this.currentUser = currentUser;

        getView().setUiHandlers(this);
    }

    @Override
    public void login(String login, String password) {
        sendLoginRequest(login, password);
    }

    private void sendLoginRequest(String username, String password) {
        dispatcher.execute(userService.login(username, password), new AsyncCallback<Void>() {
            @Override
            public void onSuccess(Void result) {
                onLoginSuccess();
            }

            @Override
            public void onFailure(Throwable caught) {
                onLoginFailure();