2 * Copyright 2010 Electronic Business Systems Ltd.
4 * This file is part of GSS.
6 * GSS is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GSS. If not, see <http://www.gnu.org/licenses/>.
19 package gr.ebs.gss.server;
21 import gr.ebs.gss.server.ejb.TransactionHelper;
23 import java.io.IOException;
24 import java.util.concurrent.Callable;
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse;
30 * The servlet that handles user registration.
34 public class CouponVerifier extends BaseServlet {
36 * The request parameter name for the verification flag.
38 private static final String VERIFY_PARAM = "verify";
41 * The request parameter name for the coupon code.
43 private static final String CODE_PARAM = "code";
46 * The request parameter name for the firstname.
48 private static final String FIRSTNAME_PARAM = "firstname";
51 * The request parameter name for the lastname.
53 private static final String LASTNAME_PARAM = "lastname";
56 * The request parameter name for the username.
58 private static final String USERNAME_PARAM = "username";
61 * The request parameter name for the e-mail.
63 private static final String EMAIL_PARAM = "email";
66 * The serial version UID of the class.
68 private static final long serialVersionUID = 1L;
71 public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
72 String firstname = request.getParameter(FIRSTNAME_PARAM);
73 String lastname = request.getParameter(LASTNAME_PARAM);
74 String email = request.getParameter(EMAIL_PARAM);
75 final String username = request.getParameter(USERNAME_PARAM);
76 final String code = request.getParameter(CODE_PARAM);
77 String verify = request.getParameter(VERIFY_PARAM);
78 response.setContentType("text/html");
80 // Validate input parameters.
81 if (username == null || username.isEmpty()) {
82 handleException(response, "No username was specified");
84 } else if (firstname == null || firstname.isEmpty()) {
85 handleException(response, "No firstname was specified");
87 } else if (lastname == null || lastname.isEmpty()) {
88 handleException(response, "No lastname was specified");
90 } else if (email == null || email.isEmpty()) {
91 handleException(response, "No email was specified");
93 } else if (code == null || code.isEmpty()) {
94 handleException(response, "No code was specified");
96 } else if (!"on".equalsIgnoreCase(verify)) {
97 String error = encode("You must verify that the coupon belongs to you");
98 String errorUrl = "couponSubmission.jsp?error=" + error;
99 errorUrl += "&username=" + username;
100 errorUrl += "&firstname=" + firstname;
101 errorUrl += "&lastname=" + lastname;
102 errorUrl += "&code=" + code;
103 errorUrl += "&email=" + email;
104 response.sendRedirect(errorUrl);
109 new TransactionHelper<Void>().tryExecute(new Callable<Void>() {
111 public Void call() throws Exception {
112 getService().upgradeUserClass(username, code);
117 response.sendRedirect("couponSubmitted.jsp?newQuota=" + getService().getCouponUserClass().getQuotaAsString());
118 } catch (Exception e) {
119 handleException(response, e.getMessage());
123 private void handleException(HttpServletResponse response, String error) throws IOException {
124 String errorUrl = "coupon.jsp?error=" + error;
125 response.sendRedirect(errorUrl);