From 61bd26d530710e74ef1c0dfd6920b9c1d27cfdd5 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 5 Jun 2015 19:18:58 +1200 Subject: Add user account dialog --- src/org/traccar/database/DataManager.java | 7 +++++++ src/org/traccar/http/MainServlet.java | 8 ++++++++ 2 files changed, 15 insertions(+) (limited to 'src/org') diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index e9647922c..6cfd84d41 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -228,6 +228,13 @@ public class DataManager { .setObject(user) .executeUpdate()); } + + public void updateUser(User user) throws SQLException { + QueryBuilder.create(dataSource, + "UPDATE user SET name = :name, email = :email, admin = :admin WHERE id = :id;") + .setObject(user) + .executeUpdate(); + } public Collection getPermissions() throws SQLException { return QueryBuilder.create(dataSource, diff --git a/src/org/traccar/http/MainServlet.java b/src/org/traccar/http/MainServlet.java index 18430f0c3..84ec25906 100644 --- a/src/org/traccar/http/MainServlet.java +++ b/src/org/traccar/http/MainServlet.java @@ -34,6 +34,8 @@ public class MainServlet extends BaseServlet { logout(req, resp); } else if (command.equals("/register")) { register(req, resp); + } else if (command.equals("/user/update")) { + update(req, resp); } else { return false; } @@ -70,5 +72,11 @@ public class MainServlet extends BaseServlet { Context.getDataManager().addUser(user); sendResponse(resp.getWriter(), true); } + + private void update(HttpServletRequest req, HttpServletResponse resp) throws Exception { + Context.getDataManager().updateUser(JsonConverter.objectFromJson( + req.getReader(), new User())); + sendResponse(resp.getWriter(), true); + } } -- cgit v1.2.3