fixed creation of first user upon database initalization
This commit is contained in:
@@ -20,7 +20,6 @@ import de.srsoftware.umbrella.user.api.UserDb;
|
||||
import de.srsoftware.umbrella.user.model.*;
|
||||
import de.srsoftware.umbrella.user.model.Session;
|
||||
import de.srsoftware.umbrella.user.model.UmbrellaUser;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
@@ -159,8 +158,17 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
long count = 0L;
|
||||
try {
|
||||
Query.insertInto(TABLE_USERS,LOGIN,PASS,THEME,SETTINGS).values("admin", hasher.hash("admin",null),"default",null).execute(db);
|
||||
ResultSet rs = select("COUNT(*)").from(TABLE_USERS).exec(db);
|
||||
if (rs.next()) count = rs.getLong(1);
|
||||
rs.close();
|
||||
} catch (SQLException ignored) {
|
||||
// go on with table creation
|
||||
}
|
||||
|
||||
try {
|
||||
if (count<1) insertInto(TABLE_USERS,LOGIN,PASS,THEME,SETTINGS).values("admin", hasher.hash("admin",null),"default",null).execute(db);
|
||||
} catch (SQLException e) {
|
||||
LOG.log(ERROR,"Failed to create first user…");
|
||||
throw new RuntimeException(e);
|
||||
|
||||
Reference in New Issue
Block a user