]> WPIA git - gigi.git/commitdiff
Add a verify page.
authorFelix Dörre <felix@dogcraft.de>
Wed, 25 Jun 2014 12:36:12 +0000 (14:36 +0200)
committerFelix Dörre <felix@dogcraft.de>
Wed, 25 Jun 2014 12:41:39 +0000 (14:41 +0200)
src/org/cacert/gigi/Gigi.java
src/org/cacert/gigi/pages/Verify.java [new file with mode: 0644]
src/org/cacert/gigi/pages/main/Signup.java
src/org/cacert/gigi/util/ServerConstants.java

index ba12cea2b6949e5f7982e9c748ff4f9475f5cd66..78924e822687909511c231cfa8dd5a52417804c3 100644 (file)
@@ -21,6 +21,7 @@ import org.cacert.gigi.pages.LoginPage;
 import org.cacert.gigi.pages.MainPage;
 import org.cacert.gigi.pages.Page;
 import org.cacert.gigi.pages.TestSecure;
 import org.cacert.gigi.pages.MainPage;
 import org.cacert.gigi.pages.Page;
 import org.cacert.gigi.pages.TestSecure;
+import org.cacert.gigi.pages.Verify;
 import org.cacert.gigi.pages.account.MailCertificates;
 import org.cacert.gigi.pages.account.MyDetails;
 import org.cacert.gigi.pages.main.RegisterPage;
 import org.cacert.gigi.pages.account.MailCertificates;
 import org.cacert.gigi.pages.account.MyDetails;
 import org.cacert.gigi.pages.main.RegisterPage;
@@ -42,6 +43,7 @@ public class Gigi extends HttpServlet {
                pages.put("/login", new LoginPage("CACert - Login"));
                pages.put("/", new MainPage("CACert - Home"));
                pages.put("/secure", new TestSecure());
                pages.put("/login", new LoginPage("CACert - Login"));
                pages.put("/", new MainPage("CACert - Home"));
                pages.put("/secure", new TestSecure());
+               pages.put(Verify.PATH, new Verify());
                pages.put(MailCertificates.PATH, new MailCertificates());
                pages.put(MyDetails.PATH, new MyDetails());
                pages.put(RegisterPage.PATH, new RegisterPage());
                pages.put(MailCertificates.PATH, new MailCertificates());
                pages.put(MyDetails.PATH, new MyDetails());
                pages.put(RegisterPage.PATH, new RegisterPage());
diff --git a/src/org/cacert/gigi/pages/Verify.java b/src/org/cacert/gigi/pages/Verify.java
new file mode 100644 (file)
index 0000000..8d29266
--- /dev/null
@@ -0,0 +1,72 @@
+package org.cacert.gigi.pages;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.cacert.gigi.database.DatabaseConnection;
+
+public class Verify extends Page {
+       public static final String PATH = "/verify";
+       public Verify() {
+               super("Verify email");
+       }
+       @Override
+       public boolean needsLogin() {
+               return false;
+       }
+       @Override
+       public void doGet(HttpServletRequest req, HttpServletResponse resp)
+                       throws IOException {
+               PrintWriter out = resp.getWriter();
+               String hash = req.getParameter("hash");
+               String type = req.getParameter("type");
+               String id = req.getParameter("id");
+               if ("email".equals(type)) {
+                       try {
+                               PreparedStatement ps = DatabaseConnection
+                                               .getInstance()
+                                               .prepare(
+                                                               "select email, memid from `email` where `id`=? and `hash`=? and `hash` != '' and `deleted` = 0");
+                               ps.setString(1, id);
+                               ps.setString(2, hash);
+                               ResultSet rs = ps.executeQuery();
+                               rs.last();
+                               if (rs.getRow() == 1) {
+                                       PreparedStatement ps1 = DatabaseConnection
+                                                       .getInstance()
+                                                       .prepare(
+                                                                       "update `email` set `hash`='', `modified`=NOW() where `id`=?");
+                                       ps1.setString(1, id);
+                                       ps1.execute();
+                                       PreparedStatement ps2 = DatabaseConnection
+                                                       .getInstance()
+                                                       .prepare(
+                                                                       "update `users` set `verified`='1' where `id`=? and `email`=? and `verified`='0'");
+                                       ps2.setString(1, rs.getString(2));
+                                       ps2.setString(2, rs.getString(1));
+                                       ps2.execute();
+                                       out.println("Your email is good.");
+                               } else {
+                                       out.println("Your request is invalid");
+                               }
+                       } catch (SQLException e) {
+                               e.printStackTrace();
+                       }
+               }
+       }
+       @Override
+       public void doPost(HttpServletRequest req, HttpServletResponse resp)
+                       throws IOException {
+               String hash = req.getParameter("hash");
+               String type = req.getParameter("type");
+               if ("email".equals(type)) {
+
+               }
+       }
+}
index f2b24c80d0a8633583ed6388155d62d05fb8f664..39e91a273fba0901d6f89ce4d15778b8fdefca30 100644 (file)
@@ -257,9 +257,8 @@ public class Signup {
                                                        req,
                                                        "Thanks for signing up with CAcert.org, below is the link you need to open to verify your account. Once your account is verified you will be able to start issuing certificates till your hearts' content!"));
                        body.append("\n\n");
                                                        req,
                                                        "Thanks for signing up with CAcert.org, below is the link you need to open to verify your account. Once your account is verified you will be able to start issuing certificates till your hearts' content!"));
                        body.append("\n\n");
-                       body.append("http://");
                        body.append(ServerConstants.NORMAL_HOST_NAME);
                        body.append(ServerConstants.NORMAL_HOST_NAME);
-                       body.append("/verify.php?type=email&emailid=");
+                       body.append("/verify?type=email&id=");
                        body.append(emailid);
                        body.append("&hash=");
                        body.append(hash);
                        body.append(emailid);
                        body.append("&hash=");
                        body.append(hash);
index c2d7fd853a9a2be010334d52d760a167635efd1e..82b124c42f5391a6f8a23273581ed515d0d2cfaf 100644 (file)
@@ -1,5 +1,5 @@
 package org.cacert.gigi.util;
 
 public class ServerConstants {
 package org.cacert.gigi.util;
 
 public class ServerConstants {
-       public static final String NORMAL_HOST_NAME = "www.cacert.org";
+       public static final String NORMAL_HOST_NAME = "http://www.cacert.org";
 }
 }