+ public boolean wantsDirectoryListing() {
+ try (GigiPreparedStatement get = new GigiPreparedStatement("SELECT listme FROM users WHERE id=?")) {
+ get.setInt(1, getId());
+ GigiResultSet exec = get.executeQuery();
+ return exec.next() && exec.getBoolean("listme");
+ }
+ }
+
+ public String getContactInformation() {
+ try (GigiPreparedStatement get = new GigiPreparedStatement("SELECT contactinfo FROM users WHERE id=?")) {
+ get.setInt(1, getId());
+
+ GigiResultSet exec = get.executeQuery();
+ exec.next();
+ return exec.getString("contactinfo");
+ }
+ }
+
+ public void setDirectoryListing(boolean on) {
+ try (GigiPreparedStatement update = new GigiPreparedStatement("UPDATE users SET listme = ? WHERE id = ?")) {
+ update.setBoolean(1, on);
+ update.setInt(2, getId());
+ update.executeUpdate();
+ }
+ }
+
+ public void setContactInformation(String contactInfo) {
+ try (GigiPreparedStatement update = new GigiPreparedStatement("UPDATE users SET contactinfo = ? WHERE id = ?")) {
+ update.setString(1, contactInfo);
+ update.setInt(2, getId());
+ update.executeUpdate();
+ }
+ }
+
+ public boolean isInGroup(Group g) {
+ return groups.contains(g);
+ }
+
+ public Set<Group> getGroups() {
+ return Collections.unmodifiableSet(groups);
+ }
+
+ public void grantGroup(User granter, Group toGrant) {
+ groups.add(toGrant);
+ try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `user_groups` SET `user`=?, `permission`=?::`userGroup`, `grantedby`=?")) {
+ ps.setInt(1, getId());
+ ps.setString(2, toGrant.getDatabaseName());
+ ps.setInt(3, granter.getId());
+ ps.execute();
+ }
+ }
+
+ public void revokeGroup(User revoker, Group toRevoke) {
+ groups.remove(toRevoke);
+ try (GigiPreparedStatement ps = new GigiPreparedStatement("UPDATE `user_groups` SET `deleted`=CURRENT_TIMESTAMP, `revokedby`=? WHERE `deleted` IS NULL AND `permission`=?::`userGroup` AND `user`=?")) {
+ ps.setInt(1, revoker.getId());
+ ps.setString(2, toRevoke.getDatabaseName());
+ ps.setInt(3, getId());
+ ps.execute();
+ }