01: package org.claros.intouch.contacts.services;
02:
03: import java.io.IOException;
04: import java.io.PrintWriter;
05:
06: import javax.servlet.ServletException;
07: import javax.servlet.http.HttpServletRequest;
08: import javax.servlet.http.HttpServletResponse;
09:
10: import org.apache.commons.logging.Log;
11: import org.apache.commons.logging.LogFactory;
12: import org.claros.commons.auth.models.AuthProfile;
13: import org.claros.intouch.common.services.BaseService;
14: import org.claros.intouch.contacts.controllers.ContactsController;
15:
16: public class SaveCheckContactService extends BaseService {
17:
18: /**
19: *
20: */
21: private static final long serialVersionUID = 5962637897139123002L;
22: private static Log log = LogFactory
23: .getLog(SaveCheckContactService.class);
24:
25: /**
26: * The doPost method of the servlet. <br>
27: *
28: * This method is called when a form has its tag value method equals to post.
29: *
30: * @param request the request send by the client to the server
31: * @param response the response send by the server to the client
32: * @throws ServletException if an error occurred
33: * @throws IOException if an error occurred
34: */
35: public void doPost(HttpServletRequest request,
36: HttpServletResponse response) throws ServletException,
37: IOException {
38:
39: response.setHeader("Expires", "-1");
40: response.setHeader("Pragma", "no-cache");
41: response.setHeader("Cache-control", "no-cache");
42: response.setHeader("Content-Type", "text/html; charset=utf-8");
43: PrintWriter out = response.getWriter();
44:
45: String emailPrimary = request.getParameter("contEmailPrimary");
46: String emailAlternative = request
47: .getParameter("contEmailAlternative");
48:
49: AuthProfile auth = getAuthProfile(request);
50:
51: boolean exists = false;
52:
53: try {
54: exists = ContactsController.searchContactExistsByEmail(auth
55: .getUsername(), emailPrimary);
56: if (!exists && emailAlternative != null
57: && !emailAlternative.trim().equals("")) {
58: exists = ContactsController.searchContactExistsByEmail(
59: auth.getUsername(), emailAlternative);
60: }
61: } catch (Exception e) {
62: log.warn("error while checking if user exists", e);
63: }
64:
65: if (exists) {
66: out.print("yes");
67: } else {
68: out.print("none");
69: }
70: }
71: }
|