aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/web/client/controller/SettingsController.java5
-rw-r--r--src/org/traccar/web/server/model/DataServiceImpl.java18
2 files changed, 20 insertions, 3 deletions
diff --git a/src/org/traccar/web/client/controller/SettingsController.java b/src/org/traccar/web/client/controller/SettingsController.java
index f8fcc72d..44d48f3d 100644
--- a/src/org/traccar/web/client/controller/SettingsController.java
+++ b/src/org/traccar/web/client/controller/SettingsController.java
@@ -33,6 +33,7 @@ import org.traccar.web.shared.model.UserSettings;
import com.google.gwt.core.client.GWT;
import com.sencha.gxt.data.shared.ListStore;
import com.sencha.gxt.widget.core.client.Dialog.PredefinedButton;
+import com.sencha.gxt.widget.core.client.box.AlertMessageBox;
import com.sencha.gxt.widget.core.client.box.ConfirmMessageBox;
import com.sencha.gxt.widget.core.client.event.HideEvent;
@@ -97,6 +98,10 @@ public class SettingsController implements DeviceView.SettingsHandler {
public void onSuccess(User result) {
userStore.add(result);
}
+ @Override
+ public void onFailure(Throwable caught) {
+ new AlertMessageBox("Error", "Username is already taken").show();
+ }
});
}
}).show();
diff --git a/src/org/traccar/web/server/model/DataServiceImpl.java b/src/org/traccar/web/server/model/DataServiceImpl.java
index 3ae4d21d..509bca4a 100644
--- a/src/org/traccar/web/server/model/DataServiceImpl.java
+++ b/src/org/traccar/web/server/model/DataServiceImpl.java
@@ -193,9 +193,21 @@ public class DataServiceImpl extends RemoteServiceServlet implements DataService
synchronized (entityManager) {
entityManager.getTransaction().begin();
try {
- entityManager.persist(user);
- entityManager.getTransaction().commit();
- return user;
+ String login = user.getLogin();
+ TypedQuery<User> query = entityManager.createQuery(
+ "SELECT x FROM User x WHERE x.login = :login", User.class);
+ query.setParameter("login", login);
+ List<User> results = query.getResultList();
+
+ if (results.isEmpty()) {
+ entityManager.persist(user);
+ entityManager.getTransaction().commit();
+ return user;
+ }
+ else
+ {
+ throw new IllegalStateException();
+ }
} catch (RuntimeException e) {
entityManager.getTransaction().rollback();
throw e;