implemented resetting passwords
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -10,6 +10,7 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
|
||||
import static de.srsoftware.widerhall.Constants.*;
|
||||
import static de.srsoftware.widerhall.Util.t;
|
||||
import static de.srsoftware.widerhall.data.MailingList.HOLD_TIME;
|
||||
|
||||
@@ -19,6 +20,7 @@ import static de.srsoftware.widerhall.data.MailingList.HOLD_TIME;
|
||||
*/
|
||||
public class Database {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Database.class);
|
||||
private static final String DB_VERSION = "db_version";
|
||||
private static Database singleton = null; // we only need one db handle ever. This will be it.
|
||||
private final Connection conn; // the actual db connection handle within the singleton
|
||||
|
||||
@@ -295,6 +297,14 @@ public class Database {
|
||||
return this;
|
||||
}
|
||||
|
||||
private void createVersionTable() throws SQLException {
|
||||
var sql = "CREATE TABLE %s (%s %s NOT NULL PRIMARY KEY);".formatted(DB_VERSION,DB_VERSION,INT);
|
||||
var db = Database.open();
|
||||
db.query(sql).compile().run();
|
||||
sql = "INSERT INTO %s VALUES (1)".formatted(DB_VERSION);
|
||||
db.query(sql).compile().run();
|
||||
}
|
||||
|
||||
private boolean columnExists(String tableName, String columnName) throws SQLException {
|
||||
var rs = Database.open().select("pragma_table_info('"+tableName+"')","COUNT(*) AS num").where("name",columnName).compile().exec();
|
||||
try {
|
||||
@@ -357,6 +367,7 @@ public class Database {
|
||||
try {
|
||||
singleton = new Database(DriverManager.getConnection(url));
|
||||
singleton.assertTables(); // must not be concatenated to exception above (assertTables accesses singleton)!
|
||||
singleton.update202405();
|
||||
} catch (SQLException sqle) {
|
||||
sqle.printStackTrace();
|
||||
}
|
||||
@@ -373,6 +384,10 @@ public class Database {
|
||||
return new Request(sql);
|
||||
}
|
||||
|
||||
public Request query(String sql) {
|
||||
return new Request(new StringBuilder(sql));
|
||||
}
|
||||
|
||||
/**
|
||||
* create a SELECT [flields] FROM [table] request.
|
||||
* If no fields are supplied, a request in the form SELECT * FROM [table] will be generated.
|
||||
@@ -390,7 +405,6 @@ public class Database {
|
||||
return new Request(sql.append(" FROM ").append(tableName));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* check, whether a table with the provided name exists
|
||||
* @param tbName
|
||||
@@ -420,4 +434,12 @@ public class Database {
|
||||
public Request update(String tableName) {
|
||||
return new Request(new StringBuilder("UPDATE ").append(tableName));
|
||||
}
|
||||
|
||||
private Database update202405() throws SQLException {
|
||||
if (!tableExists(Database.DB_VERSION)) {
|
||||
createVersionTable();
|
||||
User.addTokenColumn();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user