aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/web/client/controller/LoginController.java4
-rw-r--r--src/org/traccar/web/server/model/DataServiceImpl.java26
2 files changed, 24 insertions, 6 deletions
diff --git a/src/org/traccar/web/client/controller/LoginController.java b/src/org/traccar/web/client/controller/LoginController.java
index f8fdc8c2..1aa152b8 100644
--- a/src/org/traccar/web/client/controller/LoginController.java
+++ b/src/org/traccar/web/client/controller/LoginController.java
@@ -90,6 +90,10 @@ public class LoginController implements LoginDialog.LoginHandler {
loginHandler.onLogin();
}
}
+ @Override
+ public void onFailure(Throwable caught) {
+ new AlertMessageBox("Error", "Username is already taken").show();
+ }
});
}
}
diff --git a/src/org/traccar/web/server/model/DataServiceImpl.java b/src/org/traccar/web/server/model/DataServiceImpl.java
index 2d678b09..3ae4d21d 100644
--- a/src/org/traccar/web/server/model/DataServiceImpl.java
+++ b/src/org/traccar/web/server/model/DataServiceImpl.java
@@ -147,12 +147,26 @@ public class DataServiceImpl extends RemoteServiceServlet implements DataService
@Override
public User register(String login, String password) {
if (getApplicationSettings().getRegistrationEnabled()) {
- User user = new User();
- user.setLogin(login);
- user.setPassword(password);
- createUser(getSessionEntityManager(), user);
- setSessionUser(user);
- return user;
+ EntityManager entityManager = getSessionEntityManager();
+ synchronized (entityManager) {
+
+ 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()) {
+ User user = new User();
+ user.setLogin(login);
+ user.setPassword(password);
+ createUser(getSessionEntityManager(), user);
+ setSessionUser(user);
+ return user;
+ }
+ else
+ {
+ throw new IllegalStateException();
+ }
+ }
} else {
throw new SecurityException();
}