diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-05-10 18:11:40 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-05-10 18:11:40 +1200 |
commit | bd09a39f12c4471bdc342e5a16fbabdffdc645d1 (patch) | |
tree | db94476ee604c2026c5653975c526352093d5628 /src/org/traccar/database | |
parent | 953852e6e984f8a639cf1a5ac4116fff755d538a (diff) | |
download | trackermap-server-bd09a39f12c4471bdc342e5a16fbabdffdc645d1.tar.gz trackermap-server-bd09a39f12c4471bdc342e5a16fbabdffdc645d1.tar.bz2 trackermap-server-bd09a39f12c4471bdc342e5a16fbabdffdc645d1.zip |
Refactor web app architecture
Diffstat (limited to 'src/org/traccar/database')
-rw-r--r-- | src/org/traccar/database/DataManager.java | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index 3a34be2d7..5e921c0ea 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -22,7 +22,6 @@ import java.net.URLClassLoader; import java.sql.Connection; import java.sql.Driver; import java.sql.DriverManager; -import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; @@ -307,28 +306,27 @@ public class DataManager { admin.setName("admin"); admin.setEmail("admin"); admin.setPassword("admin"); + admin.setAdmin(true); addUser(admin); + + Device device = new Device(); + device.setName("test1"); + device.setUniqueId("123456789012345"); + addDevice(device); + linkDevice(admin.getId(), device.getId()); } - public long login(String email, String password) throws SQLException { - - Connection connection = dataSource.getConnection(); - try { - PreparedStatement statement = connection.prepareStatement( - "SELECT id FROM user WHERE email = ? AND " + - "password = CAST(HASH('SHA256', STRINGTOUTF8(?), 1000) AS VARCHAR);"); - try { - statement.setString(1, email); - statement.setString(2, password); - - ResultSet result = statement.executeQuery(); - result.next(); - return result.getLong("id"); - } finally { - statement.close(); - } - } finally { - connection.close(); + public User login(String email, String password) throws SQLException { + Collection<User> result = QueryBuilder.create(dataSource, + "SELECT * FROM user WHERE email = :email AND " + + "password = CAST(HASH('SHA256', STRINGTOUTF8(:password), 1000) AS VARCHAR);") + .setString("email", email) + .setString("password", password) + .executeQuery(new User()); + if (!result.isEmpty()) { + return result.iterator().next(); + } else { + return null; } } |