APIv3/src/main/java/net/frozenorb/apiv3/models/User.java

78 lines
2.4 KiB
Java
Raw Normal View History

2016-04-08 13:12:31 +02:00
package net.frozenorb.apiv3.models;
2016-02-12 02:40:06 +01:00
import lombok.Getter;
2016-03-22 00:58:08 +01:00
import net.frozenorb.apiv3.APIv3;
2016-03-21 23:28:17 +01:00
import net.frozenorb.apiv3.weirdStuff.ExcludeFromReplies;
import org.mongodb.morphia.annotations.Entity;
import org.mongodb.morphia.annotations.Id;
2016-02-12 02:40:06 +01:00
2016-03-21 23:28:17 +01:00
import java.util.Date;
import java.util.HashMap;
2016-02-23 13:14:42 +01:00
import java.util.Map;
import java.util.UUID;
2016-03-21 23:28:17 +01:00
@Entity(value = "users", noClassnameStored = true)
public final class User {
2016-02-12 02:40:06 +01:00
2016-03-22 00:58:08 +01:00
@Getter @Id private UUID id;
2016-02-23 13:14:42 +01:00
@Getter private String lastName;
2016-03-22 00:58:08 +01:00
@Getter @ExcludeFromReplies private Map<String, Date> aliases;
@Getter @ExcludeFromReplies private String otpCode;
@Getter @ExcludeFromReplies private String password;
@Getter @ExcludeFromReplies private String passwordSalt;
2016-02-23 13:14:42 +01:00
@Getter private String email;
@Getter private int phoneNumber;
@Getter private String lastSeenOn;
2016-03-21 23:28:17 +01:00
@Getter private Date lastSeenAt;
@Getter private Date firstSeen;
2016-03-22 00:58:08 +01:00
public static User byId(UUID id) {
return APIv3.getDatastore().createQuery(User.class).field("id").equal(id).get();
}
// TODO: FIND ALL USAGES OF THIS AND
// SEE HOW MANY OF THEM (EX NON GET REQUESTS)
// WE CAN DROP
2016-04-08 13:12:31 +02:00
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) {
2016-04-17 21:23:02 +02:00
return APIv3.getDatastore().createQuery(User.class).field("lastName").equalIgnoreCase(name).get();
2016-04-08 13:12:31 +02:00
}
2016-03-21 23:28:17 +01:00
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;
2016-03-22 00:58:08 +01:00
this.phoneNumber = -1;
this.lastSeenOn = null;
2016-03-21 23:28:17 +01:00
this.lastSeenAt = new Date();
this.firstSeen = new Date();
aliases.put(lastName, new Date());
2016-02-12 02:40:06 +01:00
}
2016-04-17 21:23:02 +02:00
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;
}
2016-02-12 02:40:06 +01:00
}