From 4978c47d5111ee3d7cb3999b346155ce8151c536 Mon Sep 17 00:00:00 2001 From: Pepich Date: Sat, 18 Feb 2017 17:20:13 +0100 Subject: [PATCH] Fixed a bug where webtoken could not generate new tokens --- .../redstoner/modules/webtoken/WebToken.java | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/com/redstoner/modules/webtoken/WebToken.java b/src/com/redstoner/modules/webtoken/WebToken.java index 5ad6632..c8b5c59 100644 --- a/src/com/redstoner/modules/webtoken/WebToken.java +++ b/src/com/redstoner/modules/webtoken/WebToken.java @@ -22,7 +22,7 @@ import com.redstoner.misc.mysql.elements.MysqlDatabase; import com.redstoner.misc.mysql.elements.MysqlTable; import com.redstoner.modules.Module; -@Version(major = 1, minor = 0, revision = 0, compatible = 1) +@Version(major = 1, minor = 1, revision = 0, compatible = 1) public class WebToken implements Module { private boolean enabled = false; @@ -67,6 +67,28 @@ public class WebToken implements Module enabled = true; } + private String getNextId() throws Exception + { + Object[] results = table.get("select id from register_tokens order by id desc limit 1;"); + if (results instanceof String[]) + { + String[] tokenResults = (String[]) results; + if (tokenResults.length == 1) + { + int id = Integer.valueOf(tokenResults[0]); + return "" + ++id; + } + else + { + return null; + } + } + else + { + throw new Exception("Token query returned invalid result!"); + } + } + private String query(String emailOrToken, UUID uuid) throws Exception { if (!(emailOrToken.equals("token") && emailOrToken.equals("email"))) @@ -164,8 +186,9 @@ public class WebToken implements Module String token = generateToken(); try { + String id = getNextId(); table.delete(new MysqlConstraint("uuid", ConstraintOperator.EQUAL, uuid)); - table.insert(uuid, token, email); + table.insert(id, uuid, token, email); player.sendMessage(ChatColor.GREEN + "Token generated!"); printToken(player, email, token); } @@ -215,7 +238,7 @@ public class WebToken implements Module " help Generates a token used for website authentication;\n" + " type player;\n" + " perm utils.webtoken;\n" + - " run gettoken;\n" + + " run gettoken email;\n" + " }\n" + "}"; }