From 40107a7886412c4582ea9a9ee946f454e28a1178 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 6 Jun 2015 18:40:54 +1200 Subject: Add users API servlet --- src/org/traccar/database/DataManager.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/org/traccar/database') diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index 54f1cdc3a..db863e8f4 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -221,10 +221,16 @@ public class DataManager { .executeQuerySingle(new User()); } + public Collection getUsers() throws SQLException { + return QueryBuilder.create(dataSource, + "SELECT * FROM user;") + .executeQuery(new User()); + } + public void addUser(User user) throws SQLException { user.setId(QueryBuilder.create(dataSource, - "INSERT INTO user (name, email, password, salt, admin) " + - "VALUES (:name, :email, CAST(HASH('SHA256', STRINGTOUTF8(:password), 1000) AS VARCHAR), '', :admin);") + "INSERT INTO user (name, email, password, admin) " + + "VALUES (:name, :email, CAST(HASH('SHA256', STRINGTOUTF8(:password), 1000) AS VARCHAR), :admin);") .setObject(user) .executeUpdate()); } @@ -236,6 +242,13 @@ public class DataManager { .setObject(user) .executeUpdate(); } + + public void removeUser(User user) throws SQLException { + QueryBuilder.create(dataSource, + "DELETE FROM user WHERE id = :id;") + .setObject(user) + .executeUpdate(); + } public Collection getPermissions() throws SQLException { return QueryBuilder.create(dataSource, -- cgit v1.2.3