From ee3a012f800b8868fa58208329e903f30509b12b Mon Sep 17 00:00:00 2001 From: colinmcdonald22 Date: Fri, 21 Oct 2016 19:36:24 -0400 Subject: [PATCH] Fix json integer parsing --- .../frozenorb/apiv3/route/accessTokens/POSTAccessTokens.java | 2 +- .../net/frozenorb/apiv3/route/bannedAsns/POSTBannedAsns.java | 2 +- .../route/bannedCellCarriers/POSTBannedCellCarriers.java | 2 +- .../java/net/frozenorb/apiv3/route/grants/POSTGrants.java | 2 +- src/main/java/net/frozenorb/apiv3/route/ranks/POSTRanks.java | 4 ++-- .../apiv3/route/users/POSTUsersIdChangePassword.java | 2 +- .../frozenorb/apiv3/route/users/POSTUsersIdConfirmPhone.java | 2 +- .../net/frozenorb/apiv3/route/users/POSTUsersIdSetupTotp.java | 2 +- .../frozenorb/apiv3/route/users/POSTUsersIdVerifyTotp.java | 2 +- src/main/java/net/frozenorb/apiv3/zang/ZangResult.java | 2 +- 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/frozenorb/apiv3/route/accessTokens/POSTAccessTokens.java b/src/main/java/net/frozenorb/apiv3/route/accessTokens/POSTAccessTokens.java index a51b9a4..831ea31 100644 --- a/src/main/java/net/frozenorb/apiv3/route/accessTokens/POSTAccessTokens.java +++ b/src/main/java/net/frozenorb/apiv3/route/accessTokens/POSTAccessTokens.java @@ -30,7 +30,7 @@ public final class POSTAccessTokens implements Handler { return; } - int code = requestBody.getInteger("totpCode"); + int code = requestBody.getInteger("totpCode", -1); TotpAuthorizationResult totpAuthorizationResult = SyncUtils.runBlocking(v -> addedBy.checkTotpAuthorization(code, null, v)); if (!totpAuthorizationResult.isAuthorized()) { diff --git a/src/main/java/net/frozenorb/apiv3/route/bannedAsns/POSTBannedAsns.java b/src/main/java/net/frozenorb/apiv3/route/bannedAsns/POSTBannedAsns.java index fbdb9e7..e24d8e9 100644 --- a/src/main/java/net/frozenorb/apiv3/route/bannedAsns/POSTBannedAsns.java +++ b/src/main/java/net/frozenorb/apiv3/route/bannedAsns/POSTBannedAsns.java @@ -16,7 +16,7 @@ public final class POSTBannedAsns implements Handler { public void handle(RoutingContext ctx) { JsonObject requestBody = ctx.getBodyAsJson(); - int id = requestBody.getInteger("id"); + int id = requestBody.getInteger("id", -1); String note = requestBody.getString("note"); BannedAsn bannedAsn = new BannedAsn(id, note); diff --git a/src/main/java/net/frozenorb/apiv3/route/bannedCellCarriers/POSTBannedCellCarriers.java b/src/main/java/net/frozenorb/apiv3/route/bannedCellCarriers/POSTBannedCellCarriers.java index 1f02d37..13ee20a 100644 --- a/src/main/java/net/frozenorb/apiv3/route/bannedCellCarriers/POSTBannedCellCarriers.java +++ b/src/main/java/net/frozenorb/apiv3/route/bannedCellCarriers/POSTBannedCellCarriers.java @@ -16,7 +16,7 @@ public final class POSTBannedCellCarriers implements Handler { public void handle(RoutingContext ctx) { JsonObject requestBody = ctx.getBodyAsJson(); - int id = requestBody.getInteger("id"); + int id = requestBody.getInteger("id", -1); String note = requestBody.getString("note"); BannedCellCarrier bannedCellCarrier = new BannedCellCarrier(id, note); diff --git a/src/main/java/net/frozenorb/apiv3/route/grants/POSTGrants.java b/src/main/java/net/frozenorb/apiv3/route/grants/POSTGrants.java index 7cd4558..d67c071 100644 --- a/src/main/java/net/frozenorb/apiv3/route/grants/POSTGrants.java +++ b/src/main/java/net/frozenorb/apiv3/route/grants/POSTGrants.java @@ -86,7 +86,7 @@ public final class POSTGrants implements Handler { } if (rank.isGrantRequiresTotp()) { - int code = requestBody.getInteger("totpCode"); + int code = requestBody.getInteger("totpCode", -1); TotpAuthorizationResult totpAuthorizationResult = SyncUtils.runBlocking(v -> addedBy.checkTotpAuthorization(code, null, v)); if (!totpAuthorizationResult.isAuthorized()) { diff --git a/src/main/java/net/frozenorb/apiv3/route/ranks/POSTRanks.java b/src/main/java/net/frozenorb/apiv3/route/ranks/POSTRanks.java index 02cd61b..09f320c 100644 --- a/src/main/java/net/frozenorb/apiv3/route/ranks/POSTRanks.java +++ b/src/main/java/net/frozenorb/apiv3/route/ranks/POSTRanks.java @@ -18,8 +18,8 @@ public final class POSTRanks implements Handler { JsonObject requestBody = ctx.getBodyAsJson(); String id = requestBody.getString("id"); String inheritsFromId = requestBody.getString("inheritsFromId"); - int generalWeight = requestBody.getInteger("generalWeight"); - int displayWeight = requestBody.getInteger("displayWeight"); + int generalWeight = requestBody.getInteger("generalWeight", -1); + int displayWeight = requestBody.getInteger("displayWeight", -1); String displayName = requestBody.getString("displayName"); String gamePrefix = requestBody.getString("gamePrefix"); String gameColor = requestBody.getString("gameColor"); diff --git a/src/main/java/net/frozenorb/apiv3/route/users/POSTUsersIdChangePassword.java b/src/main/java/net/frozenorb/apiv3/route/users/POSTUsersIdChangePassword.java index 2f597ee..39e4dd7 100644 --- a/src/main/java/net/frozenorb/apiv3/route/users/POSTUsersIdChangePassword.java +++ b/src/main/java/net/frozenorb/apiv3/route/users/POSTUsersIdChangePassword.java @@ -43,7 +43,7 @@ public final class POSTUsersIdChangePassword implements Handler RequiresTotpResult requiresTotp = SyncUtils.runBlocking(v -> user.requiresTotpAuthorization(null, v)); if (requiresTotp == RequiresTotpResult.REQUIRED_NO_EXEMPTIONS) { - int code = requestBody.getInteger("totpCode"); + int code = requestBody.getInteger("totpCode", -1); TotpAuthorizationResult totpAuthorizationResult = SyncUtils.runBlocking(v -> user.checkTotpAuthorization(code, null, v)); if (!totpAuthorizationResult.isAuthorized()) { diff --git a/src/main/java/net/frozenorb/apiv3/route/users/POSTUsersIdConfirmPhone.java b/src/main/java/net/frozenorb/apiv3/route/users/POSTUsersIdConfirmPhone.java index 7268cf0..fa76325 100644 --- a/src/main/java/net/frozenorb/apiv3/route/users/POSTUsersIdConfirmPhone.java +++ b/src/main/java/net/frozenorb/apiv3/route/users/POSTUsersIdConfirmPhone.java @@ -35,7 +35,7 @@ public final class POSTUsersIdConfirmPhone implements Handler { } JsonObject requestBody = ctx.getBodyAsJson(); - int phoneCode = requestBody.getInteger("phoneCode"); + int phoneCode = requestBody.getInteger("phoneCode", -1); if ((System.currentTimeMillis() - user.getPendingPhoneTokenSetAt().toEpochMilli()) > TimeUnit.HOURS.toMillis(6)) { ErrorUtils.respondOther(ctx, 409, "Phone token is expired", "phoneTokenExpired", ImmutableMap.of()); diff --git a/src/main/java/net/frozenorb/apiv3/route/users/POSTUsersIdSetupTotp.java b/src/main/java/net/frozenorb/apiv3/route/users/POSTUsersIdSetupTotp.java index cd35edd..02e7af8 100644 --- a/src/main/java/net/frozenorb/apiv3/route/users/POSTUsersIdSetupTotp.java +++ b/src/main/java/net/frozenorb/apiv3/route/users/POSTUsersIdSetupTotp.java @@ -30,7 +30,7 @@ public final class POSTUsersIdSetupTotp implements Handler { JsonObject requestBody = ctx.getBodyAsJson(); String secret = requestBody.getString("secret"); - int totpCode = requestBody.getInteger("totpCode"); + int totpCode = requestBody.getInteger("totpCode" -1); if (TotpUtils.authorizeUser(secret, totpCode)) { user.setTotpSecret(secret); diff --git a/src/main/java/net/frozenorb/apiv3/route/users/POSTUsersIdVerifyTotp.java b/src/main/java/net/frozenorb/apiv3/route/users/POSTUsersIdVerifyTotp.java index e088978..1f4f4c3 100644 --- a/src/main/java/net/frozenorb/apiv3/route/users/POSTUsersIdVerifyTotp.java +++ b/src/main/java/net/frozenorb/apiv3/route/users/POSTUsersIdVerifyTotp.java @@ -38,7 +38,7 @@ public final class POSTUsersIdVerifyTotp implements Handler { return; } - user.checkTotpAuthorization(requestBody.getInteger("totpCode"), userIp, (totpAuthorizationResult, error2) -> { + user.checkTotpAuthorization(requestBody.getInteger("totpCode", -1), userIp, (totpAuthorizationResult, error2) -> { if (error2 != null) { ErrorUtils.respondInternalError(ctx, error2); return; diff --git a/src/main/java/net/frozenorb/apiv3/zang/ZangResult.java b/src/main/java/net/frozenorb/apiv3/zang/ZangResult.java index 238ee1c..2e5d0dd 100644 --- a/src/main/java/net/frozenorb/apiv3/zang/ZangResult.java +++ b/src/main/java/net/frozenorb/apiv3/zang/ZangResult.java @@ -16,7 +16,7 @@ public final class ZangResult { public ZangResult(JsonObject legacy) { this.phoneNumber = legacy.getString("phone_number"); this.countryCode = legacy.getString("country_code"); - this.carrierId = legacy.getInteger("carrier_id"); + this.carrierId = legacy.getInteger("carrier_id", -1); this.network = legacy.getString("network"); this.mobile = Boolean.parseBoolean(legacy.getString("mobile")); }