Change POST /grants|ipBans|punishments to use expiresIn (a relative field in seconds) instead of expiresAt (absolute time)

This commit is contained in:
Colin McDonald 2016-07-10 11:48:53 -04:00
parent 6fbc8925eb
commit 53a56401e0
3 changed files with 9 additions and 6 deletions

View File

@ -65,8 +65,9 @@ public final class POSTGrants implements Handler<RoutingContext> {
Instant expiresAt = null;
if (requestBody.containsKey("expiresAt") && requestBody.getLong("expiresAt") != -1) {
expiresAt = Instant.ofEpochMilli(requestBody.getLong("expiresAt"));
if (requestBody.containsKey("expiresIn") && requestBody.getLong("expiresIn") != -1) {
long expiresInMillis = requestBody.getLong("expiresIn") * 1000;
expiresAt = Instant.ofEpochMilli(System.currentTimeMillis() + expiresInMillis);
}
if (expiresAt != null && expiresAt.isBefore(Instant.now())) {

View File

@ -35,8 +35,9 @@ public final class POSTIpBans implements Handler<RoutingContext> {
Instant expiresAt = null;
if (requestBody.containsKey("expiresAt") && requestBody.getLong("expiresAt") != -1) {
expiresAt = Instant.ofEpochMilli(requestBody.getLong("expiresAt"));
if (requestBody.containsKey("expiresIn") && requestBody.getLong("expiresIn") != -1) {
long expiresInMillis = requestBody.getLong("expiresIn") * 1000;
expiresAt = Instant.ofEpochMilli(System.currentTimeMillis() + expiresInMillis);
}
if (expiresAt != null && expiresAt.isBefore(Instant.now())) {

View File

@ -63,8 +63,9 @@ public final class POSTPunishments implements Handler<RoutingContext> {
Instant expiresAt = null;
if (requestBody.containsKey("expiresAt") && requestBody.getLong("expiresAt") != -1) {
expiresAt = Instant.ofEpochMilli(requestBody.getLong("expiresAt"));
if (requestBody.containsKey("expiresIn") && requestBody.getLong("expiresIn") != -1) {
long expiresInMillis = requestBody.getLong("expiresIn") * 1000;
expiresAt = Instant.ofEpochMilli(System.currentTimeMillis() + expiresInMillis);
}
if (expiresAt != null && expiresAt.isBefore(Instant.now())) {