From: Felix Dörre Date: Sun, 21 Sep 2014 13:12:09 +0000 (+0200) Subject: ADD: Request ttp page. X-Git-Url: https://code.wpia.club/?p=gigi.git;a=commitdiff_plain;h=9ce0b33f7a6bb10acaa3d74889dbb836a2ec34ad ADD: Request ttp page. --- diff --git a/doc/tableStructure.sql b/doc/tableStructure.sql index ff8cffac..cf46d042 100644 --- a/doc/tableStructure.sql +++ b/doc/tableStructure.sql @@ -274,7 +274,7 @@ DROP TABLE IF EXISTS `user_groups`; CREATE TABLE IF NOT EXISTS `user_groups` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user` int(11) NOT NULL, - `permission` enum('supporter','arbitrator','blockedassuree','blockedassurer','ttp-assuer','codesigning') NOT NULL, + `permission` enum('supporter','arbitrator','blockedassuree','blockedassurer','ttp-assuer','ttp-applicant', 'codesigning') NOT NULL, `granted` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `deleted` timestamp NULL DEFAULT NULL, `grantedby` int(11) NOT NULL, diff --git a/src/org/cacert/gigi/Gigi.java b/src/org/cacert/gigi/Gigi.java index 82ca1265..cf91b6b1 100644 --- a/src/org/cacert/gigi/Gigi.java +++ b/src/org/cacert/gigi/Gigi.java @@ -45,6 +45,7 @@ import org.cacert.gigi.pages.error.PageNotFound; import org.cacert.gigi.pages.main.RegisterPage; import org.cacert.gigi.pages.wot.AssurePage; import org.cacert.gigi.pages.wot.MyPoints; +import org.cacert.gigi.pages.wot.RequestTTPPage; import org.cacert.gigi.ping.PingerDaemon; import org.cacert.gigi.util.ServerConstants; @@ -104,6 +105,7 @@ public class Gigi extends HttpServlet { putPage(MailOverview.DEFAULT_PATH, new MailOverview("My email addresses"), "Certificates"); putPage(DomainOverview.PATH + "*", new DomainOverview("Domains"), "Certificates"); putPage(MyPoints.PATH, new MyPoints("My Points"), "CAcert Web of Trust"); + putPage(RequestTTPPage.PATH, new RequestTTPPage(), "CAcert Web of Trust"); putPage("/wot/rules", new StaticPage("CAcert Web of Trust Rules", AssurePage.class.getResourceAsStream("Rules.templ")), "CAcert Web of Trust"); baseTemplate = new Template(Gigi.class.getResource("Gigi.templ")); rootMenu = new Menu("Main"); diff --git a/src/org/cacert/gigi/pages/wot/RequestTTPForm.java b/src/org/cacert/gigi/pages/wot/RequestTTPForm.java new file mode 100644 index 00000000..7da62e06 --- /dev/null +++ b/src/org/cacert/gigi/pages/wot/RequestTTPForm.java @@ -0,0 +1,57 @@ +package org.cacert.gigi.pages.wot; + +import java.io.PrintWriter; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.cacert.gigi.GigiApiException; +import org.cacert.gigi.dbObjects.Group; +import org.cacert.gigi.dbObjects.User; +import org.cacert.gigi.localisation.Language; +import org.cacert.gigi.output.Form; +import org.cacert.gigi.output.template.OutputableArrayIterable; +import org.cacert.gigi.output.template.Template; +import org.cacert.gigi.pages.LoginPage; + +public class RequestTTPForm extends Form { + + public static final Group TTP_APPLICANT = Group.getByString("ttp-applicant"); + + private static final Template t = new Template(RequestTTPForm.class.getResource("RequestTTPForm.templ")); + + private User u; + + public RequestTTPForm(HttpServletRequest hsr) { + super(hsr); + u = LoginPage.getUser(hsr); + } + + private final String[] COUNTRIES = new String[] { + "Australia", "Puerto Rico", "USA" + }; + + @Override + public boolean submit(PrintWriter out, HttpServletRequest req) throws GigiApiException { + String country = req.getParameter("country"); + if (country != null) { + int cid = Integer.parseInt(country); + if (cid < 0 || cid >= COUNTRIES.length) { + throw new GigiApiException("Invalid country id"); + } + country = COUNTRIES[cid]; + } + User u = LoginPage.getUser(req); + u.grantGroup(u, TTP_APPLICANT); + + return false; + } + + @Override + protected void outputContent(PrintWriter out, Language l, Map map) { + map.put("countries", new OutputableArrayIterable(COUNTRIES, "country")); + + t.output(out, l, map); + } + +} diff --git a/src/org/cacert/gigi/pages/wot/RequestTTPForm.templ b/src/org/cacert/gigi/pages/wot/RequestTTPForm.templ new file mode 100644 index 00000000..6f8ff66b --- /dev/null +++ b/src/org/cacert/gigi/pages/wot/RequestTTPForm.templ @@ -0,0 +1,19 @@ + + + + + + + + + +
+ +
diff --git a/src/org/cacert/gigi/pages/wot/RequestTTPPage.java b/src/org/cacert/gigi/pages/wot/RequestTTPPage.java new file mode 100644 index 00000000..a4ea66f5 --- /dev/null +++ b/src/org/cacert/gigi/pages/wot/RequestTTPPage.java @@ -0,0 +1,61 @@ +package org.cacert.gigi.pages.wot; + +import java.io.IOException; +import java.util.HashMap; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.cacert.gigi.GigiApiException; +import org.cacert.gigi.dbObjects.Assurance; +import org.cacert.gigi.dbObjects.User; +import org.cacert.gigi.output.Form; +import org.cacert.gigi.pages.LoginPage; +import org.cacert.gigi.pages.Page; + +public class RequestTTPPage extends Page { + + public static final String PATH = "/wot/ttp"; + + public RequestTTPPage() { + super("Request TTP"); + } + + @Override + public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { + try { + Form.getForm(req, RequestTTPForm.class).submit(resp.getWriter(), req); + } catch (GigiApiException e) { + e.format(resp.getWriter(), getLanguage(req)); + } + } + + @Override + public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { + User u = LoginPage.getUser(req); + HashMap map = new HashMap(); + if (u.isInGroup(RequestTTPForm.TTP_APPLICANT)) { + map.put("inProgress", true); + } else { + if (u.getAssurancePoints() < 100) { + int ttpCount = 0; + for (Assurance a : u.getReceivedAssurances()) { + if (a.getMethod().equals(Assurance.AssuranceType.TTP_ASSISTED.getDescription())) { + ttpCount++; + } + } + if (ttpCount < 2) { + map.put("ttp", true); + map.put("form", new RequestTTPForm(req)); + } else { + map.put("nothing", true); + } + } else { + map.put("nothing", true); + } + } + map.put("form", new RequestTTPForm(req)); + getDefaultTemplate().output(resp.getWriter(), getLanguage(req), map); + } + +} diff --git a/src/org/cacert/gigi/pages/wot/RequestTTPPage.templ b/src/org/cacert/gigi/pages/wot/RequestTTPPage.templ new file mode 100644 index 00000000..163e7817 --- /dev/null +++ b/src/org/cacert/gigi/pages/wot/RequestTTPPage.templ @@ -0,0 +1,35 @@ +

+ +

+ +

+ +

+ +

+ +

+ +

+ +

https://wiki.cacert.org/TTP/TTPuser","https://wiki.cacert.org/TTP/TTPAL",If you are interested in the TTP programme, read the pages %s for the basic way how the TTP programme works for you, and %s whether the TTP programme affects the country where you are located.?>

+ + +

+ + + + +

+
+ +
+

+ + + +

+ + +

+