Convert more routes to use body fields instead of query params
This commit is contained in:
parent
c00b424fe8
commit
b291e9e13b
@ -1,6 +1,7 @@
|
||||
package net.frozenorb.apiv3.route.auditLog;
|
||||
|
||||
import io.vertx.core.Handler;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
import net.frozenorb.apiv3.APIv3;
|
||||
import net.frozenorb.apiv3.auditLog.AuditLog;
|
||||
@ -18,7 +19,8 @@ public final class POSTAuditLog implements Handler<RoutingContext> {
|
||||
} else if (user == null) {
|
||||
ErrorUtils.respondNotFound(ctx, "User", ctx.request().getParam("id"));
|
||||
} else {
|
||||
String userIp = ctx.request().getParam("userIp");
|
||||
JsonObject requestBody = ctx.getBodyAsJson();
|
||||
String userIp = requestBody.getString("userIp");
|
||||
|
||||
if (!IpUtils.isValidIp(userIp)) {
|
||||
ErrorUtils.respondInvalidInput(ctx, "Ip address \"" + userIp + "\" is not valid.");
|
||||
@ -28,9 +30,9 @@ public final class POSTAuditLog implements Handler<RoutingContext> {
|
||||
AuditLogActionType type;
|
||||
|
||||
try {
|
||||
type = AuditLogActionType.valueOf(ctx.request().getParam("type"));
|
||||
type = AuditLogActionType.valueOf(requestBody.getString("type"));
|
||||
} catch (IllegalArgumentException ex) {
|
||||
ErrorUtils.respondNotFound(ctx, "Audit log action type", ctx.request().getParam("type"));
|
||||
ErrorUtils.respondNotFound(ctx, "Audit log action type", requestBody.getString("type"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package net.frozenorb.apiv3.route.emailToken;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import io.vertx.core.Handler;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
import net.frozenorb.apiv3.APIv3;
|
||||
import net.frozenorb.apiv3.model.User;
|
||||
@ -31,7 +32,8 @@ public final class POSTEmailTokensConfirm implements Handler<RoutingContext> {
|
||||
return;
|
||||
}
|
||||
|
||||
String password = ctx.request().getParam("password");
|
||||
JsonObject requestBody = ctx.getBodyAsJson();
|
||||
String password = requestBody.getString("password");
|
||||
|
||||
if (password.length() < 8) {
|
||||
ErrorUtils.respondGeneric(ctx, 200, "Your password is too short.");
|
||||
|
@ -2,6 +2,7 @@ package net.frozenorb.apiv3.route.grants;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import io.vertx.core.Handler;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
import net.frozenorb.apiv3.APIv3;
|
||||
import net.frozenorb.apiv3.auditLog.AuditLog;
|
||||
@ -25,14 +26,15 @@ public final class DELETEGrantsId implements Handler<RoutingContext> {
|
||||
return;
|
||||
}
|
||||
|
||||
User removedBy = User.findByIdSync(ctx.request().getParam("removedBy"));
|
||||
JsonObject requestBody = ctx.getBodyAsJson();
|
||||
User removedBy = User.findByIdSync(requestBody.getString("removedBy"));
|
||||
|
||||
if (removedBy == null) {
|
||||
ErrorUtils.respondNotFound(ctx, "User", ctx.request().getParam("removedBy"));
|
||||
ErrorUtils.respondNotFound(ctx, "User", requestBody.getString("removedBy"));
|
||||
return;
|
||||
}
|
||||
|
||||
String reason = ctx.request().getParam("reason");
|
||||
String reason = requestBody.getString("reason");
|
||||
|
||||
if (reason == null || reason.trim().isEmpty()) {
|
||||
ErrorUtils.respondRequiredInput(ctx, "reason");
|
||||
|
@ -2,6 +2,7 @@ package net.frozenorb.apiv3.route.ipBans;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import io.vertx.core.Handler;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
import net.frozenorb.apiv3.APIv3;
|
||||
import net.frozenorb.apiv3.auditLog.AuditLog;
|
||||
@ -25,14 +26,15 @@ public final class DELETEIpBan implements Handler<RoutingContext> {
|
||||
return;
|
||||
}
|
||||
|
||||
User removedBy = User.findByIdSync(ctx.request().getParam("removedBy"));
|
||||
JsonObject requestBody = ctx.getBodyAsJson();
|
||||
User removedBy = User.findByIdSync(requestBody.getString("removedBy"));
|
||||
|
||||
if (removedBy == null) {
|
||||
ErrorUtils.respondNotFound(ctx, "User", ctx.request().getParam("removedBy"));
|
||||
ErrorUtils.respondNotFound(ctx, "User", requestBody.getString("removedBy"));
|
||||
return;
|
||||
}
|
||||
|
||||
String reason = ctx.request().getParam("reason");
|
||||
String reason = requestBody.getString("reason");
|
||||
|
||||
if (reason == null || reason.trim().isEmpty()) {
|
||||
ErrorUtils.respondRequiredInput(ctx, "reason");
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.frozenorb.apiv3.route.ipBans;
|
||||
|
||||
import io.vertx.core.Handler;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
import net.frozenorb.apiv3.APIv3;
|
||||
import net.frozenorb.apiv3.model.IpBan;
|
||||
@ -13,14 +14,15 @@ import java.time.Instant;
|
||||
public final class POSTIpBans implements Handler<RoutingContext> {
|
||||
|
||||
public void handle(RoutingContext ctx) {
|
||||
String userIp = ctx.request().getParam("id");
|
||||
JsonObject requestBody = ctx.getBodyAsJson();
|
||||
String userIp = requestBody.getString("id");
|
||||
|
||||
if (!IpUtils.isValidIp(userIp)) {
|
||||
ErrorUtils.respondInvalidInput(ctx, "Ip address \"" + userIp + "\" is not valid.");
|
||||
return;
|
||||
}
|
||||
|
||||
String reason = ctx.request().getParam("reason");
|
||||
String reason = requestBody.getString("reason");
|
||||
|
||||
if (reason == null || reason.trim().isEmpty()) {
|
||||
ErrorUtils.respondRequiredInput(ctx, "reason");
|
||||
@ -29,10 +31,8 @@ public final class POSTIpBans implements Handler<RoutingContext> {
|
||||
|
||||
Instant expiresAt = null;
|
||||
|
||||
try {
|
||||
expiresAt = Instant.ofEpochMilli(Long.parseLong(ctx.request().getParam("expiresAt")));
|
||||
} catch (NumberFormatException ignored) {
|
||||
// Just leave it null, we don't need an expiration date.
|
||||
if (requestBody.containsKey("expiresAt") && requestBody.getLong("expiresAt") != -1) {
|
||||
expiresAt = Instant.ofEpochMilli(requestBody.getLong("expiresAt"));
|
||||
}
|
||||
|
||||
if (expiresAt != null && expiresAt.isBefore(Instant.now())) {
|
||||
@ -41,7 +41,7 @@ public final class POSTIpBans implements Handler<RoutingContext> {
|
||||
}
|
||||
|
||||
// We purposely don't do a null check, ip bans don't have to have a source.
|
||||
User addedBy = User.findByIdSync(ctx.request().getParam("addedBy"));
|
||||
User addedBy = User.findByIdSync(requestBody.getString("addedBy"));
|
||||
|
||||
IpBan ipBan = new IpBan(userIp, reason, expiresAt, addedBy, ctx.get("actor"));
|
||||
ipBan.insert();
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.frozenorb.apiv3.route.notificationTemplates;
|
||||
|
||||
import io.vertx.core.Handler;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
import net.frozenorb.apiv3.APIv3;
|
||||
import net.frozenorb.apiv3.model.NotificationTemplate;
|
||||
@ -8,9 +9,10 @@ import net.frozenorb.apiv3.model.NotificationTemplate;
|
||||
public final class POSTNotificationTemplates implements Handler<RoutingContext> {
|
||||
|
||||
public void handle(RoutingContext ctx) {
|
||||
String id = ctx.request().getParam("id");
|
||||
String subject = ctx.request().getParam("subject");
|
||||
String body = ctx.request().getParam("body");
|
||||
JsonObject requestBody = ctx.getBodyAsJson();
|
||||
String id = requestBody.getString("id");
|
||||
String subject = requestBody.getString("subject");
|
||||
String body = requestBody.getString("body");
|
||||
|
||||
NotificationTemplate notificationTemplate = new NotificationTemplate(id, subject, body);
|
||||
notificationTemplate.insert();
|
||||
|
@ -2,6 +2,7 @@ package net.frozenorb.apiv3.route.punishments;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import io.vertx.core.Handler;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
import net.frozenorb.apiv3.APIv3;
|
||||
import net.frozenorb.apiv3.auditLog.AuditLog;
|
||||
@ -25,14 +26,15 @@ public final class DELETEPunishments implements Handler<RoutingContext> {
|
||||
return;
|
||||
}
|
||||
|
||||
User removedBy = User.findByIdSync(ctx.request().getParam("removedBy"));
|
||||
JsonObject requestBody = ctx.getBodyAsJson();
|
||||
User removedBy = User.findByIdSync(requestBody.getString("removedBy"));
|
||||
|
||||
if (removedBy == null) {
|
||||
ErrorUtils.respondNotFound(ctx, "User", ctx.request().getParam("removedBy"));
|
||||
ErrorUtils.respondNotFound(ctx, "User", requestBody.getString("removedBy"));
|
||||
return;
|
||||
}
|
||||
|
||||
String reason = ctx.request().getParam("reason");
|
||||
String reason = requestBody.getString("reason");
|
||||
|
||||
if (reason == null || reason.trim().isEmpty()) {
|
||||
ErrorUtils.respondRequiredInput(ctx, "reason");
|
||||
|
@ -3,6 +3,7 @@ package net.frozenorb.apiv3.route.punishments;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import io.vertx.core.Handler;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
import net.frozenorb.apiv3.APIv3;
|
||||
import net.frozenorb.apiv3.auditLog.AuditLog;
|
||||
@ -23,15 +24,16 @@ public final class DELETEUserActivePunishment implements Handler<RoutingContext>
|
||||
return;
|
||||
}
|
||||
|
||||
Punishment.PunishmentType type = Punishment.PunishmentType.valueOf(ctx.request().getParam("type").toUpperCase());
|
||||
User removedBy = User.findByIdSync(ctx.request().getParam("removedBy"));
|
||||
JsonObject requestBody = ctx.getBodyAsJson();
|
||||
Punishment.PunishmentType type = Punishment.PunishmentType.valueOf(requestBody.getString("type").toUpperCase());
|
||||
User removedBy = User.findByIdSync(requestBody.getString("removedBy"));
|
||||
|
||||
if (removedBy == null) {
|
||||
ErrorUtils.respondNotFound(ctx, "User", ctx.request().getParam("removedBy"));
|
||||
ErrorUtils.respondNotFound(ctx, "User", requestBody.getString("removedBy"));
|
||||
return;
|
||||
}
|
||||
|
||||
String reason = ctx.request().getParam("reason");
|
||||
String reason = requestBody.getString("reason");
|
||||
|
||||
if (reason == null || reason.trim().isEmpty()) {
|
||||
ErrorUtils.respondRequiredInput(ctx, "reason");
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.frozenorb.apiv3.route.ranks;
|
||||
|
||||
import io.vertx.core.Handler;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
import net.frozenorb.apiv3.APIv3;
|
||||
import net.frozenorb.apiv3.model.Rank;
|
||||
@ -8,12 +9,13 @@ import net.frozenorb.apiv3.model.Rank;
|
||||
public final class POSTRanks implements Handler<RoutingContext> {
|
||||
|
||||
public void handle(RoutingContext ctx) {
|
||||
String id = ctx.request().getParam("id");
|
||||
int weight = Integer.parseInt(ctx.request().getParam("weight"));
|
||||
String displayName = ctx.request().getParam("displayName");
|
||||
String gameColor = ctx.request().getParam("gameColor");
|
||||
String websiteColor = ctx.request().getParam("websiteColor");
|
||||
boolean staffRank = Boolean.parseBoolean(ctx.request().getParam("staffRank"));
|
||||
JsonObject requestBody = ctx.getBodyAsJson();
|
||||
String id = requestBody.getString("id");
|
||||
int weight = requestBody.getInteger("weight");
|
||||
String displayName = requestBody.getString("displayName");
|
||||
String gameColor = requestBody.getString("gameColor");
|
||||
String websiteColor = requestBody.getString("websiteColor");
|
||||
boolean staffRank = requestBody.getBoolean("staffRank");
|
||||
|
||||
Rank rank = new Rank(id, weight, displayName, gameColor, websiteColor, staffRank);
|
||||
rank.insert();
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.frozenorb.apiv3.route.serverGroups;
|
||||
|
||||
import io.vertx.core.Handler;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
import net.frozenorb.apiv3.APIv3;
|
||||
import net.frozenorb.apiv3.model.ServerGroup;
|
||||
@ -8,8 +9,9 @@ import net.frozenorb.apiv3.model.ServerGroup;
|
||||
public final class POSTServerGroups implements Handler<RoutingContext> {
|
||||
|
||||
public void handle(RoutingContext ctx) {
|
||||
String id = ctx.request().getParam("id");
|
||||
String image = ctx.request().getParam("image");
|
||||
JsonObject requestBody = ctx.getBodyAsJson();
|
||||
String id = requestBody.getString("id");
|
||||
String image = requestBody.getString("image");
|
||||
|
||||
ServerGroup serverGroup = new ServerGroup(id, image);
|
||||
serverGroup.insert();
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.frozenorb.apiv3.route.servers;
|
||||
|
||||
import io.vertx.core.Handler;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
import net.frozenorb.apiv3.APIv3;
|
||||
import net.frozenorb.apiv3.model.Server;
|
||||
@ -13,13 +14,14 @@ import java.util.UUID;
|
||||
public final class POSTServers implements Handler<RoutingContext> {
|
||||
|
||||
public void handle(RoutingContext ctx) {
|
||||
String id = ctx.request().getParam("id");
|
||||
String displayName = ctx.request().getParam("displayName");
|
||||
ServerGroup group = ServerGroup.findById(ctx.request().getParam("group"));
|
||||
String ip = ctx.request().getParam("ip");
|
||||
JsonObject requestBody = ctx.getBodyAsJson();
|
||||
String id = requestBody.getString("id");
|
||||
String displayName = requestBody.getString("displayName");
|
||||
ServerGroup group = ServerGroup.findById(requestBody.getString("group"));
|
||||
String ip = requestBody.getString("ip");
|
||||
|
||||
if (group == null) {
|
||||
ErrorUtils.respondNotFound(ctx, "Server group", ctx.request().getParam("group"));
|
||||
ErrorUtils.respondNotFound(ctx, "Server group", requestBody.getString("group"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package net.frozenorb.apiv3.route.users;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import io.vertx.core.Handler;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
import net.frozenorb.apiv3.APIv3;
|
||||
import net.frozenorb.apiv3.model.User;
|
||||
@ -18,12 +19,14 @@ public final class POSTUserChangePassword implements Handler<RoutingContext> {
|
||||
return;
|
||||
}
|
||||
|
||||
JsonObject requestBody = ctx.getBodyAsJson();
|
||||
|
||||
if (user.getPassword() == null) {
|
||||
ErrorUtils.respondInvalidInput(ctx, "User provided does not have password set.");
|
||||
return;
|
||||
}
|
||||
|
||||
boolean authorized = user.checkPassword(ctx.request().getParam("currentPassword"));
|
||||
boolean authorized = user.checkPassword(requestBody.getString("currentPassword"));
|
||||
|
||||
if (!authorized) {
|
||||
ErrorUtils.respondInvalidInput(ctx, "Current password is not correct.");
|
||||
@ -38,7 +41,7 @@ public final class POSTUserChangePassword implements Handler<RoutingContext> {
|
||||
// TODO
|
||||
}
|
||||
|
||||
String newPassword = ctx.request().getParam("newPassword");
|
||||
String newPassword = requestBody.getString("newPassword");
|
||||
|
||||
if (newPassword.length() < 8) {
|
||||
ErrorUtils.respondGeneric(ctx, 200, "Your password is too short.");
|
||||
|
@ -1,11 +1,11 @@
|
||||
package net.frozenorb.apiv3.route.users;
|
||||
|
||||
import io.vertx.core.Handler;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
import net.frozenorb.apiv3.APIv3;
|
||||
import net.frozenorb.apiv3.actor.Actor;
|
||||
import net.frozenorb.apiv3.actor.ActorType;
|
||||
import net.frozenorb.apiv3.actor.actors.ServerActor;
|
||||
import net.frozenorb.apiv3.model.IpLogEntry;
|
||||
import net.frozenorb.apiv3.model.Server;
|
||||
import net.frozenorb.apiv3.model.User;
|
||||
@ -25,23 +25,19 @@ public final class POSTUserLogin implements Handler<RoutingContext> {
|
||||
return;
|
||||
}
|
||||
|
||||
JsonObject requestBody = ctx.getBodyAsJson();
|
||||
User user = User.findByIdSync(uuid);
|
||||
String username = ctx.request().getParam("username");
|
||||
String userIp = ctx.request().getParam("userIp");
|
||||
String username = requestBody.getString("username");
|
||||
String userIp = requestBody.getString("userIp");
|
||||
Actor actor = ctx.get("actor");
|
||||
Server server;
|
||||
|
||||
if (actor.getType() == ActorType.SERVER) {
|
||||
server = ((ServerActor) actor).getServer();
|
||||
} else {
|
||||
server = Server.findById(ctx.request().getParam("server"));
|
||||
|
||||
if (server == null) {
|
||||
ErrorUtils.respondNotFound(ctx, "Server", ctx.request().getParam("server"));
|
||||
return;
|
||||
}
|
||||
if (actor.getType() != ActorType.SERVER) {
|
||||
ErrorUtils.respondGeneric(ctx, 400, "This action can only be performed when requested by a server.");
|
||||
return;
|
||||
}
|
||||
|
||||
Server server = Server.findById(actor.getName());
|
||||
|
||||
if (!IpUtils.isValidIp(userIp)) {
|
||||
ErrorUtils.respondInvalidInput(ctx, "IP address \"" + userIp + "\" is not valid.");
|
||||
return;
|
||||
|
@ -2,6 +2,7 @@ package net.frozenorb.apiv3.route.users;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import io.vertx.core.Handler;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
import net.frozenorb.apiv3.APIv3;
|
||||
import net.frozenorb.apiv3.model.NotificationTemplate;
|
||||
@ -9,7 +10,6 @@ import net.frozenorb.apiv3.model.User;
|
||||
import net.frozenorb.apiv3.unsorted.Notification;
|
||||
import net.frozenorb.apiv3.util.ErrorUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class POSTUserNotify implements Handler<RoutingContext> {
|
||||
@ -27,24 +27,16 @@ public final class POSTUserNotify implements Handler<RoutingContext> {
|
||||
return;
|
||||
}
|
||||
|
||||
NotificationTemplate template = NotificationTemplate.findByIdSync(ctx.request().getParam("template"));
|
||||
JsonObject requestBody = ctx.getBodyAsJson();
|
||||
NotificationTemplate template = NotificationTemplate.findByIdSync(requestBody.getString("template"));
|
||||
|
||||
if (template == null) {
|
||||
ErrorUtils.respondNotFound(ctx, "Notification template", ctx.request().getParam("template"));
|
||||
ErrorUtils.respondNotFound(ctx, "Notification template", requestBody.getString("template"));
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, Object> subjectReplacements = new HashMap<>();
|
||||
Map<String, Object> bodyReplacements = new HashMap<>();
|
||||
|
||||
//TODO: Probably make this use the body as json
|
||||
/*req.queryMap("subject").toMap().forEach((key, values) -> {
|
||||
subjectReplacements.put(key, values[0]);
|
||||
});
|
||||
|
||||
req.queryMap("body").toMap().forEach((key, values) -> {
|
||||
bodyReplacements.put(key, values[0]);
|
||||
});*/
|
||||
Map<String, Object> subjectReplacements = requestBody.getJsonObject("subjectReplacements").getMap();
|
||||
Map<String, Object> bodyReplacements = requestBody.getJsonObject("subjectReplacements").getMap();
|
||||
|
||||
Notification notification = new Notification(template, subjectReplacements, bodyReplacements);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user