aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/web/server
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2013-02-20 22:35:43 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2013-02-20 22:35:43 +1300
commit6801698dfc9c99b34d7ed081ebcfbec4a8853868 (patch)
treececc80f811b6c3a594b9da272a7c65d3a9695315 /src/org/traccar/web/server
parent0e766c9024e2457320f64353e29bb5e2d8294b28 (diff)
downloadtrackermap-web-6801698dfc9c99b34d7ed081ebcfbec4a8853868.tar.gz
trackermap-web-6801698dfc9c99b34d7ed081ebcfbec4a8853868.tar.bz2
trackermap-web-6801698dfc9c99b34d7ed081ebcfbec4a8853868.zip
Added account dialog
Diffstat (limited to 'src/org/traccar/web/server')
-rw-r--r--src/org/traccar/web/server/model/DataServiceImpl.java47
1 files changed, 41 insertions, 6 deletions
diff --git a/src/org/traccar/web/server/model/DataServiceImpl.java b/src/org/traccar/web/server/model/DataServiceImpl.java
index 28c61678..1f6ff608 100644
--- a/src/org/traccar/web/server/model/DataServiceImpl.java
+++ b/src/org/traccar/web/server/model/DataServiceImpl.java
@@ -107,7 +107,7 @@ public class DataServiceImpl extends RemoteServiceServlet implements DataService
}
@Override
- public boolean login(String login, String password) {
+ public User login(String login, String password) {
EntityManager entityManager = entityManagerFactory.createEntityManager();
try {
TypedQuery<User> query = entityManager.createQuery(
@@ -116,10 +116,11 @@ public class DataServiceImpl extends RemoteServiceServlet implements DataService
List<User> results = query.getResultList();
if (!results.isEmpty() && password.equals(results.get(0).getPassword())) {
- setUser(results.get(0));
- return true;
+ User user = results.get(0);
+ setUser(user);
+ return user;
}
- return false;
+ return null;
} finally {
entityManager.close();
}
@@ -132,14 +133,48 @@ public class DataServiceImpl extends RemoteServiceServlet implements DataService
}
@Override
- public boolean register(String login, String password) {
+ public User register(String login, String password) {
if (getApplicationSettings().getRegistrationEnabled()) {
User user = new User();
user.setLogin(login);
user.setPassword(password);
createUser(user);
setUser(user);
- return true;
+ return user;
+ } else {
+ throw new SecurityException();
+ }
+ }
+
+ @Override
+ public User updateUser(User user) {
+ User currentUser = getUser();
+ if (currentUser.getAdmin() || (currentUser.getId() == user.getId() && !user.getAdmin())) {
+ EntityManager entityManager = entityManagerFactory.createEntityManager();
+ try {
+ // TODO: better solution?
+ if (currentUser.getId() == user.getId()) {
+ currentUser.setLogin(user.getLogin());
+ currentUser.setPassword(user.getPassword());
+ currentUser.setUserSettings(user.getUserSettings());
+ user = currentUser;
+ } else {
+ // TODO: handle other users
+ }
+
+ entityManager.getTransaction().begin();
+ try {
+ entityManager.merge(user);
+ entityManager.getTransaction().commit();
+ setUser(user);
+ return user;
+ } catch (RuntimeException e) {
+ entityManager.getTransaction().rollback();
+ throw e;
+ }
+ } finally {
+ entityManager.close();
+ }
} else {
throw new SecurityException();
}