From: Felix Dörre Date: Wed, 25 Jun 2014 12:36:12 +0000 (+0200) Subject: Add a verify page. X-Git-Url: https://code.wpia.club/?p=gigi.git;a=commitdiff_plain;h=2b2cdb102fe3f3a34d8fcfd22e24b30ca09fe4ba Add a verify page. --- diff --git a/src/org/cacert/gigi/Gigi.java b/src/org/cacert/gigi/Gigi.java index ba12cea2..78924e82 100644 --- a/src/org/cacert/gigi/Gigi.java +++ b/src/org/cacert/gigi/Gigi.java @@ -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.Verify; 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(Verify.PATH, new Verify()); 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 index 00000000..8d292667 --- /dev/null +++ b/src/org/cacert/gigi/pages/Verify.java @@ -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)) { + + } + } +} diff --git a/src/org/cacert/gigi/pages/main/Signup.java b/src/org/cacert/gigi/pages/main/Signup.java index f2b24c80..39e91a27 100644 --- a/src/org/cacert/gigi/pages/main/Signup.java +++ b/src/org/cacert/gigi/pages/main/Signup.java @@ -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"); - body.append("http://"); 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); diff --git a/src/org/cacert/gigi/util/ServerConstants.java b/src/org/cacert/gigi/util/ServerConstants.java index c2d7fd85..82b124c4 100644 --- a/src/org/cacert/gigi/util/ServerConstants.java +++ b/src/org/cacert/gigi/util/ServerConstants.java @@ -1,5 +1,5 @@ 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"; }