This commit is contained in:
2026-04-10 15:26:51 +03:00
parent a8a2239d37
commit 5821006bf2
68 changed files with 3292 additions and 19 deletions

View File

@@ -0,0 +1,39 @@
package su.xserver.iikocon;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.RoutingContext;
public class SetupHandler {
private final UserService userService;
public SetupHandler(UserService userService) {
this.userService = userService;
}
public void handleSetup(RoutingContext ctx) {
// Проверяем, есть ли уже пользователи
userService.countUsers().onComplete(ar -> {
if (ar.succeeded() && ar.result() == 0) {
JsonObject body = ctx.body().asJsonObject();
String login = body.getString("login");
String password = body.getString("password");
if (login == null || password == null || login.length() < 3 || password.length() < 6) {
ctx.response().setStatusCode(400).end("Invalid login or password (min 3/6 chars)");
return;
}
String ip = ctx.request().remoteAddress().host();
userService.createUser(login, password, ip).onComplete(cr -> {
if (cr.succeeded()) {
ctx.response().setStatusCode(201).end(new JsonObject().put("success", true).encode());
} else {
ctx.response().setStatusCode(500).end("Failed to create admin: " + cr.cause().getMessage());
}
});
} else {
ctx.response().setStatusCode(403).end("Setup already completed");
}
});
}
}