Modify APIv3#respondJson to not have default status code

This commit is contained in:
Colin McDonald 2016-06-29 21:23:37 -04:00
parent bcd95d9e9b
commit 968ceb1a1d
79 changed files with 148 additions and 169 deletions

View File

@ -129,6 +129,8 @@ public final class APIv3 extends AbstractVerticle {
converter.startImport((ignored, error) -> { converter.startImport((ignored, error) -> {
if (error != null) { if (error != null) {
error.printStackTrace(); error.printStackTrace();
} else {
log.info("Finished conversion!");
} }
});*/ });*/
} }
@ -351,16 +353,12 @@ public final class APIv3 extends AbstractVerticle {
webServer.requestHandler(http::accept).listen(port); 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) { public static void respondJson(RoutingContext ctx, int code, Object response) {
ctx.response().putHeader(HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8.toString()); ctx.response().putHeader(HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8.toString());
ctx.response().setStatusCode(code); ctx.response().setStatusCode(code);
if (!ctx.request().path().contains("dumps")) { if (!ctx.request().path().contains("dumps")) {
log.info(gson.toJson(response)); //log.info(gson.toJson(response));
} }
ctx.response().end(gson.toJson(response)); ctx.response().end(gson.toJson(response));

View File

@ -4,7 +4,6 @@ import com.google.common.collect.ImmutableMap;
import com.mongodb.async.SingleResultCallback; import com.mongodb.async.SingleResultCallback;
import io.vertx.ext.web.RoutingContext; import io.vertx.ext.web.RoutingContext;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import net.frozenorb.apiv3.actor.Actor;
import net.frozenorb.apiv3.model.AuditLogEntry; import net.frozenorb.apiv3.model.AuditLogEntry;
import java.util.Map; import java.util.Map;
@ -14,19 +13,11 @@ import java.util.UUID;
public class AuditLog { public class AuditLog {
public static void log(UUID performedBy, String performedByIp, RoutingContext ctx, AuditLogActionType actionType, SingleResultCallback<AuditLogEntry> callback) { 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) { 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); AuditLogEntry entry = new AuditLogEntry(performedBy, performedByIp, ctx.get("actor"), ctx.request().remoteAddress().host(), actionType, actionData);
}
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);
entry.insert((ignored, error) -> { entry.insert((ignored, error) -> {
if (error != null) { if (error != null) {
callback.onResult(null, error); callback.onResult(null, error);

View File

@ -10,7 +10,7 @@ import net.frozenorb.apiv3.dataImport.converters.GrantConverter;
import net.frozenorb.apiv3.dataImport.converters.IpLogConverter; import net.frozenorb.apiv3.dataImport.converters.IpLogConverter;
import net.frozenorb.apiv3.dataImport.converters.PunishmentConverter; import net.frozenorb.apiv3.dataImport.converters.PunishmentConverter;
import net.frozenorb.apiv3.dataImport.converters.UserConverter; 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 org.bson.types.ObjectId;
import java.util.HashMap; import java.util.HashMap;
@ -39,9 +39,9 @@ public final class V2Importer {
Future<Void> grantsFuture = Future.future(); Future<Void> grantsFuture = Future.future();
Future<Void> ipLogFuture = Future.future(); Future<Void> ipLogFuture = Future.future();
importFrom.getCollection("punishment").find().forEach(new PunishmentConverter(oidToUniqueId), new FutureCompatibilityCallback<>(punishmentsFuture)); importFrom.getCollection("punishment").find().forEach(new PunishmentConverter(oidToUniqueId), new MongoToVertxCallback<>(punishmentsFuture));
importFrom.getCollection("grant").find().forEach(new GrantConverter(oidToUniqueId), new FutureCompatibilityCallback<>(grantsFuture)); importFrom.getCollection("grant").find().forEach(new GrantConverter(oidToUniqueId), new MongoToVertxCallback<>(grantsFuture));
importFrom.getCollection("iplog").find().forEach(new IpLogConverter(oidToUniqueId), new FutureCompatibilityCallback<>(ipLogFuture)); importFrom.getCollection("iplog").find().forEach(new IpLogConverter(oidToUniqueId), new MongoToVertxCallback<>(ipLogFuture));
CompositeFuture.all(punishmentsFuture, grantsFuture, ipLogFuture).setHandler((result) -> { CompositeFuture.all(punishmentsFuture, grantsFuture, ipLogFuture).setHandler((result) -> {
if (result.succeeded()) { if (result.succeeded()) {

View File

@ -5,6 +5,7 @@ import io.vertx.ext.web.RoutingContext;
import io.vertx.redis.RedisClient; import io.vertx.redis.RedisClient;
import io.vertx.redis.RedisOptions; import io.vertx.redis.RedisOptions;
import net.frozenorb.apiv3.APIv3; import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.actor.Actor;
public final class MetricsHandler implements Handler<RoutingContext> { public final class MetricsHandler implements Handler<RoutingContext> {
@ -19,19 +20,21 @@ public final class MetricsHandler implements Handler<RoutingContext> {
redisClient.incr("apiv3:requests:total", (totalUpdateResult) -> { redisClient.incr("apiv3:requests:total", (totalUpdateResult) -> {
if (totalUpdateResult.failed()) { if (totalUpdateResult.failed()) {
totalUpdateResult.cause().printStackTrace(); totalUpdateResult.cause().printStackTrace();
} else { return;
redisClient.incr("apiv3:requests:method:" + ctx.request().method(), (methodUpdateResult) -> { }
if (methodUpdateResult.failed()) {
methodUpdateResult.cause().printStackTrace(); redisClient.incr("apiv3:requests:method:" + ctx.request().method(), (methodUpdateResult) -> {
} else { if (methodUpdateResult.failed()) {
redisClient.incr("apiv3:requests:actor:" + ctx.get("actor").getClass().getSimpleName(), (actorUpdateResult) -> { methodUpdateResult.cause().printStackTrace();
if (actorUpdateResult.failed()) { return;
actorUpdateResult.cause().printStackTrace(); }
}
}); redisClient.incr("apiv3:requests:actor:" + ((Actor) ctx.get("actor")).getType(), (actorUpdateResult) -> {
if (actorUpdateResult.failed()) {
actorUpdateResult.cause().printStackTrace();
} }
}); });
} });
}); });
ctx.next(); ctx.next();

View File

@ -24,7 +24,7 @@ import net.frozenorb.apiv3.maxmind.MaxMindUserType;
import net.frozenorb.apiv3.serialization.gson.ExcludeFromReplies; import net.frozenorb.apiv3.serialization.gson.ExcludeFromReplies;
import net.frozenorb.apiv3.serialization.jackson.UuidJsonDeserializer; import net.frozenorb.apiv3.serialization.jackson.UuidJsonDeserializer;
import net.frozenorb.apiv3.serialization.jackson.UuidJsonSerializer; 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.Permissions;
import net.frozenorb.apiv3.unsorted.RequiresTotpResult; import net.frozenorb.apiv3.unsorted.RequiresTotpResult;
import net.frozenorb.apiv3.unsorted.TotpAuthorizationResult; import net.frozenorb.apiv3.unsorted.TotpAuthorizationResult;
@ -214,17 +214,17 @@ public final class User {
Punishment.PunishmentType.BLACKLIST, Punishment.PunishmentType.BLACKLIST,
Punishment.PunishmentType.BAN, Punishment.PunishmentType.BAN,
Punishment.PunishmentType.MUTE Punishment.PunishmentType.MUTE
), new FutureCompatibilityCallback<>(punishmentsFuture)); ), new MongoToVertxCallback<>(punishmentsFuture));
if (userIp != null) { if (userIp != null) {
IpIntel.findOrCreateById(userIp, new FutureCompatibilityCallback<>(ipIntelFuture)); IpIntel.findOrCreateById(userIp, new MongoToVertxCallback<>(ipIntelFuture));
IpBan.findByIp(userIp, new FutureCompatibilityCallback<>(ipBansFuture)); IpBan.findByIp(userIp, new MongoToVertxCallback<>(ipBansFuture));
} else { } else {
ipIntelFuture.complete(null); ipIntelFuture.complete(null);
ipBansFuture.complete(ImmutableList.of()); ipBansFuture.complete(ImmutableList.of());
} }
Grant.findByUser(this, new FutureCompatibilityCallback<>(grantsFuture)); Grant.findByUser(this, new MongoToVertxCallback<>(grantsFuture));
CompositeFuture.all(punishmentsFuture, ipIntelFuture, ipBansFuture, grantsFuture).setHandler((result) -> { CompositeFuture.all(punishmentsFuture, ipIntelFuture, ipBansFuture, grantsFuture).setHandler((result) -> {
if (result.succeeded()) { if (result.succeeded()) {
@ -456,8 +456,8 @@ public final class User {
Future<Void> markPreAuthFuture = Future.future(); Future<Void> markPreAuthFuture = Future.future();
Future<Void> markRecentlyUsedFuture = Future.future(); Future<Void> markRecentlyUsedFuture = Future.future();
TotpUtils.markPreAuthorized(this, ip, 3, TimeUnit.DAYS, new FutureCompatibilityCallback<>(markPreAuthFuture)); TotpUtils.markPreAuthorized(this, ip, 3, TimeUnit.DAYS, new MongoToVertxCallback<>(markPreAuthFuture));
TotpUtils.markRecentlyUsed(this, code, new FutureCompatibilityCallback<>(markRecentlyUsedFuture)); TotpUtils.markRecentlyUsed(this, code, new MongoToVertxCallback<>(markRecentlyUsedFuture));
CompositeFuture.all(markPreAuthFuture, markRecentlyUsedFuture).setHandler((result) -> { CompositeFuture.all(markPreAuthFuture, markRecentlyUsedFuture).setHandler((result) -> {
if (result.failed()) { if (result.failed()) {

View File

@ -33,7 +33,7 @@ public final class GETDumpsType implements Handler<RoutingContext> {
for (Punishment punishment : punishments) { for (Punishment punishment : punishments) {
if (!punishment.isActive()) { if (!punishment.isActive()) {
return; continue;
} }
if (punishment.getType() == Punishment.PunishmentType.BAN) { if (punishment.getType() == Punishment.PunishmentType.BAN) {
@ -57,7 +57,7 @@ public final class GETDumpsType implements Handler<RoutingContext> {
for (Grant grant : grants) { for (Grant grant : grants) {
if (!grant.isActive()) { if (!grant.isActive()) {
return; continue;
} }
List<UUID> users = grantCache.get(grant.getRank()); List<UUID> users = grantCache.get(grant.getRank());
@ -80,10 +80,10 @@ public final class GETDumpsType implements Handler<RoutingContext> {
switch (dumpType.toLowerCase()) { switch (dumpType.toLowerCase()) {
case "ban": case "ban":
APIv3.respondJson(ctx, banCache); APIv3.respondJson(ctx, 200, banCache);
return; return;
case "blacklist": case "blacklist":
APIv3.respondJson(ctx, blacklistCache); APIv3.respondJson(ctx, 200, blacklistCache);
return; return;
case "accessdeniable": // Lowercase d because we convert to lowercase above case "accessdeniable": // Lowercase d because we convert to lowercase above
List<UUID> result = new LinkedList<>(); List<UUID> result = new LinkedList<>();
@ -91,10 +91,10 @@ public final class GETDumpsType implements Handler<RoutingContext> {
result.addAll(banCache); result.addAll(banCache);
result.addAll(blacklistCache); result.addAll(blacklistCache);
APIv3.respondJson(ctx, result); APIv3.respondJson(ctx, 200, result);
return; return;
case "grant": case "grant":
APIv3.respondJson(ctx, grantCache); APIv3.respondJson(ctx, 200, grantCache);
return; return;
default: default:
ErrorUtils.respondInvalidInput(ctx, dumpType + " is not a valid type. Not in [ban, blacklist, accessDeniable, grant]"); ErrorUtils.respondInvalidInput(ctx, dumpType + " is not a valid type. Not in [ban, blacklist, accessDeniable, grant]");

View File

@ -11,7 +11,7 @@ public final class GETWhoAmI implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) { public void handle(RoutingContext ctx) {
Actor actor = ctx.get("actor"); Actor actor = ctx.get("actor");
APIv3.respondJson(ctx, ImmutableMap.of( APIv3.respondJson(ctx, 200, ImmutableMap.of(
"name", actor.getName(), "name", actor.getName(),
"type", actor.getType(), "type", actor.getType(),
"authorized", actor.isAuthorized() "authorized", actor.isAuthorized()

View File

@ -37,11 +37,11 @@ public final class DELETEAccessTokensId implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, accessToken); APIv3.respondJson(ctx, 200, accessToken);
} }
}); });
} else { } else {
APIv3.respondJson(ctx, accessToken); APIv3.respondJson(ctx, 200, accessToken);
} }
} }

View File

@ -35,7 +35,7 @@ public final class GETAccessTokens implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, accessTokens); APIv3.respondJson(ctx, 200, accessTokens);
} }
}); });
} }

View File

@ -13,7 +13,7 @@ public final class GETAccessTokensId implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, accessToken); APIv3.respondJson(ctx, 200, accessToken);
} }
}); });
} }

View File

@ -52,7 +52,7 @@ public final class POSTAccessTokens implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, accessToken); APIv3.respondJson(ctx, 200, accessToken);
} }
}); });
} }

View File

@ -41,11 +41,11 @@ public final class DELETEAuditLogId implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, auditLogEntry); APIv3.respondJson(ctx, 200, auditLogEntry);
} }
}); });
} else { } else {
APIv3.respondJson(ctx, auditLogEntry); APIv3.respondJson(ctx, 200, auditLogEntry);
} }
} }

View File

@ -19,7 +19,7 @@ public final class GETAuditLog implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, auditLog); APIv3.respondJson(ctx, 200, auditLog);
} }
}); });
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {

View File

@ -46,7 +46,7 @@ public final class POSTAuditLog implements Handler<RoutingContext> {
if (error2 != null) { if (error2 != null) {
ErrorUtils.respondInternalError(ctx, error2); ErrorUtils.respondInternalError(ctx, error2);
} else { } else {
APIv3.respondJson(ctx, auditLogEntry); APIv3.respondJson(ctx, 200, auditLogEntry);
} }
}); });
}); });

View File

@ -35,11 +35,11 @@ public final class DELETEBannedAsnsId implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, bannedAsn); APIv3.respondJson(ctx, 200, bannedAsn);
} }
}); });
} else { } else {
APIv3.respondJson(ctx, bannedAsn); APIv3.respondJson(ctx, 200, bannedAsn);
} }
} }

View File

@ -8,7 +8,7 @@ import net.frozenorb.apiv3.model.BannedAsn;
public final class GETBannedAsns implements Handler<RoutingContext> { public final class GETBannedAsns implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) { public void handle(RoutingContext ctx) {
APIv3.respondJson(ctx, BannedAsn.findAll()); APIv3.respondJson(ctx, 200, BannedAsn.findAll());
} }
} }

View File

@ -8,7 +8,7 @@ import net.frozenorb.apiv3.model.BannedAsn;
public final class GETBannedAsnsId implements Handler<RoutingContext> { public final class GETBannedAsnsId implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) { 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"))));
} }
} }

View File

@ -30,11 +30,11 @@ public final class POSTBannedAsns implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, bannedAsn); APIv3.respondJson(ctx, 200, bannedAsn);
} }
}); });
} else { } else {
APIv3.respondJson(ctx, bannedAsn); APIv3.respondJson(ctx, 200, bannedAsn);
} }
} }

View File

@ -35,11 +35,11 @@ public final class DELETEBannedCellCarriersId implements Handler<RoutingContext>
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, bannedCellCarrier); APIv3.respondJson(ctx, 200, bannedCellCarrier);
} }
}); });
} else { } else {
APIv3.respondJson(ctx, bannedCellCarrier); APIv3.respondJson(ctx, 200, bannedCellCarrier);
} }
} }

View File

@ -8,7 +8,7 @@ import net.frozenorb.apiv3.model.BannedCellCarrier;
public final class GETBannedCellCarriers implements Handler<RoutingContext> { public final class GETBannedCellCarriers implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) { public void handle(RoutingContext ctx) {
APIv3.respondJson(ctx, BannedCellCarrier.findAll()); APIv3.respondJson(ctx, 200, BannedCellCarrier.findAll());
} }
} }

View File

@ -8,7 +8,7 @@ import net.frozenorb.apiv3.model.BannedCellCarrier;
public final class GETBannedCellCarriersId implements Handler<RoutingContext> { public final class GETBannedCellCarriersId implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) { 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"))));
} }
} }

View File

@ -30,11 +30,11 @@ public final class POSTBannedCellCarriers implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, bannedCellCarrier); APIv3.respondJson(ctx, 200, bannedCellCarrier);
} }
}); });
} else { } else {
APIv3.respondJson(ctx, bannedCellCarrier); APIv3.respondJson(ctx, 200, bannedCellCarrier);
} }
} }

View File

@ -10,7 +10,7 @@ public final class GETChatFilter implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) { public void handle(RoutingContext ctx) {
// TODO // TODO
// WARNING: THIS IS REGISTERED ASYNC SO DONT MESS IT UP // WARNING: THIS IS REGISTERED ASYNC SO DONT MESS IT UP
APIv3.respondJson(ctx, ImmutableList.of()); APIv3.respondJson(ctx, 200, ImmutableList.of());
} }
} }

View File

@ -13,7 +13,7 @@ public final class GETEmailTokensIdOwner implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, user); APIv3.respondJson(ctx, 200, user);
} }
}); });
} }

View File

@ -27,7 +27,7 @@ public final class POSTEmailTokensIdConfirm implements Handler<RoutingContext> {
} }
if (user.getEmail() != null) { 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; return;
} }
@ -54,7 +54,7 @@ public final class POSTEmailTokensIdConfirm implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, ImmutableMap.of( APIv3.respondJson(ctx, 200, ImmutableMap.of(
"success", true "success", true
)); ));
} }

View File

@ -49,11 +49,11 @@ public final class DELETEGrantsId implements Handler<RoutingContext> {
grant.delete(removedBy, reason, callback); grant.delete(removedBy, reason, callback);
callback.get(); callback.get();
AuditLog.log(removedBy.getId(), requestBody.getString("removedByIp"), ctx, AuditLogActionType.GRANT_DELETE,ImmutableMap.of("grantId", grant.getId()), (ignored, error) -> { AuditLog.log(removedBy.getId(), requestBody.getString("removedByIp"), ctx, AuditLogActionType.GRANT_DELETE, ImmutableMap.of("grantId", grant.getId()), (ignored, error) -> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, grant); APIv3.respondJson(ctx, 200, grant);
} }
}); });
} }

View File

@ -18,7 +18,7 @@ public final class GETGrants implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, grants); APIv3.respondJson(ctx, 200, grants);
} }
}); });
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {

View File

@ -13,7 +13,7 @@ public final class GETGrantsId implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, grant); APIv3.respondJson(ctx, 200, grant);
} }
}); });
} }

View File

@ -101,11 +101,11 @@ public final class POSTGrants implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, grant); APIv3.respondJson(ctx, 200, grant);
} }
}); });
} else { } else {
APIv3.respondJson(ctx, grant); APIv3.respondJson(ctx, 200, grant);
} }
} }

View File

@ -52,7 +52,7 @@ public final class DELETEIpBansId implements Handler<RoutingContext> {
BlockingCallback<AuditLogEntry> blockingCallback = new BlockingCallback<>(); BlockingCallback<AuditLogEntry> blockingCallback = new BlockingCallback<>();
AuditLog.log(removedBy.getId(), requestBody.getString("removedByIp"), ctx, AuditLogActionType.IP_BAN_DELETE, ImmutableMap.of("punishmentId", ipBan.getId()), blockingCallback); AuditLog.log(removedBy.getId(), requestBody.getString("removedByIp"), ctx, AuditLogActionType.IP_BAN_DELETE, ImmutableMap.of("punishmentId", ipBan.getId()), blockingCallback);
blockingCallback.get(); blockingCallback.get();
APIv3.respondJson(ctx, ipBan); APIv3.respondJson(ctx, 200, ipBan);
} }
} }

View File

@ -18,7 +18,7 @@ public final class GETIpBans implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, grants); APIv3.respondJson(ctx, 200, grants);
} }
}); });
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {

View File

@ -13,7 +13,7 @@ public final class GETIpBansId implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, ipBan); APIv3.respondJson(ctx, 200, ipBan);
} }
}); });
} }

View File

@ -59,11 +59,11 @@ public final class POSTIpBans implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, ipBan); APIv3.respondJson(ctx, 200, ipBan);
} }
}); });
} else { } else {
APIv3.respondJson(ctx, ipBan); APIv3.respondJson(ctx, 200, ipBan);
} }
} }

View File

@ -21,7 +21,7 @@ public final class GETIpInteld implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, ipIntel); APIv3.respondJson(ctx, 200, ipIntel);
} }
}); });
} }

View File

@ -20,7 +20,7 @@ public final class GETIpLogId implements Handler<RoutingContext> {
if (error2 != null) { if (error2 != null) {
ErrorUtils.respondInternalError(ctx, error2); ErrorUtils.respondInternalError(ctx, error2);
} else { } else {
APIv3.respondJson(ctx, ipLog); APIv3.respondJson(ctx, 200, ipLog);
} }
}); });
} }

View File

@ -37,11 +37,11 @@ public final class DELETENotificationTemplatesId implements Handler<RoutingConte
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, notificationTemplate); APIv3.respondJson(ctx, 200, notificationTemplate);
} }
}); });
} else { } else {
APIv3.respondJson(ctx, notificationTemplate); APIv3.respondJson(ctx, 200, notificationTemplate);
} }
} }

View File

@ -13,7 +13,7 @@ public final class GETNotificationTemplates implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, notificationTemplates); APIv3.respondJson(ctx, 200, notificationTemplates);
} }
}); });
} }

View File

@ -13,7 +13,7 @@ public final class GETNotificationTemplatesId implements Handler<RoutingContext>
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, notificationTemplate); APIv3.respondJson(ctx, 200, notificationTemplate);
} }
}); });
} }

View File

@ -31,11 +31,11 @@ public final class POSTNotificationTemplates implements Handler<RoutingContext>
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, notificationTemplate); APIv3.respondJson(ctx, 200, notificationTemplate);
} }
}); });
} else { } else {
APIv3.respondJson(ctx, notificationTemplate); APIv3.respondJson(ctx, 200, notificationTemplate);
} }
} }

View File

@ -21,7 +21,7 @@ public final class GETPhoneInteld implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, ipIntel); APIv3.respondJson(ctx, 200, ipIntel);
} }
}); });
} }

View File

@ -52,7 +52,7 @@ public final class DELETEPunishmentsId implements Handler<RoutingContext> {
BlockingCallback<AuditLogEntry> blockingCallback = new BlockingCallback<>(); BlockingCallback<AuditLogEntry> blockingCallback = new BlockingCallback<>();
AuditLog.log(removedBy.getId(), requestBody.getString("removedByIp"), ctx, AuditLogActionType.PUNISHMENT_DELETE, ImmutableMap.of("punishmentId", punishment.getId()), blockingCallback); AuditLog.log(removedBy.getId(), requestBody.getString("removedByIp"), ctx, AuditLogActionType.PUNISHMENT_DELETE, ImmutableMap.of("punishmentId", punishment.getId()), blockingCallback);
blockingCallback.get(); blockingCallback.get();
APIv3.respondJson(ctx, punishment); APIv3.respondJson(ctx, 200, punishment);
} }
} }

View File

@ -60,7 +60,7 @@ public final class DELETEUsersIdActivePunishment implements Handler<RoutingConte
} }
if (activePunishment == null) { if (activePunishment == null) {
ErrorUtils.respondGeneric(ctx, 404, "User provided has no active punishments"); ErrorUtils.respondGeneric(ctx, 409, "User provided has no active punishments");
return; 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); AuditLog.log(removedBy.getId(), requestBody.getString("removedByIp"), ctx, AuditLogActionType.PUNISHMENT_DELETE, ImmutableMap.of("punishmentId", activePunishment.getId()), blockingCallback);
blockingCallback.get(); blockingCallback.get();
APIv3.respondJson(ctx, activePunishment); APIv3.respondJson(ctx, 200, activePunishment);
} }
} }

View File

@ -18,7 +18,7 @@ public final class GETPunishments implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, grants); APIv3.respondJson(ctx, 200, grants);
} }
}); });
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {

View File

@ -13,7 +13,7 @@ public final class GETPunishmentsId implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, punishment); APIv3.respondJson(ctx, 200, punishment);
} }
}); });
} }

View File

@ -49,7 +49,7 @@ public final class POSTPunishments implements Handler<RoutingContext> {
if (punishment.isActive()) { if (punishment.isActive()) {
BlockingCallback<User> addedByCallback = new BlockingCallback<>(); BlockingCallback<User> addedByCallback = new BlockingCallback<>();
User.findById(punishment.getAddedBy(), addedByCallback); 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; return;
} }
} }
@ -82,7 +82,7 @@ public final class POSTPunishments implements Handler<RoutingContext> {
target.hasPermissionAnywhere(Permissions.PROTECTED_PUNISHMENT, permissionsCallback); target.hasPermissionAnywhere(Permissions.PROTECTED_PUNISHMENT, permissionsCallback);
if (permissionsCallback.get()) { if (permissionsCallback.get()) {
ErrorUtils.respondGeneric(ctx, 200, target.getLastSeenOn() + " is protected from punishments."); ErrorUtils.respondGeneric(ctx, 409, target.getLastSeenOn() + " is protected from punishments.");
return; return;
} }
@ -108,14 +108,14 @@ public final class POSTPunishments implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, ImmutableMap.of( APIv3.respondJson(ctx, 200, ImmutableMap.of(
"punishment", punishment, "punishment", punishment,
"accessDenialReason", accessDenialReason == null ? "" : accessDenialReason "accessDenialReason", accessDenialReason == null ? "" : accessDenialReason
)); ));
} }
}); });
} else { } else {
APIv3.respondJson(ctx, ImmutableMap.of( APIv3.respondJson(ctx, 200, ImmutableMap.of(
"punishment", punishment, "punishment", punishment,
"accessDenialReason", accessDenialReason == null ? "" : accessDenialReason "accessDenialReason", accessDenialReason == null ? "" : accessDenialReason
)); ));

View File

@ -35,11 +35,11 @@ public final class DELETERanksId implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, rank); APIv3.respondJson(ctx, 200, rank);
} }
}); });
} else { } else {
APIv3.respondJson(ctx, rank); APIv3.respondJson(ctx, 200, rank);
} }
} }

View File

@ -8,7 +8,7 @@ import net.frozenorb.apiv3.model.Rank;
public final class GETRanks implements Handler<RoutingContext> { public final class GETRanks implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) { public void handle(RoutingContext ctx) {
APIv3.respondJson(ctx, Rank.findAll()); APIv3.respondJson(ctx, 200, Rank.findAll());
} }
} }

View File

@ -8,7 +8,7 @@ import net.frozenorb.apiv3.model.Rank;
public final class GETRanksId implements Handler<RoutingContext> { public final class GETRanksId implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) { public void handle(RoutingContext ctx) {
APIv3.respondJson(ctx, Rank.findById(ctx.request().getParam("rankId"))); APIv3.respondJson(ctx, 200, Rank.findById(ctx.request().getParam("rankId")));
} }
} }

View File

@ -36,11 +36,11 @@ public final class POSTRanks implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, rank); APIv3.respondJson(ctx, 200, rank);
} }
}); });
} else { } else {
APIv3.respondJson(ctx, rank); APIv3.respondJson(ctx, 200, rank);
} }
} }

View File

@ -35,11 +35,11 @@ public final class DELETEServerGroupsId implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, serverGroup); APIv3.respondJson(ctx, 200, serverGroup);
} }
}); });
} else { } else {
APIv3.respondJson(ctx, serverGroup); APIv3.respondJson(ctx, 200, serverGroup);
} }
} }

View File

@ -8,7 +8,7 @@ import net.frozenorb.apiv3.model.ServerGroup;
public final class GETServerGroups implements Handler<RoutingContext> { public final class GETServerGroups implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) { public void handle(RoutingContext ctx) {
APIv3.respondJson(ctx, ServerGroup.findAll()); APIv3.respondJson(ctx, 200, ServerGroup.findAll());
} }
} }

View File

@ -8,7 +8,7 @@ import net.frozenorb.apiv3.model.ServerGroup;
public final class GETServerGroupsId implements Handler<RoutingContext> { public final class GETServerGroupsId implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) { public void handle(RoutingContext ctx) {
APIv3.respondJson(ctx, ServerGroup.findById(ctx.request().getParam("serverGroupId"))); APIv3.respondJson(ctx, 200, ServerGroup.findById(ctx.request().getParam("serverGroupId")));
} }
} }

View File

@ -30,11 +30,11 @@ public final class POSTServerGroups implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, serverGroup); APIv3.respondJson(ctx, 200, serverGroup);
} }
}); });
} else { } else {
APIv3.respondJson(ctx, serverGroup); APIv3.respondJson(ctx, 200, serverGroup);
} }
} }

View File

@ -49,11 +49,11 @@ public final class DELETEServersId implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, server); APIv3.respondJson(ctx, 200, server);
} }
}); });
} else { } else {
APIv3.respondJson(ctx, server); APIv3.respondJson(ctx, 200, server);
} }
} }

View File

@ -8,7 +8,7 @@ import net.frozenorb.apiv3.model.Server;
public final class GETServers implements Handler<RoutingContext> { public final class GETServers implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) { public void handle(RoutingContext ctx) {
APIv3.respondJson(ctx, Server.findAll()); APIv3.respondJson(ctx, 200, Server.findAll());
} }
} }

View File

@ -8,7 +8,7 @@ import net.frozenorb.apiv3.model.Server;
public final class GETServersId implements Handler<RoutingContext> { public final class GETServersId implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) { public void handle(RoutingContext ctx) {
APIv3.respondJson(ctx, Server.findById(ctx.request().getParam("serverId"))); APIv3.respondJson(ctx, 200, Server.findById(ctx.request().getParam("serverId")));
} }
} }

View File

@ -50,11 +50,11 @@ public final class POSTServers implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, server); APIv3.respondJson(ctx, 200, server);
} }
}); });
} else { } else {
APIv3.respondJson(ctx, server); APIv3.respondJson(ctx, 200, server);
} }
} }

View File

@ -13,7 +13,7 @@ import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.actor.Actor; import net.frozenorb.apiv3.actor.Actor;
import net.frozenorb.apiv3.actor.ActorType; import net.frozenorb.apiv3.actor.ActorType;
import net.frozenorb.apiv3.model.*; 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.ErrorUtils;
import net.frozenorb.apiv3.util.PermissionUtils; import net.frozenorb.apiv3.util.PermissionUtils;
import net.frozenorb.apiv3.util.UuidUtils; import net.frozenorb.apiv3.util.UuidUtils;
@ -30,7 +30,7 @@ public final class POSTServersHeartbeat implements Handler<RoutingContext> {
Actor actor = ctx.get("actor"); Actor actor = ctx.get("actor");
if (actor.getType() != ActorType.SERVER) { 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; return;
} }
@ -48,7 +48,7 @@ public final class POSTServersHeartbeat implements Handler<RoutingContext> {
if (result.succeeded()) { if (result.succeeded()) {
// We don't do anything with the info callback, as // We don't do anything with the info callback, as
// it's just to update our database. // it's just to update our database.
APIv3.respondJson(ctx, ImmutableMap.of( APIv3.respondJson(ctx, 200, ImmutableMap.of(
"players", result.result().result(1), "players", result.result().result(1),
"permissions", result.result().result(2), "permissions", result.result().result(2),
"events", result.result().result(3) "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<Grant>>> grantLookupCallback = Future.future();
Future<Map<UUID, List<Punishment>>> punishmentLookupCallback = Future.future(); Future<Map<UUID, List<Punishment>>> punishmentLookupCallback = Future.future();
User.findOrCreateByIdGrouped(playerNames, new FutureCompatibilityCallback<>(userLookupCallback)); User.findOrCreateByIdGrouped(playerNames, new MongoToVertxCallback<>(userLookupCallback));
Grant.findByUserGrouped(playerNames.keySet(), new FutureCompatibilityCallback<>(grantLookupCallback)); Grant.findByUserGrouped(playerNames.keySet(), new MongoToVertxCallback<>(grantLookupCallback));
Punishment.findByUserGrouped(playerNames.keySet(), new FutureCompatibilityCallback<>(punishmentLookupCallback)); Punishment.findByUserGrouped(playerNames.keySet(), new MongoToVertxCallback<>(punishmentLookupCallback));
CompositeFuture.all( CompositeFuture.all(
userLookupCallback, userLookupCallback,
@ -179,10 +179,10 @@ public final class POSTServersHeartbeat implements Handler<RoutingContext> {
} }
// TODO: IP BAN INFO (AND FOR LINE BELOW) // 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 { } else {
user.getLoginInfo(server, null, punishments, ImmutableList.of(), grants, new FutureCompatibilityCallback<>(callback)); user.getLoginInfo(server, null, punishments, ImmutableList.of(), grants, new MongoToVertxCallback<>(callback));
} }
} }

View File

@ -46,7 +46,7 @@ public final class GETStaff implements Handler<RoutingContext> {
} }
}); });
APIv3.respondJson(ctx, result); APIv3.respondJson(ctx, 200, result);
} }
} }

View File

@ -13,7 +13,7 @@ public final class GETUsersId implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, user); APIv3.respondJson(ctx, 200, user);
} }
}); });
} }

View File

@ -20,7 +20,7 @@ public final class GETUsersIdCompoundedPermissions implements Handler<RoutingCon
if (error2 != null) { if (error2 != null) {
ErrorUtils.respondInternalError(ctx, error2); ErrorUtils.respondInternalError(ctx, error2);
} else { } else {
APIv3.respondJson(ctx, PermissionUtils.convertToList(permissions)); APIv3.respondJson(ctx, 200, PermissionUtils.convertToList(permissions));
} }
}); });
} }

View File

@ -43,7 +43,7 @@ public final class GETUsersIdDetails implements Handler<RoutingContext> {
result.put("aliases", user.getAliases()); result.put("aliases", user.getAliases());
result.put("totpSetup", user.getTotpSecret() != null); result.put("totpSetup", user.getTotpSecret() != null);
APIv3.respondJson(ctx, result); APIv3.respondJson(ctx, 200, result);
} }
} }

View File

@ -34,7 +34,7 @@ public final class GETUsersIdRequiresTotp implements Handler<RoutingContext> {
if (error2 != null) { if (error2 != null) {
ErrorUtils.respondInternalError(ctx, error2); ErrorUtils.respondInternalError(ctx, error2);
} else { } else {
APIv3.respondJson(ctx, ImmutableMap.of( APIv3.respondJson(ctx, 200, ImmutableMap.of(
"required", (requiresTotpResult == RequiresTotpResult.REQUIRED_NO_EXEMPTIONS), "required", (requiresTotpResult == RequiresTotpResult.REQUIRED_NO_EXEMPTIONS),
"message", requiresTotpResult.name() "message", requiresTotpResult.name()
)); ));

View File

@ -48,7 +48,7 @@ public final class GETUsersIdVerifyPassword implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, ImmutableMap.of( APIv3.respondJson(ctx, 200, ImmutableMap.of(
"authorized", authorized, "authorized", authorized,
"uuid", finalUuid "uuid", finalUuid
)); ));

View File

@ -57,7 +57,7 @@ public final class POSTUsersIdChangePassword implements Handler<RoutingContext>
authorized = true; authorized = true;
} else if (user.getPasswordResetToken() != null && user.getPasswordResetToken().equals(requestBody.getString("passwordResetToken"))) { } else if (user.getPasswordResetToken() != null && user.getPasswordResetToken().equals(requestBody.getString("passwordResetToken"))) {
if ((System.currentTimeMillis() - user.getPasswordResetTokenSetAt().toEpochMilli()) > TimeUnit.DAYS.toMillis(2)) { 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; return;
} }
@ -72,7 +72,7 @@ public final class POSTUsersIdChangePassword implements Handler<RoutingContext>
String newPassword = requestBody.getString("newPassword"); String newPassword = requestBody.getString("newPassword");
if (newPassword.length() < 8) { if (newPassword.length() < 8) {
ErrorUtils.respondGeneric(ctx, 200, "Your password is too short."); ErrorUtils.respondInvalidInput(ctx, "Password is too short.");
return; return;
} }
@ -85,7 +85,7 @@ public final class POSTUsersIdChangePassword implements Handler<RoutingContext>
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, ImmutableMap.of( APIv3.respondJson(ctx, 200, ImmutableMap.of(
"success", true "success", true
)); ));
} }

View File

@ -58,7 +58,7 @@ public final class POSTUsersIdConfirmPhone implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, ImmutableMap.of( APIv3.respondJson(ctx, 200, ImmutableMap.of(
"success", true "success", true
)); ));
} }

View File

@ -16,7 +16,7 @@ public class POSTUsersIdLeave implements Handler<RoutingContext> {
Actor actor = ctx.get("actor"); Actor actor = ctx.get("actor");
if (actor.getType() != ActorType.SERVER) { 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; return;
} }
@ -38,7 +38,7 @@ public class POSTUsersIdLeave implements Handler<RoutingContext> {
if (error2 != null) { if (error2 != null) {
ErrorUtils.respondInternalError(ctx, error2); ErrorUtils.respondInternalError(ctx, error2);
} else { } else {
APIv3.respondJson(ctx, user); APIv3.respondJson(ctx, 200, user);
} }
}); });
} }

View File

@ -36,7 +36,7 @@ public final class POSTUsersIdLogin implements Handler<RoutingContext> {
Actor actor = ctx.get("actor"); Actor actor = ctx.get("actor");
if (actor.getType() != ActorType.SERVER) { 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; return;
} }
@ -88,7 +88,7 @@ public final class POSTUsersIdLogin implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, loginInfo); APIv3.respondJson(ctx, 200, loginInfo);
} }
}); });
} }

View File

@ -49,7 +49,7 @@ public final class POSTUsersIdNotify implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, ImmutableMap.of( APIv3.respondJson(ctx, 200, ImmutableMap.of(
"success", true "success", true
)); ));
} }

View File

@ -58,7 +58,7 @@ public final class POSTUsersIdPasswordReset implements Handler<RoutingContext> {
if (error2 != null) { if (error2 != null) {
ErrorUtils.respondInternalError(ctx, error2); ErrorUtils.respondInternalError(ctx, error2);
} else { } else {
APIv3.respondJson(ctx, ImmutableMap.of( APIv3.respondJson(ctx, 200, ImmutableMap.of(
"success", true "success", true
)); ));
} }

View File

@ -84,7 +84,7 @@ public final class POSTUsersIdRegisterEmail implements Handler<RoutingContext> {
if (error2 != null) { if (error2 != null) {
ErrorUtils.respondInternalError(ctx, error2); ErrorUtils.respondInternalError(ctx, error2);
} else { } else {
APIv3.respondJson(ctx, ImmutableMap.of( APIv3.respondJson(ctx, 200, ImmutableMap.of(
"success", true "success", true
)); ));
} }

View File

@ -90,7 +90,7 @@ public final class POSTUsersIdRegisterPhone implements Handler<RoutingContext> {
if (error2 != null) { if (error2 != null) {
ErrorUtils.respondInternalError(ctx, error2); ErrorUtils.respondInternalError(ctx, error2);
} else { } else {
APIv3.respondJson(ctx, ImmutableMap.of( APIv3.respondJson(ctx, 200, ImmutableMap.of(
"success", true "success", true
)); ));
} }

View File

@ -44,7 +44,7 @@ public final class POSTUsersIdSetupTotp implements Handler<RoutingContext> {
if (error != null) { if (error != null) {
ErrorUtils.respondInternalError(ctx, error); ErrorUtils.respondInternalError(ctx, error);
} else { } else {
APIv3.respondJson(ctx, ImmutableMap.of( APIv3.respondJson(ctx, 200, ImmutableMap.of(
"success", true, "success", true,
"message", "Totp code set." "message", "Totp code set."
)); ));

View File

@ -48,7 +48,7 @@ public final class POSTUsersIdVerifyTotp implements Handler<RoutingContext> {
if (error3 != null) { if (error3 != null) {
ErrorUtils.respondInternalError(ctx, error3); ErrorUtils.respondInternalError(ctx, error3);
} else { } else {
APIv3.respondJson(ctx, ImmutableMap.of( APIv3.respondJson(ctx, 200, ImmutableMap.of(
"authorized", totpAuthorizationResult.isAuthorized(), "authorized", totpAuthorizationResult.isAuthorized(),
"message", totpAuthorizationResult.name() "message", totpAuthorizationResult.name()
)); ));

View File

@ -3,11 +3,11 @@ package net.frozenorb.apiv3.unsorted;
import com.mongodb.async.SingleResultCallback; import com.mongodb.async.SingleResultCallback;
import io.vertx.core.Future; import io.vertx.core.Future;
public class FutureCompatibilityCallback<T> implements SingleResultCallback<T> { public class MongoToVertxCallback<T> implements SingleResultCallback<T> {
private final Future<T> future; private final Future<T> future;
public FutureCompatibilityCallback(Future<T> future) { public MongoToVertxCallback(Future<T> future) {
this.future = future; this.future = future;
} }

View File

@ -32,7 +32,7 @@ public class EmailUtils {
} }
public static boolean isBannedEmailDomain(String email) { public static boolean isBannedEmailDomain(String email) {
if (email == null) { if (!isValidEmail(email)) {
return false; return false;
} }
@ -42,7 +42,7 @@ public class EmailUtils {
} }
public static boolean isValidEmail(String email) { public static boolean isValidEmail(String email) {
return VALID_EMAIL_PATTERN.matcher(email).matches(); return email != null && VALID_EMAIL_PATTERN.matcher(email).matches();
} }
} }

View File

@ -17,7 +17,7 @@ public class ErrorUtils {
} }
public static void respondRequiredInput(RoutingContext ctx, String field) { 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) { public static void respondInternalError(RoutingContext ctx, Throwable error) {

View File

@ -8,13 +8,12 @@ import java.util.regex.Pattern;
public class PhoneUtils { public class PhoneUtils {
private static final Pattern VALID_PHONE_PATTERN = Pattern.compile( 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 Pattern.CASE_INSENSITIVE
); );
public static boolean isValidPhone(String phoneNumber) { public static boolean isValidPhone(String phoneNumber) {
return true; // TODO return phoneNumber != null && VALID_PHONE_PATTERN.matcher(phoneNumber).matches();
//return VALID_EMAIL_PATTERN.matcher(email).matches();
} }
} }

View File

@ -48,15 +48,9 @@ public class TotpUtils {
String key = user.getId() + ":preAuthorizedIp:" + ip.toLowerCase(); String key = user.getId() + ":preAuthorizedIp:" + ip.toLowerCase();
redisClient.set(key, "", (result) -> { redisClient.setex(key, unit.toSeconds(duration), "", (result) -> {
if (result.succeeded()) { if (result.succeeded()) {
redisClient.expire(key, (int) unit.toSeconds(duration), (result2) -> { callback.onResult(null, null);
if (result2.succeeded()) {
callback.onResult(null, null);
} else {
callback.onResult(null, result.cause());
}
});
} else { } else {
callback.onResult(null, result.cause()); callback.onResult(null, result.cause());
} }
@ -76,15 +70,9 @@ public class TotpUtils {
public static void markRecentlyUsed(User user, int code, SingleResultCallback<Void> callback) { public static void markRecentlyUsed(User user, int code, SingleResultCallback<Void> callback) {
String key = user.getId() + ":recentTotpCodes:" + code; String key = user.getId() + ":recentTotpCodes:" + code;
redisClient.set(key, "", (result) -> { redisClient.setex(key, TimeUnit.MINUTES.toSeconds(5), "", (result) -> {
if (result.succeeded()) { if (result.succeeded()) {
redisClient.expire(key, (int) TimeUnit.MINUTES.toSeconds(5), (result2) -> { callback.onResult(null, null);
if (result2.succeeded()) {
callback.onResult(null, null);
} else {
callback.onResult(null, result.cause());
}
});
} else { } else {
callback.onResult(null, result.cause()); callback.onResult(null, result.cause());
} }