+ @Override
+ public synchronized boolean submit(PrintWriter out, HttpServletRequest req) {
+ update(req);
+ if (buildup.getLname().trim().equals("")) {
+ outputError(out, req, "Last name were blank.");
+ }
+ if ( !myDoB.isValid()) {
+ outputError(out, req, "Invalid date of birth");
+ }
+ if ( !"1".equals(req.getParameter("cca_agree"))) {
+ outputError(out, req, "You have to agree to the CAcert Community agreement.");
+ }
+ if (buildup.getEmail().equals("")) {
+ outputError(out, req, "Email Address was blank");
+ }
+ String pw1 = req.getParameter("pword1");
+ String pw2 = req.getParameter("pword2");
+ if (pw1 == null || pw1.equals("")) {
+ outputError(out, req, "Pass Phrases were blank");
+ } else if ( !pw1.equals(pw2)) {
+ outputError(out, req, "Pass Phrases don't match");
+ }
+ int pwpoints = PasswordStrengthChecker.checkpw(pw1, buildup);
+ if (pwpoints < 3) {
+ outputError(out, req, "The Pass Phrase you submitted failed to contain enough" + " differing characters and/or contained words from" + " your name and/or email address.");
+ }
+ if (isFailed(out)) {
+ return false;
+ }
+ GigiPreparedStatement q1 = DatabaseConnection.getInstance().prepare("select * from `emails` where `email`=? and `deleted` IS NULL");
+ GigiPreparedStatement q2 = DatabaseConnection.getInstance().prepare("select * from certOwners inner join users on users.id=certOwners.id where `email`=? and `deleted` IS NULL");
+ q1.setString(1, buildup.getEmail());
+ q2.setString(1, buildup.getEmail());
+ GigiResultSet r1 = q1.executeQuery();
+ GigiResultSet r2 = q2.executeQuery();
+ if (r1.next() || r2.next()) {
+ outputError(out, req, "This email address is currently valid in the system.");
+ }
+ r1.close();
+ r2.close();
+ GigiPreparedStatement q3 = DatabaseConnection.getInstance().prepare("select `domain` from `baddomains` where `domain`=RIGHT(?, LENGTH(`domain`))");
+ q3.setString(1, buildup.getEmail());
+
+ GigiResultSet r3 = q3.executeQuery();
+ if (r3.next()) {
+ String domain = r3.getString(1);
+ outputError(out, req, "We don't allow signups from people using email addresses from %s", domain);
+ }
+ r3.close();
+ String mailResult = EmailProvider.FAIL;
+ try {
+ mailResult = EmailProvider.getInstance().checkEmailServer(0, buildup.getEmail());
+ } catch (IOException e) {
+ }
+ if ( !mailResult.equals(EmailProvider.OK)) {
+ if (mailResult.startsWith("4")) {
+ outputError(out, req, "The mail server responsible for your domain indicated" + " a temporary failure. This may be due to anti-SPAM measures, such" + " as greylisting. Please try again in a few minutes.");
+ } else {
+ outputError(out, req, "Email Address given was invalid, or a test connection" + " couldn't be made to your server, or the server" + " rejected the email address as invalid");
+ }
+ if (mailResult.equals(EmailProvider.FAIL)) {
+ outputError(out, req, "Failed to make a connection to the mail server");
+ } else {
+ outputErrorPlain(out, mailResult);
+ }
+ }
+
+ if (isFailed(out)) {
+ return false;
+ }
+ try {
+ 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, GigiApiException {
+ try {
+ DatabaseConnection.getInstance().beginTransaction();
+ buildup.setPreferredLocale(Page.getLanguage(req).getLocale());
+ buildup.setDob(myDoB.getDate());
+ buildup.insert(password);
+ int memid = buildup.getId();
+ EmailAddress ea = new EmailAddress(buildup, buildup.getEmail());
+ ea.insert(Page.getLanguage(req));
+
+ GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("insert into `alerts` set `memid`=?," + " `general`=?, `country`=?, `regional`=?, `radius`=?");
+ ps.setInt(1, memid);
+ ps.setString(2, general ? "1" : "0");
+ ps.setString(3, country ? "1" : "0");
+ ps.setString(4, regional ? "1" : "0");
+ ps.setString(5, radius ? "1" : "0");
+ ps.execute();
+ Notary.writeUserAgreement(buildup, "CCA", "account creation", "", true, 0);
+
+ DatabaseConnection.getInstance().commitTransaction();
+ } finally {
+ DatabaseConnection.getInstance().quitTransaction();
+ }
+
+ }