aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-05-06 22:23:26 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-05-06 22:23:26 +1200
commit80e166430b79df771abc73e55892dc9f5fd0b2f1 (patch)
tree72c8849812ec43bd97f6f8bf65d6e700d5bdf7df /src/org/traccar/database
parentb9d6befdbcc1a56c87d14066d67da574762d81bc (diff)
downloadtrackermap-server-80e166430b79df771abc73e55892dc9f5fd0b2f1.tar.gz
trackermap-server-80e166430b79df771abc73e55892dc9f5fd0b2f1.tar.bz2
trackermap-server-80e166430b79df771abc73e55892dc9f5fd0b2f1.zip
Add new user registration
Diffstat (limited to 'src/org/traccar/database')
-rw-r--r--src/org/traccar/database/DataManager.java34
1 files changed, 13 insertions, 21 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index c62c7d7e6..2aca1ff87 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -37,8 +37,8 @@ import javax.sql.DataSource;
import org.traccar.helper.DriverDelegate;
import org.traccar.model.Device;
import org.traccar.model.Permission;
-import org.traccar.model.Event;
import org.traccar.model.Position;
+import org.traccar.model.User;
public class DataManager {
@@ -222,6 +222,7 @@ public class DataManager {
QueryBuilder.create(dataSource,
"CREATE TABLE user (" +
"id INT PRIMARY KEY AUTO_INCREMENT," +
+ "name VARCHAR(1024) NOT NULL," +
"email VARCHAR(1024) NOT NULL UNIQUE," +
"password VARCHAR(1024) NOT NULL," +
"salt VARCHAR(1024) NOT NULL," +
@@ -296,7 +297,11 @@ public class DataManager {
"CREATE TABLE traccar1 (" +
"id INT PRIMARY KEY AUTO_INCREMENT);").executeUpdate();
- addUser("admin", "admin", true);
+ User admin = new User();
+ admin.setName("admin");
+ admin.setEmail("admin");
+ admin.setPassword("admin");
+ addUser(admin);
}
public long login(String email, String password) throws SQLException {
@@ -321,25 +326,12 @@ public class DataManager {
}
}
- public void addUser(String email, String password, boolean admin) throws SQLException {
-
- Connection connection = dataSource.getConnection();
- try {
- PreparedStatement statement = connection.prepareStatement(
- "INSERT INTO user (email, password, salt, admin) " +
- "VALUES (?, CAST(HASH('SHA256', STRINGTOUTF8(?), 1000) AS VARCHAR), '', ?);");
- try {
- statement.setString(1, email);
- statement.setString(2, password);
- statement.setBoolean(3, admin);
-
- statement.executeUpdate();
- } finally {
- statement.close();
- }
- } finally {
- connection.close();
- }
+ 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);")
+ .setObject(user)
+ .executeUpdate());
}
public Collection<Permission> getPermissions() throws SQLException {