Skip to content

Commit

Permalink
Removes duplicate keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Nickster258 committed May 9, 2020
1 parent e99cc1b commit a9f12a0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/org/openredstone/managers/QueryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public boolean userIsLinkedById(String userId) throws SQLException {
}

public void createUnlinkedUser(String userId, String ign) throws SQLException {
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `nu_users` VALUES (?, NULL, ?)");
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `nu_users` VALUES (?, NULL, ?) ON DUPLICATE KEY UPDATE `discord_id` = NULL");
preparedStatement.setString(1, userId);
preparedStatement.setString(2, ign);
preparedStatement.execute();
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/openredstone/managers/TokenManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public TokenManager(int tokenLength, int lifeSpan) {

public String registerTokenToUser(String userId) {
String token = generateToken(tokenLength);
if (authenticationTokens.containsValue(userId)) {
String key = authenticationTokens.keySet().stream().filter(e -> authenticationTokens.get(e).equals(userId)).findFirst().get();
authenticationTokens.remove(key);
tokenLifespans.remove(key);
}
authenticationTokens.put(token, userId);
tokenLifespans.put(token, System.currentTimeMillis() / 1000L);
return token;
Expand Down

0 comments on commit a9f12a0

Please sign in to comment.