diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2014-03-22 17:36:50 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2014-03-22 17:36:50 +1300 |
commit | 33dbcf4d450e190228a3a0dffd611f142215380b (patch) | |
tree | 580980d5381fbfe77d66f5135a78efd90d249bb2 /src | |
parent | d132abb4d0a4b55ab1894b72d69d7c31da41d1ee (diff) | |
parent | f40f6e306d055ebc46b0e22c850a21f0cd0cfb6c (diff) | |
download | trackermap-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')
-rw-r--r-- | src/org/traccar/web/client/controller/LoginController.java | 4 | ||||
-rw-r--r-- | src/org/traccar/web/server/model/DataServiceImpl.java | 26 |
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(); } |