]> WPIA git - gigi.git/blobdiff - util-testing/club/wpia/gigi/pages/Manager.java
fix: only add contract to test-agents if missing
[gigi.git] / util-testing / club / wpia / gigi / pages / Manager.java
index bd90d2629fb1c05901785bc190cedaff0671b72c..bed50973a1bbef8d13c791cb514bd409f05080b4 100644 (file)
@@ -48,6 +48,7 @@ import club.wpia.gigi.dbObjects.DomainPingExecution;
 import club.wpia.gigi.dbObjects.DomainPingType;
 import club.wpia.gigi.dbObjects.EmailAddress;
 import club.wpia.gigi.dbObjects.Group;
+import club.wpia.gigi.dbObjects.Name;
 import club.wpia.gigi.dbObjects.NamePart;
 import club.wpia.gigi.dbObjects.NamePart.NamePartType;
 import club.wpia.gigi.dbObjects.User;
@@ -166,7 +167,9 @@ public class Manager extends Page {
                 ps.setString(6, getRandomCountry().getCode());
                 ps.execute();
             }
-            new Contract(u, ContractType.RA_AGENT_CONTRACT);
+            if ( !Contract.hasSignedContract(u, ContractType.RA_AGENT_CONTRACT)) {
+                new Contract(u, ContractType.RA_AGENT_CONTRACT);
+            }
             return u;
         }
     }
@@ -409,18 +412,55 @@ public class Manager extends Page {
             }
 
             int vp = 0;
+            int verifications = 0;
+            String info = "";
 
             try {
-                vp = Integer.parseInt(verificationPoints);
-            } catch (NumberFormatException e) {
-                resp.getWriter().println("No valid Verification Points entered.</br>");
-                vp = 0;
+                try {
+                    vp = Integer.parseInt(verificationPoints);
+                } catch (NumberFormatException e) {
+                    resp.getWriter().println("The value for Verification Points must be an integer.</br>");
+                    vp = 0;
+                }
+
+                int agentNumber = addVerificationPoints(vp, byEmail);
+
+                while (vp > 0) {
+                    int currentVP = 10;
+                    if (vp < 10) {
+                        currentVP = vp;
+                    }
+                    if (Notary.checkVerificationIsPossible(getAgent(agentNumber), byEmail.getPreferredName())) {
+
+                        Notary.verify(getAgent(agentNumber), byEmail, byEmail.getPreferredName(), byEmail.getDoB(), currentVP, "Testmanager Verify up code", validVerificationDateString(), VerificationType.FACE_TO_FACE, getRandomCountry());
+                        vp -= currentVP;
+                        verifications += 1;
+
+                    }
+                    agentNumber += 1;
+                    if (agentNumber >= agents.length) {
+                        info = "<br/>The limit of agents is reached. You cannot add any more Verification Points to the preferred name of this user using this method.";
+                        break;
+                    }
+                }
+
+            } catch (GigiApiException e) {
+                throw new Error(e);
             }
 
-            int agentNumber = addVerificationPoints(vp, byEmail);
+            resp.getWriter().println("User has been verified " + verifications + " times." + info);
 
-            resp.getWriter().println("User has been verified " + agentNumber + " times.");
+        } else if (req.getParameter("verifyexpire") != null) {
+            String mail = req.getParameter("verifyEmail");
+            User byEmail = User.getByEmail(mail);
+            if (byEmail == null) {
+                resp.getWriter().println("User not found.");
+                return;
+            } else {
+                setVerificationDateToPast(byEmail.getPreferredName());
+            }
 
+            resp.getWriter().println("Verification set to time past the limit.");
         } else if (req.getParameter("letverify") != null) {
             String mail = req.getParameter("letverifyEmail");
             User byEmail = User.getByEmail(mail);
@@ -602,4 +642,18 @@ public class Manager extends Page {
 
         form.output(resp.getWriter(), getLanguage(req), vars);
     }
+
+    private static void setVerificationDateToPast(Name name) {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        Calendar c = Calendar.getInstance();
+        c.setTimeInMillis(System.currentTimeMillis());
+        c.add(Calendar.MONTH, -TimeConditions.getInstance().getVerificationMonths());
+        String date = sdf.format(new Date(c.getTimeInMillis()));
+        GigiPreparedStatement ps = new GigiPreparedStatement("UPDATE `notary` SET `date`=? WHERE `to`=? AND `date`>?");
+        ps.setString(1, date);
+        ps.setInt(2, name.getId());
+        ps.setString(3, date);
+        ps.execute();
+        ps.close();
+    }
 }