mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-21 05:50:18 +08:00
Formatted SecurityTable
This commit is contained in:
parent
4516ab81bf
commit
a4ae93390c
@ -22,4 +22,8 @@ public class Select extends WhereParser {
|
||||
Log.debug(parser.toString());
|
||||
return parser;
|
||||
}
|
||||
|
||||
public static Select all(String table) {
|
||||
return new Select("SELECT * FROM " + table);
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,8 @@ package main.java.com.djrapitops.plan.database.tables;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.data.WebUser;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
import main.java.com.djrapitops.plan.database.sql.Insert;
|
||||
import main.java.com.djrapitops.plan.database.sql.Select;
|
||||
import main.java.com.djrapitops.plan.database.sql.Sql;
|
||||
import main.java.com.djrapitops.plan.database.sql.TableSqlParser;
|
||||
|
||||
@ -22,15 +24,12 @@ import java.util.List;
|
||||
*/
|
||||
public class SecurityTable extends Table {
|
||||
|
||||
private final String columnUser;
|
||||
private final String columnSaltedHash;
|
||||
private final String columnPermLevel;
|
||||
private final String columnUser = "username";
|
||||
private final String columnSaltedHash = "salted_pass_hash";
|
||||
private final String columnPermLevel = "permission_level";
|
||||
|
||||
public SecurityTable(SQLDB db, boolean usingMySQL) {
|
||||
super("plan_security", db, usingMySQL);
|
||||
columnUser = "username";
|
||||
columnSaltedHash = "salted_pass_hash";
|
||||
columnPermLevel = "permission_level";
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -71,11 +70,10 @@ public class SecurityTable extends Table {
|
||||
public void addNewUser(String user, String saltPassHash, int permLevel) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
statement = prepareStatement("INSERT INTO " + tableName + " ("
|
||||
+ columnUser + ", "
|
||||
+ columnSaltedHash + ", "
|
||||
+ columnPermLevel
|
||||
+ ") VALUES (?, ?, ?)");
|
||||
statement = prepareStatement(Insert.values(tableName,
|
||||
columnUser,
|
||||
columnSaltedHash,
|
||||
columnPermLevel));
|
||||
statement.setString(1, user);
|
||||
statement.setString(2, saltPassHash);
|
||||
statement.setInt(3, permLevel);
|
||||
@ -94,7 +92,7 @@ public class SecurityTable extends Table {
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
try {
|
||||
statement = prepareStatement("SELECT * FROM " + tableName + " WHERE (" + columnUser + "=?)");
|
||||
statement = prepareStatement(Select.all(tableName).where(columnUser + "=?").toString());
|
||||
statement.setString(1, user);
|
||||
set = statement.executeQuery();
|
||||
if (set.next()) {
|
||||
@ -113,7 +111,7 @@ public class SecurityTable extends Table {
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
try {
|
||||
statement = prepareStatement("SELECT * FROM " + tableName);
|
||||
statement = prepareStatement(Select.all(tableName).toString());
|
||||
set = statement.executeQuery();
|
||||
List<WebUser> list = new ArrayList<>();
|
||||
while (set.next()) {
|
||||
|
Loading…
Reference in New Issue
Block a user