]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/dbObjects/EmailAddress.java
UPD: check for duplicate Email in the Email class itself.
[gigi.git] / src / org / cacert / gigi / dbObjects / EmailAddress.java
index f398087d16bf067213afc0b2507557de10cfc658..b945f9eecc23028575b8d4368738ecd5d652c42e 100644 (file)
@@ -45,16 +45,22 @@ public class EmailAddress implements IdCachable {
         this.hash = RandomToken.generateToken(16);
     }
 
-    public void insert(Language l) {
+    public void insert(Language l) throws GigiApiException {
         if (id != 0) {
             throw new IllegalStateException("already inserted.");
         }
         try {
+            GigiPreparedStatement psCheck = DatabaseConnection.getInstance().prepare("SELECT 1 FROM `emails` WHERE email=? AND deleted is NULL");
             GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("INSERT INTO `emails` SET memid=?, hash=?, email=?");
             ps.setInt(1, owner.getId());
             ps.setString(2, hash);
             ps.setString(3, address);
+            psCheck.setString(1, address);
             synchronized (EmailAddress.class) {
+                GigiResultSet res = psCheck.executeQuery();
+                if (res.next()) {
+                    throw new GigiApiException("The email is currently valid");
+                }
                 ps.execute();
                 id = ps.lastInsertId();
                 myCache.put(this);