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);
import javax.servlet.http.HttpServletRequest;
+import org.cacert.gigi.GigiApiException;
import org.cacert.gigi.dbObjects.EmailAddress;
import org.cacert.gigi.dbObjects.User;
import org.cacert.gigi.localisation.Language;
} catch (IllegalArgumentException e) {
out.println("<div class='formError'>Error: Invalid address!</div>");
return false;
+ } catch (GigiApiException e) {
+ e.format(out, Page.getLanguage(req));
+ return false;
}
return true;
}
run(req, pw1);
} catch (SQLException e) {
e.printStackTrace();
+ } catch (GigiApiException e) {
+ outputError(out, req, e.getMessage());
+ return false;
}
return true;
}
- private void run(HttpServletRequest req, String password) throws SQLException {
+ private void run(HttpServletRequest req, String password) throws SQLException, GigiApiException {
try {
DatabaseConnection.getInstance().beginTransaction();
buildup.setPreferredLocale(Page.getLanguage(req).getLocale());
}
@Test
- public void testEmailCache() {
+ public void testEmailCache() throws GigiApiException {
EmailAddress em = new EmailAddress(User.getById(uid), createUniqueName() + "@example.org");
em.insert(Language.getInstance(Locale.ENGLISH));