aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/web/server
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2014-03-22 17:36:50 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2014-03-22 17:36:50 +1300
commit33dbcf4d450e190228a3a0dffd611f142215380b (patch)
tree580980d5381fbfe77d66f5135a78efd90d249bb2 /src/org/traccar/web/server
parentd132abb4d0a4b55ab1894b72d69d7c31da41d1ee (diff)
parentf40f6e306d055ebc46b0e22c850a21f0cd0cfb6c (diff)
downloadtrackermap-web-33dbcf4d450e190228a3a0dffd611f142215380b.tar.gz
trackermap-web-33dbcf4d450e190228a3a0dffd611f142215380b.tar.bz2
trackermap-web-33dbcf4d450e190228a3a0dffd611f142215380b.zip
Merge pull request #146 from khfayzullaev/master
Don't register with an existing username
Diffstat (limited to 'src/org/traccar/web/server')
-rw-r--r--src/org/traccar/web/server/model/DataServiceImpl.java26
1 files changed, 20 insertions, 6 deletions
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();
}