Modify APIv3#respondJson to not have default status code
This commit is contained in:
parent
bcd95d9e9b
commit
968ceb1a1d
@ -129,6 +129,8 @@ public final class APIv3 extends AbstractVerticle {
|
||||
converter.startImport((ignored, error) -> {
|
||||
if (error != null) {
|
||||
error.printStackTrace();
|
||||
} else {
|
||||
log.info("Finished conversion!");
|
||||
}
|
||||
});*/
|
||||
}
|
||||
@ -351,16 +353,12 @@ public final class APIv3 extends AbstractVerticle {
|
||||
webServer.requestHandler(http::accept).listen(port);
|
||||
}
|
||||
|
||||
public static void respondJson(RoutingContext ctx, Object response) {
|
||||
respondJson(ctx, 200, response);
|
||||
}
|
||||
|
||||
public static void respondJson(RoutingContext ctx, int code, Object response) {
|
||||
ctx.response().putHeader(HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8.toString());
|
||||
ctx.response().setStatusCode(code);
|
||||
|
||||
if (!ctx.request().path().contains("dumps")) {
|
||||
log.info(gson.toJson(response));
|
||||
//log.info(gson.toJson(response));
|
||||
}
|
||||
|
||||
ctx.response().end(gson.toJson(response));
|
||||
|
@ -4,7 +4,6 @@ import com.google.common.collect.ImmutableMap;
|
||||
import com.mongodb.async.SingleResultCallback;
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.frozenorb.apiv3.actor.Actor;
|
||||
import net.frozenorb.apiv3.model.AuditLogEntry;
|
||||
|
||||
import java.util.Map;
|
||||
@ -14,19 +13,11 @@ import java.util.UUID;
|
||||
public class AuditLog {
|
||||
|
||||
public static void log(UUID performedBy, String performedByIp, RoutingContext ctx, AuditLogActionType actionType, SingleResultCallback<AuditLogEntry> callback) {
|
||||
log(performedBy, performedByIp, ctx.get("actor"), ctx.request().remoteAddress().host(), actionType, ImmutableMap.of(), callback);
|
||||
log(performedBy, performedByIp, ctx, actionType, ImmutableMap.of(), callback);
|
||||
}
|
||||
|
||||
public static void log(UUID performedBy, String performedByIp, RoutingContext ctx, AuditLogActionType actionType, Map<String, Object> actionData, SingleResultCallback<AuditLogEntry> callback) {
|
||||
log(performedBy, performedByIp, ctx.get("actor"), ctx.request().remoteAddress().host(), actionType, actionData, callback);
|
||||
}
|
||||
|
||||
public static void log(UUID performedBy, String performedByIp, Actor actor, String actorIp, AuditLogActionType actionType, SingleResultCallback<AuditLogEntry> callback) {
|
||||
log(performedBy, performedByIp, actor, actorIp, actionType, ImmutableMap.of(), callback);
|
||||
}
|
||||
|
||||
public static void log(UUID performedBy, String performedByIp, Actor actor, String actorIp, AuditLogActionType actionType, Map<String, Object> actionData, SingleResultCallback<AuditLogEntry> callback) {
|
||||
AuditLogEntry entry = new AuditLogEntry(performedBy, performedByIp, actor,actorIp, actionType, actionData);
|
||||
AuditLogEntry entry = new AuditLogEntry(performedBy, performedByIp, ctx.get("actor"), ctx.request().remoteAddress().host(), actionType, actionData);
|
||||
entry.insert((ignored, error) -> {
|
||||
if (error != null) {
|
||||
callback.onResult(null, error);
|
||||
|
@ -10,7 +10,7 @@ import net.frozenorb.apiv3.dataImport.converters.GrantConverter;
|
||||
import net.frozenorb.apiv3.dataImport.converters.IpLogConverter;
|
||||
import net.frozenorb.apiv3.dataImport.converters.PunishmentConverter;
|
||||
import net.frozenorb.apiv3.dataImport.converters.UserConverter;
|
||||
import net.frozenorb.apiv3.unsorted.FutureCompatibilityCallback;
|
||||
import net.frozenorb.apiv3.unsorted.MongoToVertxCallback;
|
||||
import org.bson.types.ObjectId;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -39,9 +39,9 @@ public final class V2Importer {
|
||||
Future<Void> grantsFuture = Future.future();
|
||||
Future<Void> ipLogFuture = Future.future();
|
||||
|
||||
importFrom.getCollection("punishment").find().forEach(new PunishmentConverter(oidToUniqueId), new FutureCompatibilityCallback<>(punishmentsFuture));
|
||||
importFrom.getCollection("grant").find().forEach(new GrantConverter(oidToUniqueId), new FutureCompatibilityCallback<>(grantsFuture));
|
||||
importFrom.getCollection("iplog").find().forEach(new IpLogConverter(oidToUniqueId), new FutureCompatibilityCallback<>(ipLogFuture));
|
||||
importFrom.getCollection("punishment").find().forEach(new PunishmentConverter(oidToUniqueId), new MongoToVertxCallback<>(punishmentsFuture));
|
||||
importFrom.getCollection("grant").find().forEach(new GrantConverter(oidToUniqueId), new MongoToVertxCallback<>(grantsFuture));
|
||||
importFrom.getCollection("iplog").find().forEach(new IpLogConverter(oidToUniqueId), new MongoToVertxCallback<>(ipLogFuture));
|
||||
|
||||
CompositeFuture.all(punishmentsFuture, grantsFuture, ipLogFuture).setHandler((result) -> {
|
||||
if (result.succeeded()) {
|
||||
|
@ -5,6 +5,7 @@ import io.vertx.ext.web.RoutingContext;
|
||||
import io.vertx.redis.RedisClient;
|
||||
import io.vertx.redis.RedisOptions;
|
||||
import net.frozenorb.apiv3.APIv3;
|
||||
import net.frozenorb.apiv3.actor.Actor;
|
||||
|
||||
public final class MetricsHandler implements Handler<RoutingContext> {
|
||||
|
||||
@ -19,19 +20,21 @@ public final class MetricsHandler implements Handler<RoutingContext> {
|
||||
redisClient.incr("apiv3:requests:total", (totalUpdateResult) -> {
|
||||
if (totalUpdateResult.failed()) {
|
||||
totalUpdateResult.cause().printStackTrace();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
redisClient.incr("apiv3:requests:method:" + ctx.request().method(), (methodUpdateResult) -> {
|
||||
if (methodUpdateResult.failed()) {
|
||||
methodUpdateResult.cause().printStackTrace();
|
||||
} else {
|
||||
redisClient.incr("apiv3:requests:actor:" + ctx.get("actor").getClass().getSimpleName(), (actorUpdateResult) -> {
|
||||
return;
|
||||
}
|
||||
|
||||
redisClient.incr("apiv3:requests:actor:" + ((Actor) ctx.get("actor")).getType(), (actorUpdateResult) -> {
|
||||
if (actorUpdateResult.failed()) {
|
||||
actorUpdateResult.cause().printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
ctx.next();
|
||||
|
@ -24,7 +24,7 @@ import net.frozenorb.apiv3.maxmind.MaxMindUserType;
|
||||
import net.frozenorb.apiv3.serialization.gson.ExcludeFromReplies;
|
||||
import net.frozenorb.apiv3.serialization.jackson.UuidJsonDeserializer;
|
||||
import net.frozenorb.apiv3.serialization.jackson.UuidJsonSerializer;
|
||||
import net.frozenorb.apiv3.unsorted.FutureCompatibilityCallback;
|
||||
import net.frozenorb.apiv3.unsorted.MongoToVertxCallback;
|
||||
import net.frozenorb.apiv3.unsorted.Permissions;
|
||||
import net.frozenorb.apiv3.unsorted.RequiresTotpResult;
|
||||
import net.frozenorb.apiv3.unsorted.TotpAuthorizationResult;
|
||||
@ -214,17 +214,17 @@ public final class User {
|
||||
Punishment.PunishmentType.BLACKLIST,
|
||||
Punishment.PunishmentType.BAN,
|
||||
Punishment.PunishmentType.MUTE
|
||||
), new FutureCompatibilityCallback<>(punishmentsFuture));
|
||||
), new MongoToVertxCallback<>(punishmentsFuture));
|
||||
|
||||
if (userIp != null) {
|
||||
IpIntel.findOrCreateById(userIp, new FutureCompatibilityCallback<>(ipIntelFuture));
|
||||
IpBan.findByIp(userIp, new FutureCompatibilityCallback<>(ipBansFuture));
|
||||
IpIntel.findOrCreateById(userIp, new MongoToVertxCallback<>(ipIntelFuture));
|
||||
IpBan.findByIp(userIp, new MongoToVertxCallback<>(ipBansFuture));
|
||||
} else {
|
||||
ipIntelFuture.complete(null);
|
||||
ipBansFuture.complete(ImmutableList.of());
|
||||
}
|
||||
|
||||
Grant.findByUser(this, new FutureCompatibilityCallback<>(grantsFuture));
|
||||
Grant.findByUser(this, new MongoToVertxCallback<>(grantsFuture));
|
||||
|
||||
CompositeFuture.all(punishmentsFuture, ipIntelFuture, ipBansFuture, grantsFuture).setHandler((result) -> {
|
||||
if (result.succeeded()) {
|
||||
@ -456,8 +456,8 @@ public final class User {
|
||||
Future<Void> markPreAuthFuture = Future.future();
|
||||
Future<Void> markRecentlyUsedFuture = Future.future();
|
||||
|
||||
TotpUtils.markPreAuthorized(this, ip, 3, TimeUnit.DAYS, new FutureCompatibilityCallback<>(markPreAuthFuture));
|
||||
TotpUtils.markRecentlyUsed(this, code, new FutureCompatibilityCallback<>(markRecentlyUsedFuture));
|
||||
TotpUtils.markPreAuthorized(this, ip, 3, TimeUnit.DAYS, new MongoToVertxCallback<>(markPreAuthFuture));
|
||||
TotpUtils.markRecentlyUsed(this, code, new MongoToVertxCallback<>(markRecentlyUsedFuture));
|
||||
|
||||
CompositeFuture.all(markPreAuthFuture, markRecentlyUsedFuture).setHandler((result) -> {
|
||||
if (result.failed()) {
|
||||
|
@ -33,7 +33,7 @@ public final class GETDumpsType implements Handler<RoutingContext> {
|
||||
|
||||
for (Punishment punishment : punishments) {
|
||||
if (!punishment.isActive()) {
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (punishment.getType() == Punishment.PunishmentType.BAN) {
|
||||
@ -57,7 +57,7 @@ public final class GETDumpsType implements Handler<RoutingContext> {
|
||||
|
||||
for (Grant grant : grants) {
|
||||
if (!grant.isActive()) {
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
List<UUID> users = grantCache.get(grant.getRank());
|
||||
@ -80,10 +80,10 @@ public final class GETDumpsType implements Handler<RoutingContext> {
|
||||
|
||||
switch (dumpType.toLowerCase()) {
|
||||
case "ban":
|
||||
APIv3.respondJson(ctx, banCache);
|
||||
APIv3.respondJson(ctx, 200, banCache);
|
||||
return;
|
||||
case "blacklist":
|
||||
APIv3.respondJson(ctx, blacklistCache);
|
||||
APIv3.respondJson(ctx, 200, blacklistCache);
|
||||
return;
|
||||
case "accessdeniable": // Lowercase d because we convert to lowercase above
|
||||
List<UUID> result = new LinkedList<>();
|
||||
@ -91,10 +91,10 @@ public final class GETDumpsType implements Handler<RoutingContext> {
|
||||
result.addAll(banCache);
|
||||
result.addAll(blacklistCache);
|
||||
|
||||
APIv3.respondJson(ctx, result);
|
||||
APIv3.respondJson(ctx, 200, result);
|
||||
return;
|
||||
case "grant":
|
||||
APIv3.respondJson(ctx, grantCache);
|
||||
APIv3.respondJson(ctx, 200, grantCache);
|
||||
return;
|
||||
default:
|
||||
ErrorUtils.respondInvalidInput(ctx, dumpType + " is not a valid type. Not in [ban, blacklist, accessDeniable, grant]");
|
||||
|
@ -11,7 +11,7 @@ public final class GETWhoAmI implements Handler<RoutingContext> {
|
||||
public void handle(RoutingContext ctx) {
|
||||
Actor actor = ctx.get("actor");
|
||||
|
||||
APIv3.respondJson(ctx, ImmutableMap.of(
|
||||
APIv3.respondJson(ctx, 200, ImmutableMap.of(
|
||||
"name", actor.getName(),
|
||||
"type", actor.getType(),
|
||||
"authorized", actor.isAuthorized()
|
||||
|
@ -37,11 +37,11 @@ public final class DELETEAccessTokensId implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, accessToken);
|
||||
APIv3.respondJson(ctx, 200, accessToken);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
APIv3.respondJson(ctx, accessToken);
|
||||
APIv3.respondJson(ctx, 200, accessToken);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ public final class GETAccessTokens implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, accessTokens);
|
||||
APIv3.respondJson(ctx, 200, accessTokens);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ public final class GETAccessTokensId implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, accessToken);
|
||||
APIv3.respondJson(ctx, 200, accessToken);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public final class POSTAccessTokens implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, accessToken);
|
||||
APIv3.respondJson(ctx, 200, accessToken);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -41,11 +41,11 @@ public final class DELETEAuditLogId implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, auditLogEntry);
|
||||
APIv3.respondJson(ctx, 200, auditLogEntry);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
APIv3.respondJson(ctx, auditLogEntry);
|
||||
APIv3.respondJson(ctx, 200, auditLogEntry);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ public final class GETAuditLog implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, auditLog);
|
||||
APIv3.respondJson(ctx, 200, auditLog);
|
||||
}
|
||||
});
|
||||
} catch (NumberFormatException ignored) {
|
||||
|
@ -46,7 +46,7 @@ public final class POSTAuditLog implements Handler<RoutingContext> {
|
||||
if (error2 != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error2);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, auditLogEntry);
|
||||
APIv3.respondJson(ctx, 200, auditLogEntry);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -35,11 +35,11 @@ public final class DELETEBannedAsnsId implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, bannedAsn);
|
||||
APIv3.respondJson(ctx, 200, bannedAsn);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
APIv3.respondJson(ctx, bannedAsn);
|
||||
APIv3.respondJson(ctx, 200, bannedAsn);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ import net.frozenorb.apiv3.model.BannedAsn;
|
||||
public final class GETBannedAsns implements Handler<RoutingContext> {
|
||||
|
||||
public void handle(RoutingContext ctx) {
|
||||
APIv3.respondJson(ctx, BannedAsn.findAll());
|
||||
APIv3.respondJson(ctx, 200, BannedAsn.findAll());
|
||||
}
|
||||
|
||||
}
|
@ -8,7 +8,7 @@ import net.frozenorb.apiv3.model.BannedAsn;
|
||||
public final class GETBannedAsnsId implements Handler<RoutingContext> {
|
||||
|
||||
public void handle(RoutingContext ctx) {
|
||||
APIv3.respondJson(ctx, BannedAsn.findById(Integer.parseInt(ctx.request().getParam("bannedAsn"))));
|
||||
APIv3.respondJson(ctx, 200, BannedAsn.findById(Integer.parseInt(ctx.request().getParam("bannedAsn"))));
|
||||
}
|
||||
|
||||
}
|
@ -30,11 +30,11 @@ public final class POSTBannedAsns implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, bannedAsn);
|
||||
APIv3.respondJson(ctx, 200, bannedAsn);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
APIv3.respondJson(ctx, bannedAsn);
|
||||
APIv3.respondJson(ctx, 200, bannedAsn);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,11 +35,11 @@ public final class DELETEBannedCellCarriersId implements Handler<RoutingContext>
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, bannedCellCarrier);
|
||||
APIv3.respondJson(ctx, 200, bannedCellCarrier);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
APIv3.respondJson(ctx, bannedCellCarrier);
|
||||
APIv3.respondJson(ctx, 200, bannedCellCarrier);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ import net.frozenorb.apiv3.model.BannedCellCarrier;
|
||||
public final class GETBannedCellCarriers implements Handler<RoutingContext> {
|
||||
|
||||
public void handle(RoutingContext ctx) {
|
||||
APIv3.respondJson(ctx, BannedCellCarrier.findAll());
|
||||
APIv3.respondJson(ctx, 200, BannedCellCarrier.findAll());
|
||||
}
|
||||
|
||||
}
|
@ -8,7 +8,7 @@ import net.frozenorb.apiv3.model.BannedCellCarrier;
|
||||
public final class GETBannedCellCarriersId implements Handler<RoutingContext> {
|
||||
|
||||
public void handle(RoutingContext ctx) {
|
||||
APIv3.respondJson(ctx, BannedCellCarrier.findById(Integer.parseInt(ctx.request().getParam("bannedCellCarrier"))));
|
||||
APIv3.respondJson(ctx, 200, BannedCellCarrier.findById(Integer.parseInt(ctx.request().getParam("bannedCellCarrier"))));
|
||||
}
|
||||
|
||||
}
|
@ -30,11 +30,11 @@ public final class POSTBannedCellCarriers implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, bannedCellCarrier);
|
||||
APIv3.respondJson(ctx, 200, bannedCellCarrier);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
APIv3.respondJson(ctx, bannedCellCarrier);
|
||||
APIv3.respondJson(ctx, 200, bannedCellCarrier);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ public final class GETChatFilter implements Handler<RoutingContext> {
|
||||
public void handle(RoutingContext ctx) {
|
||||
// TODO
|
||||
// WARNING: THIS IS REGISTERED ASYNC SO DONT MESS IT UP
|
||||
APIv3.respondJson(ctx, ImmutableList.of());
|
||||
APIv3.respondJson(ctx, 200, ImmutableList.of());
|
||||
}
|
||||
|
||||
}
|
@ -13,7 +13,7 @@ public final class GETEmailTokensIdOwner implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, user);
|
||||
APIv3.respondJson(ctx, 200, user);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public final class POSTEmailTokensIdConfirm implements Handler<RoutingContext> {
|
||||
}
|
||||
|
||||
if (user.getEmail() != null) {
|
||||
ErrorUtils.respondGeneric(ctx, 400, "User provided already has email set.");
|
||||
ErrorUtils.respondGeneric(ctx, 409, "User provided already has email set.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ public final class POSTEmailTokensIdConfirm implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, ImmutableMap.of(
|
||||
APIv3.respondJson(ctx, 200, ImmutableMap.of(
|
||||
"success", true
|
||||
));
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ public final class DELETEGrantsId implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, grant);
|
||||
APIv3.respondJson(ctx, 200, grant);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ public final class GETGrants implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, grants);
|
||||
APIv3.respondJson(ctx, 200, grants);
|
||||
}
|
||||
});
|
||||
} catch (NumberFormatException ignored) {
|
||||
|
@ -13,7 +13,7 @@ public final class GETGrantsId implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, grant);
|
||||
APIv3.respondJson(ctx, 200, grant);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -101,11 +101,11 @@ public final class POSTGrants implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, grant);
|
||||
APIv3.respondJson(ctx, 200, grant);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
APIv3.respondJson(ctx, grant);
|
||||
APIv3.respondJson(ctx, 200, grant);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ public final class DELETEIpBansId implements Handler<RoutingContext> {
|
||||
BlockingCallback<AuditLogEntry> blockingCallback = new BlockingCallback<>();
|
||||
AuditLog.log(removedBy.getId(), requestBody.getString("removedByIp"), ctx, AuditLogActionType.IP_BAN_DELETE, ImmutableMap.of("punishmentId", ipBan.getId()), blockingCallback);
|
||||
blockingCallback.get();
|
||||
APIv3.respondJson(ctx, ipBan);
|
||||
APIv3.respondJson(ctx, 200, ipBan);
|
||||
}
|
||||
|
||||
}
|
@ -18,7 +18,7 @@ public final class GETIpBans implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, grants);
|
||||
APIv3.respondJson(ctx, 200, grants);
|
||||
}
|
||||
});
|
||||
} catch (NumberFormatException ignored) {
|
||||
|
@ -13,7 +13,7 @@ public final class GETIpBansId implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, ipBan);
|
||||
APIv3.respondJson(ctx, 200, ipBan);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -59,11 +59,11 @@ public final class POSTIpBans implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, ipBan);
|
||||
APIv3.respondJson(ctx, 200, ipBan);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
APIv3.respondJson(ctx, ipBan);
|
||||
APIv3.respondJson(ctx, 200, ipBan);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ public final class GETIpInteld implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, ipIntel);
|
||||
APIv3.respondJson(ctx, 200, ipIntel);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ public final class GETIpLogId implements Handler<RoutingContext> {
|
||||
if (error2 != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error2);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, ipLog);
|
||||
APIv3.respondJson(ctx, 200, ipLog);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -37,11 +37,11 @@ public final class DELETENotificationTemplatesId implements Handler<RoutingConte
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, notificationTemplate);
|
||||
APIv3.respondJson(ctx, 200, notificationTemplate);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
APIv3.respondJson(ctx, notificationTemplate);
|
||||
APIv3.respondJson(ctx, 200, notificationTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ public final class GETNotificationTemplates implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, notificationTemplates);
|
||||
APIv3.respondJson(ctx, 200, notificationTemplates);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ public final class GETNotificationTemplatesId implements Handler<RoutingContext>
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, notificationTemplate);
|
||||
APIv3.respondJson(ctx, 200, notificationTemplate);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -31,11 +31,11 @@ public final class POSTNotificationTemplates implements Handler<RoutingContext>
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, notificationTemplate);
|
||||
APIv3.respondJson(ctx, 200, notificationTemplate);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
APIv3.respondJson(ctx, notificationTemplate);
|
||||
APIv3.respondJson(ctx, 200, notificationTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ public final class GETPhoneInteld implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, ipIntel);
|
||||
APIv3.respondJson(ctx, 200, ipIntel);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public final class DELETEPunishmentsId implements Handler<RoutingContext> {
|
||||
BlockingCallback<AuditLogEntry> blockingCallback = new BlockingCallback<>();
|
||||
AuditLog.log(removedBy.getId(), requestBody.getString("removedByIp"), ctx, AuditLogActionType.PUNISHMENT_DELETE, ImmutableMap.of("punishmentId", punishment.getId()), blockingCallback);
|
||||
blockingCallback.get();
|
||||
APIv3.respondJson(ctx, punishment);
|
||||
APIv3.respondJson(ctx, 200, punishment);
|
||||
}
|
||||
|
||||
}
|
@ -60,7 +60,7 @@ public final class DELETEUsersIdActivePunishment implements Handler<RoutingConte
|
||||
}
|
||||
|
||||
if (activePunishment == null) {
|
||||
ErrorUtils.respondGeneric(ctx, 404, "User provided has no active punishments");
|
||||
ErrorUtils.respondGeneric(ctx, 409, "User provided has no active punishments");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ public final class DELETEUsersIdActivePunishment implements Handler<RoutingConte
|
||||
AuditLog.log(removedBy.getId(), requestBody.getString("removedByIp"), ctx, AuditLogActionType.PUNISHMENT_DELETE, ImmutableMap.of("punishmentId", activePunishment.getId()), blockingCallback);
|
||||
blockingCallback.get();
|
||||
|
||||
APIv3.respondJson(ctx, activePunishment);
|
||||
APIv3.respondJson(ctx, 200, activePunishment);
|
||||
}
|
||||
|
||||
}
|
@ -18,7 +18,7 @@ public final class GETPunishments implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, grants);
|
||||
APIv3.respondJson(ctx, 200, grants);
|
||||
}
|
||||
});
|
||||
} catch (NumberFormatException ignored) {
|
||||
|
@ -13,7 +13,7 @@ public final class GETPunishmentsId implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, punishment);
|
||||
APIv3.respondJson(ctx, 200, punishment);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ public final class POSTPunishments implements Handler<RoutingContext> {
|
||||
if (punishment.isActive()) {
|
||||
BlockingCallback<User> addedByCallback = new BlockingCallback<>();
|
||||
User.findById(punishment.getAddedBy(), addedByCallback);
|
||||
ErrorUtils.respondGeneric(ctx, 200, "A punishment by " + addedByCallback.get().getLastUsername() + " already covers this user.");
|
||||
ErrorUtils.respondGeneric(ctx, 409, "A punishment by " + addedByCallback.get().getLastUsername() + " already covers this user.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -82,7 +82,7 @@ public final class POSTPunishments implements Handler<RoutingContext> {
|
||||
target.hasPermissionAnywhere(Permissions.PROTECTED_PUNISHMENT, permissionsCallback);
|
||||
|
||||
if (permissionsCallback.get()) {
|
||||
ErrorUtils.respondGeneric(ctx, 200, target.getLastSeenOn() + " is protected from punishments.");
|
||||
ErrorUtils.respondGeneric(ctx, 409, target.getLastSeenOn() + " is protected from punishments.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -108,14 +108,14 @@ public final class POSTPunishments implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, ImmutableMap.of(
|
||||
APIv3.respondJson(ctx, 200, ImmutableMap.of(
|
||||
"punishment", punishment,
|
||||
"accessDenialReason", accessDenialReason == null ? "" : accessDenialReason
|
||||
));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
APIv3.respondJson(ctx, ImmutableMap.of(
|
||||
APIv3.respondJson(ctx, 200, ImmutableMap.of(
|
||||
"punishment", punishment,
|
||||
"accessDenialReason", accessDenialReason == null ? "" : accessDenialReason
|
||||
));
|
||||
|
@ -35,11 +35,11 @@ public final class DELETERanksId implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, rank);
|
||||
APIv3.respondJson(ctx, 200, rank);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
APIv3.respondJson(ctx, rank);
|
||||
APIv3.respondJson(ctx, 200, rank);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ import net.frozenorb.apiv3.model.Rank;
|
||||
public final class GETRanks implements Handler<RoutingContext> {
|
||||
|
||||
public void handle(RoutingContext ctx) {
|
||||
APIv3.respondJson(ctx, Rank.findAll());
|
||||
APIv3.respondJson(ctx, 200, Rank.findAll());
|
||||
}
|
||||
|
||||
}
|
@ -8,7 +8,7 @@ import net.frozenorb.apiv3.model.Rank;
|
||||
public final class GETRanksId implements Handler<RoutingContext> {
|
||||
|
||||
public void handle(RoutingContext ctx) {
|
||||
APIv3.respondJson(ctx, Rank.findById(ctx.request().getParam("rankId")));
|
||||
APIv3.respondJson(ctx, 200, Rank.findById(ctx.request().getParam("rankId")));
|
||||
}
|
||||
|
||||
}
|
@ -36,11 +36,11 @@ public final class POSTRanks implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, rank);
|
||||
APIv3.respondJson(ctx, 200, rank);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
APIv3.respondJson(ctx, rank);
|
||||
APIv3.respondJson(ctx, 200, rank);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,11 +35,11 @@ public final class DELETEServerGroupsId implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, serverGroup);
|
||||
APIv3.respondJson(ctx, 200, serverGroup);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
APIv3.respondJson(ctx, serverGroup);
|
||||
APIv3.respondJson(ctx, 200, serverGroup);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ import net.frozenorb.apiv3.model.ServerGroup;
|
||||
public final class GETServerGroups implements Handler<RoutingContext> {
|
||||
|
||||
public void handle(RoutingContext ctx) {
|
||||
APIv3.respondJson(ctx, ServerGroup.findAll());
|
||||
APIv3.respondJson(ctx, 200, ServerGroup.findAll());
|
||||
}
|
||||
|
||||
}
|
@ -8,7 +8,7 @@ import net.frozenorb.apiv3.model.ServerGroup;
|
||||
public final class GETServerGroupsId implements Handler<RoutingContext> {
|
||||
|
||||
public void handle(RoutingContext ctx) {
|
||||
APIv3.respondJson(ctx, ServerGroup.findById(ctx.request().getParam("serverGroupId")));
|
||||
APIv3.respondJson(ctx, 200, ServerGroup.findById(ctx.request().getParam("serverGroupId")));
|
||||
}
|
||||
|
||||
}
|
@ -30,11 +30,11 @@ public final class POSTServerGroups implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, serverGroup);
|
||||
APIv3.respondJson(ctx, 200, serverGroup);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
APIv3.respondJson(ctx, serverGroup);
|
||||
APIv3.respondJson(ctx, 200, serverGroup);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,11 +49,11 @@ public final class DELETEServersId implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, server);
|
||||
APIv3.respondJson(ctx, 200, server);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
APIv3.respondJson(ctx, server);
|
||||
APIv3.respondJson(ctx, 200, server);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ import net.frozenorb.apiv3.model.Server;
|
||||
public final class GETServers implements Handler<RoutingContext> {
|
||||
|
||||
public void handle(RoutingContext ctx) {
|
||||
APIv3.respondJson(ctx, Server.findAll());
|
||||
APIv3.respondJson(ctx, 200, Server.findAll());
|
||||
}
|
||||
|
||||
}
|
@ -8,7 +8,7 @@ import net.frozenorb.apiv3.model.Server;
|
||||
public final class GETServersId implements Handler<RoutingContext> {
|
||||
|
||||
public void handle(RoutingContext ctx) {
|
||||
APIv3.respondJson(ctx, Server.findById(ctx.request().getParam("serverId")));
|
||||
APIv3.respondJson(ctx, 200, Server.findById(ctx.request().getParam("serverId")));
|
||||
}
|
||||
|
||||
}
|
@ -50,11 +50,11 @@ public final class POSTServers implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, server);
|
||||
APIv3.respondJson(ctx, 200, server);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
APIv3.respondJson(ctx, server);
|
||||
APIv3.respondJson(ctx, 200, server);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ import net.frozenorb.apiv3.APIv3;
|
||||
import net.frozenorb.apiv3.actor.Actor;
|
||||
import net.frozenorb.apiv3.actor.ActorType;
|
||||
import net.frozenorb.apiv3.model.*;
|
||||
import net.frozenorb.apiv3.unsorted.FutureCompatibilityCallback;
|
||||
import net.frozenorb.apiv3.unsorted.MongoToVertxCallback;
|
||||
import net.frozenorb.apiv3.util.ErrorUtils;
|
||||
import net.frozenorb.apiv3.util.PermissionUtils;
|
||||
import net.frozenorb.apiv3.util.UuidUtils;
|
||||
@ -30,7 +30,7 @@ public final class POSTServersHeartbeat implements Handler<RoutingContext> {
|
||||
Actor actor = ctx.get("actor");
|
||||
|
||||
if (actor.getType() != ActorType.SERVER) {
|
||||
ErrorUtils.respondGeneric(ctx, 400, "This action can only be performed when requested by a server.");
|
||||
ErrorUtils.respondGeneric(ctx, 403, "This action can only be performed when requested by a server.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ public final class POSTServersHeartbeat implements Handler<RoutingContext> {
|
||||
if (result.succeeded()) {
|
||||
// We don't do anything with the info callback, as
|
||||
// it's just to update our database.
|
||||
APIv3.respondJson(ctx, ImmutableMap.of(
|
||||
APIv3.respondJson(ctx, 200, ImmutableMap.of(
|
||||
"players", result.result().result(1),
|
||||
"permissions", result.result().result(2),
|
||||
"events", result.result().result(3)
|
||||
@ -81,9 +81,9 @@ public final class POSTServersHeartbeat implements Handler<RoutingContext> {
|
||||
Future<Map<UUID, List<Grant>>> grantLookupCallback = Future.future();
|
||||
Future<Map<UUID, List<Punishment>>> punishmentLookupCallback = Future.future();
|
||||
|
||||
User.findOrCreateByIdGrouped(playerNames, new FutureCompatibilityCallback<>(userLookupCallback));
|
||||
Grant.findByUserGrouped(playerNames.keySet(), new FutureCompatibilityCallback<>(grantLookupCallback));
|
||||
Punishment.findByUserGrouped(playerNames.keySet(), new FutureCompatibilityCallback<>(punishmentLookupCallback));
|
||||
User.findOrCreateByIdGrouped(playerNames, new MongoToVertxCallback<>(userLookupCallback));
|
||||
Grant.findByUserGrouped(playerNames.keySet(), new MongoToVertxCallback<>(grantLookupCallback));
|
||||
Punishment.findByUserGrouped(playerNames.keySet(), new MongoToVertxCallback<>(punishmentLookupCallback));
|
||||
|
||||
CompositeFuture.all(
|
||||
userLookupCallback,
|
||||
@ -179,10 +179,10 @@ public final class POSTServersHeartbeat implements Handler<RoutingContext> {
|
||||
}
|
||||
|
||||
// TODO: IP BAN INFO (AND FOR LINE BELOW)
|
||||
user.getLoginInfo(server, null, punishments, ImmutableList.of(), grants, new FutureCompatibilityCallback<>(callback));
|
||||
user.getLoginInfo(server, null, punishments, ImmutableList.of(), grants, new MongoToVertxCallback<>(callback));
|
||||
});
|
||||
} else {
|
||||
user.getLoginInfo(server, null, punishments, ImmutableList.of(), grants, new FutureCompatibilityCallback<>(callback));
|
||||
user.getLoginInfo(server, null, punishments, ImmutableList.of(), grants, new MongoToVertxCallback<>(callback));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ public final class GETStaff implements Handler<RoutingContext> {
|
||||
}
|
||||
});
|
||||
|
||||
APIv3.respondJson(ctx, result);
|
||||
APIv3.respondJson(ctx, 200, result);
|
||||
}
|
||||
|
||||
}
|
@ -13,7 +13,7 @@ public final class GETUsersId implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, user);
|
||||
APIv3.respondJson(ctx, 200, user);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ public final class GETUsersIdCompoundedPermissions implements Handler<RoutingCon
|
||||
if (error2 != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error2);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, PermissionUtils.convertToList(permissions));
|
||||
APIv3.respondJson(ctx, 200, PermissionUtils.convertToList(permissions));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ public final class GETUsersIdDetails implements Handler<RoutingContext> {
|
||||
result.put("aliases", user.getAliases());
|
||||
result.put("totpSetup", user.getTotpSecret() != null);
|
||||
|
||||
APIv3.respondJson(ctx, result);
|
||||
APIv3.respondJson(ctx, 200, result);
|
||||
}
|
||||
|
||||
}
|
@ -34,7 +34,7 @@ public final class GETUsersIdRequiresTotp implements Handler<RoutingContext> {
|
||||
if (error2 != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error2);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, ImmutableMap.of(
|
||||
APIv3.respondJson(ctx, 200, ImmutableMap.of(
|
||||
"required", (requiresTotpResult == RequiresTotpResult.REQUIRED_NO_EXEMPTIONS),
|
||||
"message", requiresTotpResult.name()
|
||||
));
|
||||
|
@ -48,7 +48,7 @@ public final class GETUsersIdVerifyPassword implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, ImmutableMap.of(
|
||||
APIv3.respondJson(ctx, 200, ImmutableMap.of(
|
||||
"authorized", authorized,
|
||||
"uuid", finalUuid
|
||||
));
|
||||
|
@ -57,7 +57,7 @@ public final class POSTUsersIdChangePassword implements Handler<RoutingContext>
|
||||
authorized = true;
|
||||
} else if (user.getPasswordResetToken() != null && user.getPasswordResetToken().equals(requestBody.getString("passwordResetToken"))) {
|
||||
if ((System.currentTimeMillis() - user.getPasswordResetTokenSetAt().toEpochMilli()) > TimeUnit.DAYS.toMillis(2)) {
|
||||
ErrorUtils.respondGeneric(ctx, 200, "Password reset token is expired");
|
||||
ErrorUtils.respondGeneric(ctx, 409, "Password reset token is expired");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ public final class POSTUsersIdChangePassword implements Handler<RoutingContext>
|
||||
String newPassword = requestBody.getString("newPassword");
|
||||
|
||||
if (newPassword.length() < 8) {
|
||||
ErrorUtils.respondGeneric(ctx, 200, "Your password is too short.");
|
||||
ErrorUtils.respondInvalidInput(ctx, "Password is too short.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -85,7 +85,7 @@ public final class POSTUsersIdChangePassword implements Handler<RoutingContext>
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, ImmutableMap.of(
|
||||
APIv3.respondJson(ctx, 200, ImmutableMap.of(
|
||||
"success", true
|
||||
));
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ public final class POSTUsersIdConfirmPhone implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, ImmutableMap.of(
|
||||
APIv3.respondJson(ctx, 200, ImmutableMap.of(
|
||||
"success", true
|
||||
));
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ public class POSTUsersIdLeave implements Handler<RoutingContext> {
|
||||
Actor actor = ctx.get("actor");
|
||||
|
||||
if (actor.getType() != ActorType.SERVER) {
|
||||
ErrorUtils.respondGeneric(ctx, 400, "This action can only be performed when requested by a server.");
|
||||
ErrorUtils.respondGeneric(ctx, 403, "This action can only be performed when requested by a server.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ public class POSTUsersIdLeave implements Handler<RoutingContext> {
|
||||
if (error2 != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error2);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, user);
|
||||
APIv3.respondJson(ctx, 200, user);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public final class POSTUsersIdLogin implements Handler<RoutingContext> {
|
||||
Actor actor = ctx.get("actor");
|
||||
|
||||
if (actor.getType() != ActorType.SERVER) {
|
||||
ErrorUtils.respondGeneric(ctx, 400, "This action can only be performed when requested by a server.");
|
||||
ErrorUtils.respondGeneric(ctx, 403, "This action can only be performed when requested by a server.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ public final class POSTUsersIdLogin implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, loginInfo);
|
||||
APIv3.respondJson(ctx, 200, loginInfo);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ public final class POSTUsersIdNotify implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, ImmutableMap.of(
|
||||
APIv3.respondJson(ctx, 200, ImmutableMap.of(
|
||||
"success", true
|
||||
));
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ public final class POSTUsersIdPasswordReset implements Handler<RoutingContext> {
|
||||
if (error2 != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error2);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, ImmutableMap.of(
|
||||
APIv3.respondJson(ctx, 200, ImmutableMap.of(
|
||||
"success", true
|
||||
));
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ public final class POSTUsersIdRegisterEmail implements Handler<RoutingContext> {
|
||||
if (error2 != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error2);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, ImmutableMap.of(
|
||||
APIv3.respondJson(ctx, 200, ImmutableMap.of(
|
||||
"success", true
|
||||
));
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ public final class POSTUsersIdRegisterPhone implements Handler<RoutingContext> {
|
||||
if (error2 != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error2);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, ImmutableMap.of(
|
||||
APIv3.respondJson(ctx, 200, ImmutableMap.of(
|
||||
"success", true
|
||||
));
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public final class POSTUsersIdSetupTotp implements Handler<RoutingContext> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, ImmutableMap.of(
|
||||
APIv3.respondJson(ctx, 200, ImmutableMap.of(
|
||||
"success", true,
|
||||
"message", "Totp code set."
|
||||
));
|
||||
|
@ -48,7 +48,7 @@ public final class POSTUsersIdVerifyTotp implements Handler<RoutingContext> {
|
||||
if (error3 != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error3);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, ImmutableMap.of(
|
||||
APIv3.respondJson(ctx, 200, ImmutableMap.of(
|
||||
"authorized", totpAuthorizationResult.isAuthorized(),
|
||||
"message", totpAuthorizationResult.name()
|
||||
));
|
||||
|
@ -3,11 +3,11 @@ package net.frozenorb.apiv3.unsorted;
|
||||
import com.mongodb.async.SingleResultCallback;
|
||||
import io.vertx.core.Future;
|
||||
|
||||
public class FutureCompatibilityCallback<T> implements SingleResultCallback<T> {
|
||||
public class MongoToVertxCallback<T> implements SingleResultCallback<T> {
|
||||
|
||||
private final Future<T> future;
|
||||
|
||||
public FutureCompatibilityCallback(Future<T> future) {
|
||||
public MongoToVertxCallback(Future<T> future) {
|
||||
this.future = future;
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public class EmailUtils {
|
||||
}
|
||||
|
||||
public static boolean isBannedEmailDomain(String email) {
|
||||
if (email == null) {
|
||||
if (!isValidEmail(email)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ public class EmailUtils {
|
||||
}
|
||||
|
||||
public static boolean isValidEmail(String email) {
|
||||
return VALID_EMAIL_PATTERN.matcher(email).matches();
|
||||
return email != null && VALID_EMAIL_PATTERN.matcher(email).matches();
|
||||
}
|
||||
|
||||
}
|
@ -17,7 +17,7 @@ public class ErrorUtils {
|
||||
}
|
||||
|
||||
public static void respondRequiredInput(RoutingContext ctx, String field) {
|
||||
respondGeneric(ctx, 400, "Field \"" + field + "\" is required.");
|
||||
respondGeneric(ctx, 400, "Required input: " + field + " is required.");
|
||||
}
|
||||
|
||||
public static void respondInternalError(RoutingContext ctx, Throwable error) {
|
||||
|
@ -8,13 +8,12 @@ import java.util.regex.Pattern;
|
||||
public class PhoneUtils {
|
||||
|
||||
private static final Pattern VALID_PHONE_PATTERN = Pattern.compile(
|
||||
"^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$",
|
||||
"^(+1|1)?([2-9]\\d\\d[2-9]\\d{6})$",
|
||||
Pattern.CASE_INSENSITIVE
|
||||
);
|
||||
|
||||
public static boolean isValidPhone(String phoneNumber) {
|
||||
return true; // TODO
|
||||
//return VALID_EMAIL_PATTERN.matcher(email).matches();
|
||||
return phoneNumber != null && VALID_PHONE_PATTERN.matcher(phoneNumber).matches();
|
||||
}
|
||||
|
||||
}
|
@ -48,19 +48,13 @@ public class TotpUtils {
|
||||
|
||||
String key = user.getId() + ":preAuthorizedIp:" + ip.toLowerCase();
|
||||
|
||||
redisClient.set(key, "", (result) -> {
|
||||
redisClient.setex(key, unit.toSeconds(duration), "", (result) -> {
|
||||
if (result.succeeded()) {
|
||||
redisClient.expire(key, (int) unit.toSeconds(duration), (result2) -> {
|
||||
if (result2.succeeded()) {
|
||||
callback.onResult(null, null);
|
||||
} else {
|
||||
callback.onResult(null, result.cause());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
callback.onResult(null, result.cause());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void wasRecentlyUsed(User user, int code, SingleResultCallback<Boolean> callback) {
|
||||
@ -76,19 +70,13 @@ public class TotpUtils {
|
||||
public static void markRecentlyUsed(User user, int code, SingleResultCallback<Void> callback) {
|
||||
String key = user.getId() + ":recentTotpCodes:" + code;
|
||||
|
||||
redisClient.set(key, "", (result) -> {
|
||||
redisClient.setex(key, TimeUnit.MINUTES.toSeconds(5), "", (result) -> {
|
||||
if (result.succeeded()) {
|
||||
redisClient.expire(key, (int) TimeUnit.MINUTES.toSeconds(5), (result2) -> {
|
||||
if (result2.succeeded()) {
|
||||
callback.onResult(null, null);
|
||||
} else {
|
||||
callback.onResult(null, result.cause());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
callback.onResult(null, result.cause());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user