Statistics
| Branch: | Tag: | Revision:

root / src / gr / ebs / gss / server / CouponVerifier.java @ 01a30cd0

History | View | Annotate | Download (3.9 kB)

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