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