diff options
author | Khurshid Fayzullaev <khurshidfayzullaev@yahoo.com> | 2014-03-20 14:59:25 -0400 |
---|---|---|
committer | Khurshid Fayzullaev <khurshidfayzullaev@yahoo.com> | 2014-03-20 14:59:25 -0400 |
commit | 4ed5277c256c3e1391e70d74b83c53aa05124ec1 (patch) | |
tree | af267fd248bef828c79f5d27a4885de7acb6853b /src/org | |
parent | d132abb4d0a4b55ab1894b72d69d7c31da41d1ee (diff) | |
download | trackermap-web-4ed5277c256c3e1391e70d74b83c53aa05124ec1.tar.gz trackermap-web-4ed5277c256c3e1391e70d74b83c53aa05124ec1.tar.bz2 trackermap-web-4ed5277c256c3e1391e70d74b83c53aa05124ec1.zip |
Don't register with an existing username
Register method has been modified. A new user cannot register with an existing username.
Diffstat (limited to 'src/org')
-rw-r--r-- | src/org/traccar/web/server/model/DataServiceImpl.java | 26 |
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..e1f4748b 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(); } |