More stuff
This commit is contained in:
parent
6a1c86ee5a
commit
34415929c4
@ -34,6 +34,7 @@ import net.frozenorb.apiv3.routes.serverGroups.GETServerGroups;
|
||||
import net.frozenorb.apiv3.routes.serverGroups.POSTServerGroup;
|
||||
import net.frozenorb.apiv3.routes.servers.*;
|
||||
import net.frozenorb.apiv3.routes.users.*;
|
||||
import net.frozenorb.apiv3.serialization.DateTypeAdapter;
|
||||
import net.frozenorb.apiv3.serialization.FollowAnnotationExclusionStrategy;
|
||||
import net.frozenorb.apiv3.serialization.ObjectIdTypeAdapter;
|
||||
import net.frozenorb.apiv3.unsorted.LoggingExceptionHandler;
|
||||
@ -46,6 +47,7 @@ import redis.clients.jedis.JedisPool;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.Date;
|
||||
import java.util.Properties;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
@ -62,6 +64,7 @@ public final class APIv3 {
|
||||
@Getter private static StatsDClient statsD;
|
||||
@Getter private static final Gson gson = new GsonBuilder()
|
||||
.registerTypeAdapter(ObjectId.class, new ObjectIdTypeAdapter())
|
||||
.registerTypeAdapter(Date.class, new DateTypeAdapter())
|
||||
.setExclusionStrategies(new FollowAnnotationExclusionStrategy())
|
||||
.create();
|
||||
|
||||
|
@ -4,6 +4,7 @@ import lombok.Getter;
|
||||
import net.frozenorb.apiv3.APIv3;
|
||||
import net.frozenorb.apiv3.actors.Actor;
|
||||
import net.frozenorb.apiv3.actors.ActorType;
|
||||
import net.frozenorb.apiv3.utils.TimeUtils;
|
||||
import org.bson.types.ObjectId;
|
||||
import org.mongodb.morphia.annotations.Entity;
|
||||
import org.mongodb.morphia.annotations.Id;
|
||||
@ -72,6 +73,25 @@ public final class Punishment {
|
||||
return removedBy != null;
|
||||
}
|
||||
|
||||
public String getAccessDenialReason() {
|
||||
switch (type) {
|
||||
case BLACKLIST:
|
||||
return "Your account has been blacklisted from the MineHQ Network. \n\nThis type of punishment cannot be appealed.";
|
||||
case BAN:
|
||||
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()));
|
||||
} else {
|
||||
accessDenialReason += "Appeal at MineHQ.com/appeal";
|
||||
}
|
||||
|
||||
return accessDenialReason;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public enum PunishmentType {
|
||||
|
||||
BLACKLIST, BAN, MUTE, WARN
|
||||
|
@ -7,7 +7,6 @@ import lombok.Setter;
|
||||
import net.frozenorb.apiv3.APIv3;
|
||||
import net.frozenorb.apiv3.serialization.ExcludeFromReplies;
|
||||
import net.frozenorb.apiv3.utils.PermissionUtils;
|
||||
import net.frozenorb.apiv3.utils.TimeUtils;
|
||||
import org.bson.Document;
|
||||
import org.mindrot.jbcrypt.BCrypt;
|
||||
import org.mongodb.morphia.annotations.Entity;
|
||||
@ -215,17 +214,7 @@ public final class User {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (punishment.getType() == Punishment.PunishmentType.BLACKLIST) {
|
||||
accessDenialReason = "Your account has been blacklisted from the MineHQ Network. \n\nThis type of punishment cannot be appealed.";
|
||||
} else {
|
||||
accessDenialReason = "Your account has been suspended from the MineHQ Network. \n\n";
|
||||
|
||||
if (punishment.getExpiresAt() != null) {
|
||||
accessDenialReason += "Expires in " + TimeUtils.formatIntoDetailedString(TimeUtils.getSecondsBetween(punishment.getExpiresAt(), new Date()));
|
||||
} else {
|
||||
accessDenialReason += "Appeal at MineHQ.com/appeal";
|
||||
}
|
||||
}
|
||||
accessDenialReason = punishment.getAccessDenialReason();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.frozenorb.apiv3.routes.punishments;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import net.frozenorb.apiv3.APIv3;
|
||||
import net.frozenorb.apiv3.models.Punishment;
|
||||
@ -58,7 +59,11 @@ public final class POSTUserPunish implements Route {
|
||||
|
||||
Punishment punishment = new Punishment(target, reason, type, expiresAt, addedBy, req.attribute("actor"));
|
||||
APIv3.getDatastore().save(punishment);
|
||||
return punishment;
|
||||
|
||||
return ImmutableMap.of(
|
||||
"punishment", punishment,
|
||||
"accessDenialReason", punishment.getAccessDenialReason()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package net.frozenorb.apiv3.serialization;
|
||||
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
|
||||
public final class DateTypeAdapter extends TypeAdapter<Date> {
|
||||
|
||||
public void write(JsonWriter writer, Date write) throws IOException {
|
||||
writer.value(write.getTime());
|
||||
}
|
||||
|
||||
// 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) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user