import org.cacert.gigi.util.PasswordHash;
import org.cacert.gigi.util.PasswordStrengthChecker;
+/**
+ * Represents an acting, assurable, user. Synchronizing on user means: no
+ * name-change and no assurance.
+ */
public class User extends CertificateOwner {
private Name name = new Name(null, null, null, null);
}
public int getAssurancePoints() {
- try (GigiPreparedStatement query = new GigiPreparedStatement("SELECT sum(points) FROM `notary` where `to`=? AND `deleted` is NULL")) {
+ try (GigiPreparedStatement query = new GigiPreparedStatement("SELECT sum(points) FROM `notary` where `to`=? AND `deleted` is NULL AND (`expire` IS NULL OR `expire` > CURRENT_TIMESTAMP)")) {
query.setInt(1, getId());
GigiResultSet rs = query.executeQuery();
List<Assurance> assurances = new LinkedList<Assurance>();
while (res.next()) {
- assurances.add(new Assurance(res));
+ assurances.add(assuranceByRes(res));
}
this.receivedAssurances = assurances.toArray(new Assurance[0]);
List<Assurance> assurances = new LinkedList<Assurance>();
while (res.next()) {
- assurances.add(new Assurance(res));
+ assurances.add(assuranceByRes(res));
}
this.madeAssurances = assurances.toArray(new Assurance[0]);
}
public List<Organisation> getOrganisations() {
+ return getOrganisations(false);
+ }
+
+ public List<Organisation> getOrganisations(boolean isAdmin) {
List<Organisation> orgas = new ArrayList<>();
- try (GigiPreparedStatement query = new GigiPreparedStatement("SELECT `orgid` FROM `org_admin` WHERE `memid`=? AND `deleted` IS NULL")) {
+ try (GigiPreparedStatement query = new GigiPreparedStatement("SELECT `orgid` FROM `org_admin` WHERE `memid`=? AND `deleted` IS NULL" + (isAdmin ? " AND master='y'" : ""))) {
query.setInt(1, getId());
try (GigiResultSet res = query.executeQuery()) {
while (res.next()) {
ps.executeUpdate();
}
}
+
+ private Assurance assuranceByRes(GigiResultSet res) {
+ return new Assurance(res.getInt("id"), User.getById(res.getInt("from")), User.getById(res.getInt("to")), res.getString("location"), res.getString("method"), res.getInt("points"), res.getString("date"));
+ }
}