if ( !gae.isEmpty()) {
throw gae;
}
+
+ LinkedList<Name> toAssure = new LinkedList<Name>();
for (int i = 0; i < selected.length; i++) {
if (selected[i]) {
- Notary.assure(assurer, assuree, assureeNames[i], dob, pointsI, location, req.getParameter("date"), type);
+ toAssure.add(assureeNames[i]);
}
}
+
+ Notary.assureAll(assurer, assuree, dob, pointsI, location, req.getParameter("date"), type, toAssure.toArray(new Name[toAssure.size()]));
+
if (aword != null && !aword.equals("")) {
- Language l = Language.getInstance(assuree.getPreferredLocale());
- String method = l.getTranslation("A password reset was triggered. If you did a password reset by assurance, please enter your secret password using this form:");
- String subject = l.getTranslation("Password reset by assurance");
- PasswordResetPage.initPasswordResetProcess(out, assuree, req, aword, l, method, subject);
+ Language langApplicant = Language.getInstance(assuree.getPreferredLocale());
+ String method = langApplicant.getTranslation("A password reset was triggered. If you did a password reset by assurance, please enter your secret password using this form:");
+ String subject = langApplicant.getTranslation("Password reset by assurance");
+ PasswordResetPage.initPasswordResetProcess(out, assuree, req, aword, langApplicant, method, subject);
}
return true;
}
package org.cacert.gigi.util;
+import java.io.IOException;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.Map;
import org.cacert.gigi.GigiApiException;
import org.cacert.gigi.database.GigiPreparedStatement;
import org.cacert.gigi.dbObjects.Group;
import org.cacert.gigi.dbObjects.Name;
import org.cacert.gigi.dbObjects.User;
+import org.cacert.gigi.localisation.Language;
+import org.cacert.gigi.output.ArrayIterable;
import org.cacert.gigi.output.DateSelector;
+import org.cacert.gigi.output.template.MailTemplate;
import org.cacert.gigi.output.template.SprintfCommand;
public class Notary {
ps.execute();
}
}
+
+ public synchronized static void assureAll(User assurer, User assuree, DayDate dob, int awarded, String location, String date, AssuranceType type, Name[] toAssure) throws GigiApiException {
+ boolean[] hadLessThan50Points = new boolean[toAssure.length];
+ boolean hadTotalLessThan100 = assuree.getAssurancePoints() < 100;
+ for (int i = 0; i < toAssure.length; i++) {
+ hadLessThan50Points[i] = toAssure[i].getAssurancePoints() < 50;
+
+ assure(assurer, assuree, toAssure[i], dob, awarded, location, date, type);
+ }
+ sendVerificationNotificationApplicant(assurer, assuree, toAssure, awarded, hadLessThan50Points, hadTotalLessThan100);
+ }
+
+ private static final MailTemplate verificationEntered = new MailTemplate(Notary.class.getResource("VerificationEntered.templ"));
+
+ private static void sendVerificationNotificationApplicant(User assurer, User assuree, Name[] toAssure, final int awarded, final boolean[] hadLessThan50Points, boolean hadTotalLessThan100) {
+ HashMap<String, Object> mailVars = new HashMap<>();
+ mailVars.put("agent", assurer.getPreferredName().toString());
+ mailVars.put("names", new ArrayIterable<Name>(toAssure) {
+
+ @Override
+ public void apply(Name t, Language l, Map<String, Object> vars) {
+ int totalVP = t.getAssurancePoints();
+ vars.put("name", t.toString());
+ vars.put("points", Integer.toString(awarded));
+ vars.put("total", totalVP);
+ if (totalVP < 50) {
+ vars.put("rem", (50 - totalVP));
+ vars.remove("gotGreater");
+ } else if (hadLessThan50Points[i]) {
+ vars.put("gotGreater", true);
+ vars.remove("rem");
+ }
+ }
+
+ });
+
+ int grandTotalVP = assuree.getAssurancePoints();
+ if (grandTotalVP >= 50 && grandTotalVP < 100) {
+ mailVars.put("remAll", (100 - grandTotalVP));
+ mailVars.remove("gotGreaterAll");
+ } else if (hadTotalLessThan100) {
+ mailVars.put("gotGreaterAll", true);
+ mailVars.remove("remAll");
+ }
+ try {
+ verificationEntered.sendMail(Language.getInstance(assuree.getPreferredLocale()), mailVars, assuree.getEmail());
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
}