Swap Date to Instant
This commit is contained in:
parent
fac4d50501
commit
453a3264be
@ -62,8 +62,8 @@ import net.frozenorb.apiv3.route.serverGroups.GETServerGroups;
|
||||
import net.frozenorb.apiv3.route.serverGroups.POSTServerGroup;
|
||||
import net.frozenorb.apiv3.route.servers.*;
|
||||
import net.frozenorb.apiv3.route.users.*;
|
||||
import net.frozenorb.apiv3.serialization.gson.DateTypeAdapter;
|
||||
import net.frozenorb.apiv3.serialization.gson.FollowAnnotationExclusionStrategy;
|
||||
import net.frozenorb.apiv3.serialization.gson.InstantTimeAdapter;
|
||||
import net.frozenorb.apiv3.serialization.jackson.UUIDJsonDeserializer;
|
||||
import net.frozenorb.apiv3.serialization.jackson.UUIDJsonSerializer;
|
||||
import net.frozenorb.apiv3.serialization.mongodb.UUIDCodecProvider;
|
||||
@ -79,7 +79,11 @@ import org.bson.codecs.configuration.CodecRegistry;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
public final class APIv3 extends AbstractVerticle {
|
||||
@ -89,7 +93,7 @@ public final class APIv3 extends AbstractVerticle {
|
||||
@Getter private static Properties config = new Properties();
|
||||
@Getter private static RedisClient redisClient;
|
||||
private static final Gson gson = new GsonBuilder()
|
||||
.registerTypeAdapter(Date.class, new DateTypeAdapter())
|
||||
.registerTypeAdapter(Instant.class, new InstantTimeAdapter())
|
||||
.setExclusionStrategies(new FollowAnnotationExclusionStrategy())
|
||||
.create();
|
||||
|
||||
|
@ -7,8 +7,8 @@ import net.frozenorb.apiv3.model.Grant;
|
||||
import org.bson.Document;
|
||||
import org.bson.types.ObjectId;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -45,9 +45,9 @@ public final class GrantConverter implements Block<Document> {
|
||||
grant.containsKey("comment") ? grant.getString("comment") : "",
|
||||
grant.containsKey("scope") ? ImmutableSet.copyOf((Collection<String>) grant.get("scope")) : ImmutableSet.of(),
|
||||
rank,
|
||||
grant.getDate("expires"),
|
||||
grant.containsKey("expires") ? grant.getDate("expires").toInstant() : null,
|
||||
grant.containsKey("addedBy") ? oidToUniqueId.get(((Map<String, Object>) grant.get("addedBy")).get("$id")) : null,
|
||||
grant.containsKey("created") ? grant.getDate("created") : new Date(),
|
||||
grant.containsKey("created") ? grant.getDate("created").toInstant() : Instant.now(),
|
||||
null,
|
||||
null,
|
||||
null
|
||||
|
@ -44,10 +44,9 @@ public final class IpLogConverter implements Block<Document> {
|
||||
new ObjectId().toString(),
|
||||
user,
|
||||
ip,
|
||||
lastSeen,
|
||||
lastSeen,
|
||||
lastSeen.toInstant(),
|
||||
lastSeen.toInstant(),
|
||||
((Number) ipLogEntry.get("uses")).intValue()
|
||||
|
||||
);
|
||||
|
||||
created.insert();
|
||||
|
@ -8,7 +8,6 @@ import net.frozenorb.apiv3.model.Punishment;
|
||||
import org.bson.Document;
|
||||
import org.bson.types.ObjectId;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@ -40,15 +39,15 @@ public final class PunishmentConverter implements Block<Document> {
|
||||
target,
|
||||
punishment.getString("reason").toString(),
|
||||
Punishment.PunishmentType.valueOf(punishment.getString("type").toUpperCase()),
|
||||
punishment.getDate("expires"),
|
||||
punishment.containsKey("expires") ? punishment.getDate("expires").toInstant() : null,
|
||||
punishment.containsKey("meta") ? (punishment.get("meta") instanceof List ? ImmutableMap.of() : (Document) punishment.get("meta")) : ImmutableMap.of(),
|
||||
null,
|
||||
punishment.containsKey("addedBy") ? oidToUniqueId.get(((Map<String, Object>) punishment.get("addedBy")).get("$id")) : null,
|
||||
(Date) punishment.getDate("created").clone(),
|
||||
punishment.getDate("created").toInstant(),
|
||||
punishment.containsKey("createdOn") ? String.valueOf(((Map<String, Object>) punishment.get("createdOn")).get("$id")) : "Website",
|
||||
punishment.containsKey("createdOn") ? ActorType.SERVER : ActorType.WEBSITE,
|
||||
punishment.containsKey("removedBy") ? (((Map<String, Object>) punishment.get("removedBy")).get("$ref").equals("user") ? oidToUniqueId.get(((Map<String, Object>) punishment.get("removedBy")).get("$id")) : null) : null,
|
||||
punishment.containsKey("removedBy") ? (punishment.containsKey("removedAt") ? punishment.getDate("removedAt") : punishment.getDate("created")) : null,
|
||||
punishment.containsKey("removedBy") ? (punishment.containsKey("removedAt") ? punishment.getDate("removedAt") : punishment.getDate("created")).toInstant() : null,
|
||||
punishment.containsKey("removedBy") ? punishment.getString("removalReason").toString() : null
|
||||
);
|
||||
|
||||
|
@ -39,7 +39,7 @@ public final class UserConverter implements Block<Document> {
|
||||
User created = new User(
|
||||
uuid,
|
||||
user.get("name").toString(),
|
||||
ImmutableMap.of(user.get("name").toString(), user.getDate("joined")),
|
||||
ImmutableMap.of(user.get("name").toString(), user.getDate("joined").toInstant()),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
@ -47,8 +47,8 @@ public final class UserConverter implements Block<Document> {
|
||||
user.getString("email"),
|
||||
user.getString("phone"),
|
||||
"INVALID",
|
||||
user.getDate("joined"),
|
||||
user.getDate("joined"),
|
||||
user.getDate("joined").toInstant(),
|
||||
user.getDate("joined").toInstant(),
|
||||
false
|
||||
);
|
||||
|
||||
|
@ -9,7 +9,6 @@ import net.frozenorb.apiv3.model.Server;
|
||||
import net.frozenorb.apiv3.model.User;
|
||||
import net.frozenorb.apiv3.util.ErrorUtils;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Base64;
|
||||
|
||||
public final class ActorAttributeHandler implements Handler<RoutingContext> {
|
||||
|
@ -14,7 +14,11 @@ import net.frozenorb.apiv3.util.SyncUtils;
|
||||
import org.bson.Document;
|
||||
import org.bson.types.ObjectId;
|
||||
|
||||
import java.util.*;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@Entity
|
||||
public final class AuditLogEntry {
|
||||
@ -24,7 +28,7 @@ public final class AuditLogEntry {
|
||||
@Getter @Id private String id;
|
||||
@Getter private UUID user;
|
||||
@Getter private String userIp;
|
||||
@Getter private Date performedAt;
|
||||
@Getter private Instant performedAt;
|
||||
@Getter private String actorName;
|
||||
@Getter private ActorType actorType;
|
||||
@Getter private AuditLogActionType type;
|
||||
@ -76,7 +80,7 @@ public final class AuditLogEntry {
|
||||
this.id = new ObjectId().toString();
|
||||
this.user = user.getId();
|
||||
this.userIp = userIp;
|
||||
this.performedAt = new Date();
|
||||
this.performedAt = Instant.now();
|
||||
this.actorName = actor.getName();
|
||||
this.actorType = actor.getType();
|
||||
this.type = type;
|
||||
|
@ -14,6 +14,7 @@ import net.frozenorb.apiv3.util.SyncUtils;
|
||||
import org.bson.Document;
|
||||
import org.bson.types.ObjectId;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -28,13 +29,13 @@ public final class Grant {
|
||||
@Getter private String reason;
|
||||
@Getter private Set<String> scopes = new HashSet<>(); // So on things w/o scopes we still load properly (Morphia drops empty sets)
|
||||
@Getter private String rank;
|
||||
@Getter private Date expiresAt;
|
||||
@Getter private Instant expiresAt;
|
||||
|
||||
@Getter private UUID addedBy;
|
||||
@Getter private Date addedAt;
|
||||
@Getter private Instant addedAt;
|
||||
|
||||
@Getter private UUID removedBy;
|
||||
@Getter private Date removedAt;
|
||||
@Getter private Instant removedAt;
|
||||
@Getter private String removalReason;
|
||||
|
||||
public static List<Grant> findAllSync() {
|
||||
@ -109,7 +110,7 @@ public final class Grant {
|
||||
|
||||
public Grant() {} // For Morphia
|
||||
|
||||
public Grant(User user, String reason, Set<ServerGroup> scopes, Rank rank, Date expiresAt, User addedBy) {
|
||||
public Grant(User user, String reason, Set<ServerGroup> scopes, Rank rank, Instant expiresAt, User addedBy) {
|
||||
this.id = new ObjectId().toString();
|
||||
this.user = user.getId();
|
||||
this.reason = reason;
|
||||
@ -117,7 +118,7 @@ public final class Grant {
|
||||
this.rank = rank.getId();
|
||||
this.expiresAt = expiresAt;
|
||||
this.addedBy = addedBy == null ? null : addedBy.getId();
|
||||
this.addedAt = new Date();
|
||||
this.addedAt = Instant.now();
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
@ -128,7 +129,7 @@ public final class Grant {
|
||||
if (expiresAt == null) {
|
||||
return false; // Never expires
|
||||
} else {
|
||||
return expiresAt.before(new Date());
|
||||
return expiresAt.isBefore(Instant.now());
|
||||
}
|
||||
}
|
||||
|
||||
@ -152,7 +153,7 @@ public final class Grant {
|
||||
|
||||
public void delete(User removedBy, String reason) {
|
||||
this.removedBy = removedBy.getId();
|
||||
this.removedAt = new Date();
|
||||
this.removedAt = Instant.now();
|
||||
this.removalReason = reason;
|
||||
|
||||
BlockingCallback<UpdateResult> callback = new BlockingCallback<>();
|
||||
|
@ -16,6 +16,7 @@ import net.frozenorb.apiv3.util.TimeUtils;
|
||||
import org.bson.Document;
|
||||
import org.bson.types.ObjectId;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
|
||||
@Entity
|
||||
@ -27,15 +28,15 @@ public final class IpBan {
|
||||
@Getter @Id private String id;
|
||||
@Getter private String userIp;
|
||||
@Getter private String reason;
|
||||
@Getter private Date expiresAt;
|
||||
@Getter private Instant expiresAt;
|
||||
|
||||
@Getter private UUID addedBy;
|
||||
@Getter private Date addedAt;
|
||||
@Getter private Instant addedAt;
|
||||
@Getter private String actorName;
|
||||
@Getter private ActorType actorType;
|
||||
|
||||
@Getter private UUID removedBy;
|
||||
@Getter private Date removedAt;
|
||||
@Getter private Instant removedAt;
|
||||
@Getter private String removalReason;
|
||||
|
||||
public static List<IpBan> findAllSync() {
|
||||
@ -98,18 +99,18 @@ public final class IpBan {
|
||||
this.reason = linked.getReason();
|
||||
this.expiresAt = linked.getExpiresAt();
|
||||
this.addedBy = linked.getAddedBy();
|
||||
this.addedAt = new Date();
|
||||
this.addedAt = Instant.now();
|
||||
this.actorName = linked.getActorName();
|
||||
this.actorType = linked.getActorType();
|
||||
}
|
||||
|
||||
public IpBan(String userIp, String reason, Date expiresAt, User addedBy, Actor actor) {
|
||||
public IpBan(String userIp, String reason, Instant expiresAt, User addedBy, Actor actor) {
|
||||
this.id = new ObjectId().toString();
|
||||
this.userIp = userIp;
|
||||
this.reason = reason;
|
||||
this.expiresAt = expiresAt;
|
||||
this.addedBy = addedBy == null ? null : addedBy.getId();
|
||||
this.addedAt = new Date();
|
||||
this.addedAt = Instant.now();
|
||||
this.actorName = actor.getName();
|
||||
this.actorType = actor.getType();
|
||||
}
|
||||
@ -122,7 +123,7 @@ public final class IpBan {
|
||||
if (expiresAt == null) {
|
||||
return false; // Never expires
|
||||
} else {
|
||||
return expiresAt.before(new Date());
|
||||
return expiresAt.isBefore(Instant.now());
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,7 +135,7 @@ public final class IpBan {
|
||||
String accessDenialReason = "Your ip address has been suspended from the MineHQ Network. \n\n";
|
||||
|
||||
if (getExpiresAt() != null) {
|
||||
accessDenialReason += "Expires in " + TimeUtils.formatIntoDetailedString(TimeUtils.getSecondsBetween(getExpiresAt(), new Date()));
|
||||
accessDenialReason += "Expires in " + TimeUtils.formatIntoDetailedString(TimeUtils.getSecondsBetween(getExpiresAt(), Instant.now()));
|
||||
} else {
|
||||
accessDenialReason += "Appeal at MineHQ.com/appeal";
|
||||
}
|
||||
@ -150,7 +151,7 @@ public final class IpBan {
|
||||
|
||||
public void delete(User removedBy, String reason) {
|
||||
this.removedBy = removedBy.getId();
|
||||
this.removedAt = new Date();
|
||||
this.removedAt = Instant.now();
|
||||
this.removalReason = reason;
|
||||
|
||||
BlockingCallback<UpdateResult> callback = new BlockingCallback<>();
|
||||
|
@ -13,8 +13,8 @@ import net.frozenorb.apiv3.util.SyncUtils;
|
||||
import org.bson.Document;
|
||||
import org.bson.types.ObjectId;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -27,8 +27,8 @@ public final class IpLogEntry {
|
||||
@Getter @Id private String id;
|
||||
@Getter private UUID user;
|
||||
@Getter private String userIp;
|
||||
@Getter private Date firstSeenAt;
|
||||
@Getter private Date lastSeenAt;
|
||||
@Getter private Instant firstSeenAt;
|
||||
@Getter private Instant lastSeenAt;
|
||||
@Getter private int uses;
|
||||
|
||||
public static List<IpLogEntry> findAllSync() {
|
||||
@ -85,13 +85,13 @@ public final class IpLogEntry {
|
||||
this.id = new ObjectId().toString();
|
||||
this.user = user.getId();
|
||||
this.userIp = userIp;
|
||||
this.firstSeenAt = new Date();
|
||||
this.lastSeenAt = new Date();
|
||||
this.firstSeenAt = Instant.now();
|
||||
this.lastSeenAt = Instant.now();
|
||||
this.uses = 0;
|
||||
}
|
||||
|
||||
public void used() {
|
||||
this.lastSeenAt = new Date();
|
||||
this.lastSeenAt = Instant.now();
|
||||
this.uses++;
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ import net.frozenorb.apiv3.util.TimeUtils;
|
||||
import org.bson.Document;
|
||||
import org.bson.types.ObjectId;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -29,17 +30,17 @@ public final class Punishment {
|
||||
@Getter private UUID user;
|
||||
@Getter private String reason;
|
||||
@Getter private PunishmentType type;
|
||||
@Getter private Date expiresAt;
|
||||
@Getter private Instant expiresAt;
|
||||
@Getter private Map<String, Object> metadata;
|
||||
@Getter private String linkedIpBanId;
|
||||
|
||||
@Getter private UUID addedBy;
|
||||
@Getter private Date addedAt;
|
||||
@Getter private Instant addedAt;
|
||||
@Getter private String actorName;
|
||||
@Getter private ActorType actorType;
|
||||
|
||||
@Getter private UUID removedBy;
|
||||
@Getter private Date removedAt;
|
||||
@Getter private Instant removedAt;
|
||||
@Getter private String removalReason;
|
||||
|
||||
public static List<Punishment> findAllSync() {
|
||||
@ -132,14 +133,14 @@ public final class Punishment {
|
||||
|
||||
public Punishment() {} // For Morphia
|
||||
|
||||
public Punishment(User user, String reason, PunishmentType type, Date expiresAt, User addedBy, Actor actor, Map<String, Object> metadata) {
|
||||
public Punishment(User user, String reason, PunishmentType type, Instant expiresAt, User addedBy, Actor actor, Map<String, Object> metadata) {
|
||||
this.id = new ObjectId().toString();
|
||||
this.user = user.getId();
|
||||
this.reason = reason;
|
||||
this.type = type;
|
||||
this.expiresAt = expiresAt;
|
||||
this.addedBy = addedBy == null ? null : addedBy.getId();
|
||||
this.addedAt = new Date();
|
||||
this.addedAt = Instant.now();
|
||||
this.actorName = actor.getName();
|
||||
this.actorType = actor.getType();
|
||||
this.metadata = metadata;
|
||||
@ -153,7 +154,7 @@ public final class Punishment {
|
||||
if (expiresAt == null) {
|
||||
return false; // Never expires
|
||||
} else {
|
||||
return expiresAt.before(new Date());
|
||||
return expiresAt.isBefore(Instant.now());
|
||||
}
|
||||
}
|
||||
|
||||
@ -169,7 +170,7 @@ public final class Punishment {
|
||||
String accessDenialReason = "Your account has been suspended from the MineHQ Network. \n\n";
|
||||
|
||||
if (getExpiresAt() != null) {
|
||||
accessDenialReason += "Expires in " + TimeUtils.formatIntoDetailedString(TimeUtils.getSecondsBetween(getExpiresAt(), new Date()));
|
||||
accessDenialReason += "Expires in " + TimeUtils.formatIntoDetailedString(TimeUtils.getSecondsBetween(getExpiresAt(), Instant.now()));
|
||||
} else {
|
||||
accessDenialReason += "Appeal at MineHQ.com/appeal";
|
||||
}
|
||||
@ -192,7 +193,7 @@ public final class Punishment {
|
||||
|
||||
public void delete(User removedBy, String reason) {
|
||||
this.removedBy = removedBy.getId();
|
||||
this.removedAt = new Date();
|
||||
this.removedAt = Instant.now();
|
||||
this.removalReason = reason;
|
||||
|
||||
if (linkedIpBanId != null) {
|
||||
|
@ -14,6 +14,7 @@ import net.frozenorb.apiv3.unsorted.BlockingCallback;
|
||||
import net.frozenorb.apiv3.util.SyncUtils;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -31,7 +32,7 @@ public final class Server {
|
||||
@Getter @ExcludeFromReplies String apiKey;
|
||||
@Getter private String serverGroup;
|
||||
@Getter private String serverIp;
|
||||
@Getter @Setter private Date lastUpdatedAt;
|
||||
@Getter @Setter private Instant lastUpdatedAt;
|
||||
@Getter @Setter private double lastTps;
|
||||
@Getter @Setter @ExcludeFromReplies private Set<UUID> players;
|
||||
|
||||
@ -53,7 +54,7 @@ public final class Server {
|
||||
this.apiKey = apiKey;
|
||||
this.serverGroup = serverGroup.getId();
|
||||
this.serverIp = serverIp;
|
||||
this.lastUpdatedAt = new Date();
|
||||
this.lastUpdatedAt = Instant.now();
|
||||
this.lastTps = 0;
|
||||
this.players = new HashSet<>();
|
||||
}
|
||||
@ -75,7 +76,7 @@ public final class Server {
|
||||
}
|
||||
|
||||
public void receivedHeartbeat(double tps, Iterable<UUID> players) {
|
||||
this.lastUpdatedAt = new Date();
|
||||
this.lastUpdatedAt = Instant.now();
|
||||
this.lastTps = tps;
|
||||
this.players = ImmutableSet.copyOf(players);
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import net.frozenorb.apiv3.util.SyncUtils;
|
||||
import net.frozenorb.apiv3.util.UUIDUtils;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
|
||||
@Entity
|
||||
@ -37,16 +38,16 @@ public final class User {
|
||||
|
||||
@Getter @Id @JsonSerialize(using=UUIDJsonSerializer.class) @JsonDeserialize(using=UUIDJsonDeserializer.class) private UUID id;
|
||||
@Getter private String lastUsername;
|
||||
@Getter @ExcludeFromReplies private Map<String, Date> aliases = new HashMap<>();
|
||||
@Getter @ExcludeFromReplies private Map<String, Instant> aliases = new HashMap<>();
|
||||
@Getter @ExcludeFromReplies @Setter private String totpSecret;
|
||||
@Getter @ExcludeFromReplies @Setter private String emailToken;
|
||||
@Getter @ExcludeFromReplies @Setter private Date emailTokenSetAt;
|
||||
@Getter @ExcludeFromReplies @Setter private Instant emailTokenSetAt;
|
||||
@Getter @ExcludeFromReplies private String password;
|
||||
@Getter @Setter private String email;
|
||||
@Getter private String phoneNumber;
|
||||
@Getter private String lastSeenOn;
|
||||
@Getter private Date lastSeenAt;
|
||||
@Getter private Date firstSeenAt;
|
||||
@Getter private Instant lastSeenAt;
|
||||
@Getter private Instant firstSeenAt;
|
||||
@Getter private boolean online;
|
||||
|
||||
public static List<User> findAllSync() {
|
||||
@ -141,8 +142,8 @@ public final class User {
|
||||
this.email = null;
|
||||
this.phoneNumber = null;
|
||||
this.lastSeenOn = null;
|
||||
this.lastSeenAt = new Date();
|
||||
this.firstSeenAt = new Date();
|
||||
this.lastSeenAt = Instant.now();
|
||||
this.firstSeenAt = Instant.now();
|
||||
|
||||
// TODO: MAKE THIS ASYNC? SOMEHOW?
|
||||
BlockingCallback<Void> blockingCallback = new BlockingCallback<>();
|
||||
@ -175,7 +176,7 @@ public final class User {
|
||||
this.lastSeenOn = server.getId();
|
||||
|
||||
if (!online) {
|
||||
this.lastSeenAt = new Date();
|
||||
this.lastSeenAt = Instant.now();
|
||||
}
|
||||
|
||||
this.online = true;
|
||||
@ -183,12 +184,12 @@ public final class User {
|
||||
}
|
||||
|
||||
public void leftServer() {
|
||||
this.lastSeenAt = new Date();
|
||||
this.lastSeenAt = Instant.now();
|
||||
this.online = false;
|
||||
}
|
||||
|
||||
public void updateUsername(String newUsername, SingleResultCallback<Void> callback) {
|
||||
this.aliases.put(newUsername, new Date());
|
||||
this.aliases.put(newUsername, Instant.now());
|
||||
|
||||
if (newUsername.equalsIgnoreCase(lastUsername)) {
|
||||
callback.onResult(null, null);
|
||||
|
@ -9,7 +9,7 @@ import net.frozenorb.apiv3.model.ServerGroup;
|
||||
import net.frozenorb.apiv3.model.User;
|
||||
import net.frozenorb.apiv3.util.ErrorUtils;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.Instant;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@ -53,16 +53,16 @@ public final class POSTUserGrant implements Handler<RoutingContext> {
|
||||
return;
|
||||
}
|
||||
|
||||
Date expiresAt;
|
||||
Instant expiresAt;
|
||||
|
||||
try {
|
||||
expiresAt = new Date(Long.parseLong(ctx.request().getParam("expiresAt")));
|
||||
expiresAt = Instant.ofEpochMilli(Long.parseLong(ctx.request().getParam("expiresAt")));
|
||||
} catch (NumberFormatException ex) {
|
||||
expiresAt = null;
|
||||
}
|
||||
|
||||
if (expiresAt != null && expiresAt.before(new Date())) {
|
||||
ErrorUtils.respondInvalidInput(ctx, "Expiration date cannot be in the past.");
|
||||
if (expiresAt != null && expiresAt.isBefore(Instant.now())) {
|
||||
ErrorUtils.respondInvalidInput(ctx, "Expiration time cannot be in the past.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ import net.frozenorb.apiv3.model.User;
|
||||
import net.frozenorb.apiv3.util.ErrorUtils;
|
||||
import net.frozenorb.apiv3.util.IpUtils;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.Instant;
|
||||
|
||||
public final class POSTIpIpBan implements Handler<RoutingContext> {
|
||||
|
||||
@ -27,16 +27,16 @@ public final class POSTIpIpBan implements Handler<RoutingContext> {
|
||||
return;
|
||||
}
|
||||
|
||||
Date expiresAt;
|
||||
Instant expiresAt;
|
||||
|
||||
try {
|
||||
expiresAt = new Date(Long.parseLong(ctx.request().getParam("expiresAt")));
|
||||
expiresAt = Instant.ofEpochMilli(Long.parseLong(ctx.request().getParam("expiresAt")));
|
||||
} catch (NumberFormatException ex) {
|
||||
expiresAt = null;
|
||||
}
|
||||
|
||||
if (expiresAt != null && expiresAt.before(new Date())) {
|
||||
ErrorUtils.respondInvalidInput(ctx, "Expiration date cannot be in the past.");
|
||||
if (expiresAt != null && expiresAt.isBefore(Instant.now())) {
|
||||
ErrorUtils.respondInvalidInput(ctx, "Expiration time cannot be in the past.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ import net.frozenorb.apiv3.unsorted.Permissions;
|
||||
import net.frozenorb.apiv3.util.ErrorUtils;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.Instant;
|
||||
import java.util.Map;
|
||||
|
||||
public final class POSTUserPunish implements Handler<RoutingContext> {
|
||||
@ -43,16 +43,16 @@ public final class POSTUserPunish implements Handler<RoutingContext> {
|
||||
}
|
||||
}
|
||||
|
||||
Date expiresAt;
|
||||
Instant expiresAt;
|
||||
|
||||
try {
|
||||
expiresAt = new Date(Long.parseLong(ctx.request().getParam("expiresAt")));
|
||||
expiresAt = Instant.ofEpochMilli(Long.parseLong(ctx.request().getParam("expiresAt")));
|
||||
} catch (NumberFormatException ex) {
|
||||
expiresAt = null;
|
||||
}
|
||||
|
||||
if (expiresAt != null && expiresAt.before(new Date())) {
|
||||
ErrorUtils.respondInvalidInput(ctx, "Expiration date cannot be in the past.");
|
||||
if (expiresAt != null && expiresAt.isBefore(Instant.now())) {
|
||||
ErrorUtils.respondInvalidInput(ctx, "Expiration time cannot be in the past.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,11 @@ import net.frozenorb.apiv3.util.PermissionUtils;
|
||||
import net.frozenorb.apiv3.util.UUIDUtils;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.util.*;
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
public final class POSTServerHeartbeat implements Handler<RoutingContext> {
|
||||
@ -60,7 +64,7 @@ public final class POSTServerHeartbeat implements Handler<RoutingContext> {
|
||||
|
||||
server.setPlayers(playerNames.keySet());
|
||||
server.setLastTps(tps);
|
||||
server.setLastUpdatedAt(new Date());
|
||||
server.setLastUpdatedAt(Instant.now());
|
||||
server.save();
|
||||
|
||||
callback.complete();
|
||||
|
@ -36,7 +36,7 @@ public final class POSTUserConfirmRegister implements Handler<RoutingContext> {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((System.currentTimeMillis() - user.getEmailTokenSetAt().getTime()) > TimeUnit.DAYS.toMillis(2)) {
|
||||
if ((System.currentTimeMillis() - user.getEmailTokenSetAt().toEpochMilli()) > TimeUnit.DAYS.toMillis(2)) {
|
||||
ErrorUtils.respondGeneric(ctx, 200, "Email token is expired");
|
||||
return;
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import net.frozenorb.apiv3.unsorted.Notification;
|
||||
import net.frozenorb.apiv3.util.ErrorUtils;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Date;
|
||||
import java.time.Instant;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -43,14 +43,14 @@ public final class POSTUserRegister implements Handler<RoutingContext> {
|
||||
return;
|
||||
}
|
||||
|
||||
if (user.getEmailToken() != null && (System.currentTimeMillis() - user.getEmailTokenSetAt().getTime()) < TimeUnit.DAYS.toMillis(2)) {
|
||||
if (user.getEmailToken() != null && (System.currentTimeMillis() - user.getEmailTokenSetAt().toEpochMilli()) < TimeUnit.DAYS.toMillis(2)) {
|
||||
ErrorUtils.respondGeneric(ctx, 200, "We just recently sent you a confirmation email. Please wait before trying to register again.");
|
||||
return;
|
||||
}
|
||||
|
||||
user.setEmail(email);
|
||||
user.setEmailToken(new BigInteger(130, new Random()).toString(32));
|
||||
user.setEmailTokenSetAt(new Date());
|
||||
user.setEmailTokenSetAt(Instant.now());
|
||||
user.save();
|
||||
|
||||
Map<String, Object> replacements = ImmutableMap.of(
|
||||
|
@ -5,22 +5,22 @@ import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.time.Instant;
|
||||
|
||||
public final class DateTypeAdapter extends TypeAdapter<Date> {
|
||||
public final class InstantTimeAdapter extends TypeAdapter<Instant> {
|
||||
|
||||
public void write(JsonWriter writer, Date write) throws IOException {
|
||||
public void write(JsonWriter writer, Instant write) throws IOException {
|
||||
if (write == null) {
|
||||
writer.nullValue();
|
||||
} else {
|
||||
writer.value(write.getTime());
|
||||
writer.value(write.toEpochMilli());
|
||||
}
|
||||
}
|
||||
|
||||
// This is used with Gson, which is only used
|
||||
// to serialize outgoing responses, thus we
|
||||
// don't need to have a read method.
|
||||
public Date read(JsonReader reader) {
|
||||
public Instant read(JsonReader reader) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package net.frozenorb.apiv3.util;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.Instant;
|
||||
|
||||
@UtilityClass
|
||||
public class TimeUtils {
|
||||
@ -27,8 +27,8 @@ public class TimeUtils {
|
||||
return (fDays + fHours + fMinutes + fSeconds).trim();
|
||||
}
|
||||
|
||||
public static int getSecondsBetween(Date a, Date b) {
|
||||
return (Math.abs((int) (a.getTime() - b.getTime()) / 1000));
|
||||
public static int getSecondsBetween(Instant a, Instant b) {
|
||||
return (Math.abs((int) (a.toEpochMilli() - b.toEpochMilli()) / 1000));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user