package net.frozenorb.apiv3.models; import lombok.Getter; import net.frozenorb.apiv3.APIv3; import net.frozenorb.apiv3.weirdStuff.ExcludeFromReplies; import org.mongodb.morphia.annotations.Entity; import org.mongodb.morphia.annotations.Id; import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.UUID; @Entity(value = "users", noClassnameStored = true) public final class User { @Getter @Id private UUID id; @Getter private String lastName; @Getter @ExcludeFromReplies private Map aliases; @Getter @ExcludeFromReplies private String otpCode; @Getter @ExcludeFromReplies private String password; @Getter @ExcludeFromReplies private String passwordSalt; @Getter private String email; @Getter private int phoneNumber; @Getter private String lastSeenOn; @Getter private Date lastSeenAt; @Getter private Date firstSeen; public static User byId(UUID id) { return APIv3.getDatastore().createQuery(User.class).field("id").equal(id).get(); } public static User byIdOrName(String idOrName) { if (idOrName.length() == 36) { return byId(UUID.fromString(idOrName)); } else { return byName(idOrName); } } @Deprecated public static User byName(String name) { return APIv3.getDatastore().createQuery(User.class).field("lastName").equalIgnoreCase(name).get(); } public User() {} // For Morphia public User(UUID id, String lastName) { this.id = id; this.lastName = lastName; this.aliases = new HashMap<>(); this.otpCode = null; this.password = null; this.passwordSalt = null; this.email = null; this.phoneNumber = -1; this.lastSeenOn = null; this.lastSeenAt = new Date(); this.firstSeen = new Date(); aliases.put(lastName, new Date()); } public boolean hasPermissionAnywhere(String permission) { return hasPermissionScoped(permission, null); } public boolean hasPermissionScoped(String permission, ServerGroup scope) { // TODO: BLAH FIX THIS IF WE DONT REMOVE THEN IDK WHAT TO SAY // Also this is 1 > 0 because 'return true;' means all usages of this // get marked as a warning until we change it. return 1 > 0; } }