Updated accounts SQL table to match other branches.

This commit is contained in:
MobiusDev
2018-03-21 11:01:09 +00:00
parent ceb1549b84
commit dfc25d6642
3 changed files with 21 additions and 19 deletions

View File

@@ -3,10 +3,12 @@
-- --------------------------- -- ---------------------------
CREATE TABLE IF NOT EXISTS `accounts` ( CREATE TABLE IF NOT EXISTS `accounts` (
`login` VARCHAR(45) NOT NULL default '', `login` VARCHAR(45) NOT NULL default '',
`password` VARCHAR(45) , `password` VARCHAR(45),
`lastactive` DECIMAL(20), `email` varchar(255) DEFAULT NULL,
`access_level` INT, `created_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`lastIP` VARCHAR(20), `lastactive` bigint(13) unsigned NOT NULL DEFAULT '0',
`lastServer` int(4) default 1, `accessLevel` TINYINT NOT NULL DEFAULT 0,
`lastIP` CHAR(15) NULL DEFAULT NULL,
`lastServer` TINYINT DEFAULT 1,
PRIMARY KEY (`login`) PRIMARY KEY (`login`)
); ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@@ -513,7 +513,7 @@ public class LoginController
{ {
try (Connection con = DatabaseFactory.getInstance().getConnection()) try (Connection con = DatabaseFactory.getInstance().getConnection())
{ {
final String stmt = "UPDATE accounts SET access_level=? WHERE login=?"; final String stmt = "UPDATE accounts SET accessLevel=? WHERE login=?";
PreparedStatement statement = con.prepareStatement(stmt); PreparedStatement statement = con.prepareStatement(stmt);
statement.setInt(1, banLevel); statement.setInt(1, banLevel);
statement.setString(2, account); statement.setString(2, account);
@@ -531,7 +531,7 @@ public class LoginController
boolean ok = false; boolean ok = false;
try (Connection con = DatabaseFactory.getInstance().getConnection()) try (Connection con = DatabaseFactory.getInstance().getConnection())
{ {
PreparedStatement statement = con.prepareStatement("SELECT access_level FROM accounts WHERE login=?"); PreparedStatement statement = con.prepareStatement("SELECT accessLevel FROM accounts WHERE login=?");
statement.setString(1, user); statement.setString(1, user);
ResultSet rset = statement.executeQuery(); ResultSet rset = statement.executeQuery();
@@ -595,14 +595,14 @@ public class LoginController
int access = 0; int access = 0;
int lastServer = 1; int lastServer = 1;
PreparedStatement statement = con.prepareStatement("SELECT password, access_level, lastServer FROM accounts WHERE login=?"); PreparedStatement statement = con.prepareStatement("SELECT password, accessLevel, lastServer FROM accounts WHERE login=?");
statement.setString(1, user); statement.setString(1, user);
ResultSet rset = statement.executeQuery(); ResultSet rset = statement.executeQuery();
if (rset.next()) if (rset.next())
{ {
expected = Base64.getDecoder().decode(rset.getString("password")); expected = Base64.getDecoder().decode(rset.getString("password"));
access = rset.getInt("access_level"); access = rset.getInt("accessLevel");
lastServer = rset.getInt("lastServer"); lastServer = rset.getInt("lastServer");
if (lastServer <= 0) if (lastServer <= 0)
@@ -628,7 +628,7 @@ public class LoginController
{ {
if ((user != null) && ((user.length()) >= 2) && (user.length() <= 14)) if ((user != null) && ((user.length()) >= 2) && (user.length() <= 14))
{ {
statement = con.prepareStatement("INSERT INTO accounts (login,password,lastactive,access_level,lastIP) values(?,?,?,?,?)"); statement = con.prepareStatement("INSERT INTO accounts (login,password,lastactive,accessLevel,lastIP) values(?,?,?,?,?)");
statement.setString(1, user); statement.setString(1, user);
statement.setString(2, Base64.getEncoder().encodeToString(hash)); statement.setString(2, Base64.getEncoder().encodeToString(hash));
statement.setLong(3, System.currentTimeMillis()); statement.setLong(3, System.currentTimeMillis());
@@ -723,7 +723,7 @@ public class LoginController
try (Connection con = DatabaseFactory.getInstance().getConnection()) try (Connection con = DatabaseFactory.getInstance().getConnection())
{ {
PreparedStatement statement = con.prepareStatement("SELECT access_level FROM accounts WHERE login=?"); PreparedStatement statement = con.prepareStatement("SELECT accessLevel FROM accounts WHERE login=?");
statement.setString(1, user); statement.setString(1, user);
ResultSet rset = statement.executeQuery(); ResultSet rset = statement.executeQuery();

View File

@@ -162,18 +162,18 @@ public class SQLAccountManager
int count = 0; int count = 0;
Connection con = null; Connection con = null;
con = DatabaseFactory.getInstance().getConnection(); con = DatabaseFactory.getInstance().getConnection();
String q = "SELECT login, access_level FROM accounts "; String q = "SELECT login, accessLevel FROM accounts ";
if (m.equals("1")) if (m.equals("1"))
{ {
q = q.concat("WHERE access_level < 0"); q = q.concat("WHERE accessLevel < 0");
} }
else if (m.equals("2")) else if (m.equals("2"))
{ {
q = q.concat("WHERE access_level > 0"); q = q.concat("WHERE accessLevel > 0");
} }
else if (m.equals("3")) else if (m.equals("3"))
{ {
q = q.concat("WHERE access_level = 0"); q = q.concat("WHERE accessLevel = 0");
} }
q = q.concat(" ORDER BY login ASC"); q = q.concat(" ORDER BY login ASC");
@@ -181,7 +181,7 @@ public class SQLAccountManager
ResultSet rset = statement.executeQuery(); ResultSet rset = statement.executeQuery();
while (rset.next()) while (rset.next())
{ {
System.out.println(rset.getString("login") + " -> " + rset.getInt("access_level")); System.out.println(rset.getString("login") + " -> " + rset.getInt("accessLevel"));
count++; count++;
} }
rset.close(); rset.close();
@@ -201,7 +201,7 @@ public class SQLAccountManager
// Add to Base // Add to Base
Connection con = null; Connection con = null;
con = DatabaseFactory.getInstance().getConnection(); con = DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement("REPLACE accounts (login, password, access_level) VALUES (?,?,?)"); PreparedStatement statement = con.prepareStatement("REPLACE accounts (login, password, accessLevel) VALUES (?,?,?)");
statement.setString(1, account); statement.setString(1, account);
statement.setString(2, Base64.getEncoder().encodeToString(newpass)); statement.setString(2, Base64.getEncoder().encodeToString(newpass));
statement.setString(3, level); statement.setString(3, level);
@@ -227,7 +227,7 @@ public class SQLAccountManager
{ {
// Exist // Exist
// Update // Update
statement = con.prepareStatement("UPDATE accounts SET access_level=? WHERE login=?;"); statement = con.prepareStatement("UPDATE accounts SET accessLevel=? WHERE login=?;");
statement.setEscapeProcessing(true); statement.setEscapeProcessing(true);
statement.setString(1, level); statement.setString(1, level);
statement.setString(2, account); statement.setString(2, account);