Refactor token generation and remove unused endpoints.

This commit is contained in:
2025-02-20 22:13:13 +01:00
parent 7f5b57516e
commit dea0d33185
4 changed files with 5 additions and 47 deletions
@@ -19,17 +19,13 @@
package de.steamwar.velocitycore.commands;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import de.steamwar.command.SWCommand;
import de.steamwar.messages.Chatter;
import de.steamwar.sql.SteamwarUser;
import de.steamwar.sql.Token;
import java.net.URI;
import java.net.URLEncoder;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
public class WebpasswordCommand extends SWCommand {
@@ -44,16 +40,7 @@ public class WebpasswordCommand extends SWCommand {
public void genericCommand(Chatter sender) {
SteamwarUser user = sender.user();
HttpRequest request = HttpRequest.newBuilder()
.POST(HttpRequest.BodyPublishers.noBody())
.uri(URI.create("http://localhost:1337/v2/auth/enroll/" + user.getId())).build();
client.sendAsync(request, responseInfo -> HttpResponse.BodySubscribers.ofString(StandardCharsets.UTF_8)).thenAccept(httpResponse -> {
JsonObject jsonObject = JsonParser.parseString(httpResponse.body()).getAsJsonObject();
String token = jsonObject.get("token").getAsString();
sender.system("WEB_RESET_URL", URLEncoder.encode(token, StandardCharsets.UTF_8));
});
String token = Token.createToken("PT" + user.getUserName(), user);
sender.system("WEB_RESET_URL", URLEncoder.encode(token, StandardCharsets.UTF_8));
}
}