From 47cea42e319176aa69decc43e8d8074374ff0c4b Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 11 Jan 2013 19:48:19 +1300 Subject: Add logout button --- src/org/traccar/web/client/controller/LoginController.java | 2 +- src/org/traccar/web/client/model/DataService.java | 4 +++- src/org/traccar/web/client/model/DataServiceAsync.java | 6 ++++-- src/org/traccar/web/client/view/DeviceView.java | 13 +++++++++++++ src/org/traccar/web/client/view/DeviceView.ui.xml | 3 ++- src/org/traccar/web/client/view/MapView.java | 6 ------ src/org/traccar/web/server/model/DataServiceImpl.java | 14 ++++++++++++-- 7 files changed, 35 insertions(+), 13 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/web/client/controller/LoginController.java b/src/org/traccar/web/client/controller/LoginController.java index ceda85cf..6f3bc565 100644 --- a/src/org/traccar/web/client/controller/LoginController.java +++ b/src/org/traccar/web/client/controller/LoginController.java @@ -43,7 +43,7 @@ public class LoginController implements LoginDialog.LoginHandler { @Override public void onLogin(String login, String password) { if (validate(login, password)) { - Application.getDataService().authenticate(login, password, new BaseAsyncCallback() { + Application.getDataService().login(login, password, new BaseAsyncCallback() { @Override public void onSuccess(Boolean result) { if (result) { diff --git a/src/org/traccar/web/client/model/DataService.java b/src/org/traccar/web/client/model/DataService.java index d8d71520..d3a9ea73 100644 --- a/src/org/traccar/web/client/model/DataService.java +++ b/src/org/traccar/web/client/model/DataService.java @@ -14,7 +14,9 @@ public interface DataService extends RemoteService { boolean authenticated(); - boolean authenticate(String login, String password); + boolean login(String login, String password); + + boolean logout(); boolean register(String login, String password); diff --git a/src/org/traccar/web/client/model/DataServiceAsync.java b/src/org/traccar/web/client/model/DataServiceAsync.java index 357beb5d..51a419c6 100644 --- a/src/org/traccar/web/client/model/DataServiceAsync.java +++ b/src/org/traccar/web/client/model/DataServiceAsync.java @@ -10,10 +10,12 @@ import com.google.gwt.user.client.rpc.AsyncCallback; public interface DataServiceAsync { - void authenticate(String login, String password, AsyncCallback callback); - void authenticated(AsyncCallback callback); + void login(String login, String password, AsyncCallback callback); + + void logout(AsyncCallback callback); + void register(String login, String password, AsyncCallback callback); void getDevices(AsyncCallback> callback); diff --git a/src/org/traccar/web/client/view/DeviceView.java b/src/org/traccar/web/client/view/DeviceView.java index 1213e5f0..76c773db 100644 --- a/src/org/traccar/web/client/view/DeviceView.java +++ b/src/org/traccar/web/client/view/DeviceView.java @@ -3,6 +3,8 @@ package org.traccar.web.client.view; import java.util.LinkedList; import java.util.List; +import org.traccar.web.client.Application; +import org.traccar.web.client.model.BaseAsyncCallback; import org.traccar.web.client.model.DeviceProperties; import org.traccar.web.shared.model.Device; @@ -10,6 +12,7 @@ import com.google.gwt.core.client.GWT; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.uibinder.client.UiHandler; +import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.Widget; import com.sencha.gxt.core.client.Style.SelectionMode; import com.sencha.gxt.data.shared.ListStore; @@ -106,4 +109,14 @@ public class DeviceView implements SelectionChangedEvent.SelectionChangedHandler deviceHandler.onRemove(grid.getSelectionModel().getSelectedItem()); } + @UiHandler("logoutButton") + public void onLogoutClicked(SelectEvent event) { + Application.getDataService().logout(new BaseAsyncCallback() { + @Override + public void onSuccess(Boolean result) { + Window.Location.reload(); + } + }); + } + } diff --git a/src/org/traccar/web/client/view/DeviceView.ui.xml b/src/org/traccar/web/client/view/DeviceView.ui.xml index af1b33cd..77de651e 100644 --- a/src/org/traccar/web/client/view/DeviceView.ui.xml +++ b/src/org/traccar/web/client/view/DeviceView.ui.xml @@ -33,7 +33,8 @@ - + + diff --git a/src/org/traccar/web/client/view/MapView.java b/src/org/traccar/web/client/view/MapView.java index a7d1dad2..70558b6e 100644 --- a/src/org/traccar/web/client/view/MapView.java +++ b/src/org/traccar/web/client/view/MapView.java @@ -23,8 +23,6 @@ import com.google.gwt.event.logical.shared.ResizeHandler; import com.google.gwt.user.client.Command; import com.sencha.gxt.widget.core.client.ContentPanel; - - public class MapView { private ContentPanel contentPanel; @@ -68,8 +66,6 @@ public class MapView { MapOptions defaultMapOptions = new MapOptions(); defaultMapOptions.setNumZoomLevels(16); - defaultMapOptions.setProjection("EPSG:4326"); - defaultMapOptions.setDisplayProjection(new Projection("EPSG:4326")); mapWidget = new MapWidget("100%", "100%", defaultMapOptions); map = mapWidget.getMap(); @@ -78,11 +74,9 @@ public class MapView { mapLayer.setIsBaseLayer(true); VectorOptions vectorOptions = new VectorOptions(); - vectorOptions.setProjection("EPSG:4326"); vectorLayer = new Vector("Vector", vectorOptions); MarkersOptions markersOptions = new MarkersOptions(); - markersOptions.setProjection("EPSG:4326"); markerLayer = new Markers("Markers", markersOptions); map.addLayer(mapLayer); diff --git a/src/org/traccar/web/server/model/DataServiceImpl.java b/src/org/traccar/web/server/model/DataServiceImpl.java index 9c69b48e..01ab3164 100644 --- a/src/org/traccar/web/server/model/DataServiceImpl.java +++ b/src/org/traccar/web/server/model/DataServiceImpl.java @@ -55,7 +55,11 @@ public class DataServiceImpl extends RemoteServiceServlet implements DataService private void setUser(User user) { HttpSession session = getThreadLocalRequest().getSession(); - session.setAttribute(ATTRIBUTE_USER, user); + if (user != null) { + session.setAttribute(ATTRIBUTE_USER, user); + } else { + session.removeAttribute(ATTRIBUTE_USER); + } } private User getUser() { @@ -69,7 +73,7 @@ public class DataServiceImpl extends RemoteServiceServlet implements DataService } @Override - public boolean authenticate(String login, String password) { + public boolean login(String login, String password) { TypedQuery query = entityManager.createQuery( "SELECT x FROM User x WHERE x.login = :login", User.class); query.setParameter("login", login); @@ -82,6 +86,12 @@ public class DataServiceImpl extends RemoteServiceServlet implements DataService return false; } + @Override + public boolean logout() { + setUser(null); + return true; + } + @Override public boolean register(String login, String password) { User user = new User(); -- cgit v1.2.3