|
| 1 | +/* |
| 2 | + * To change this license header, choose License Headers in Project Properties. |
| 3 | + * To change this template file, choose Tools | Templates |
| 4 | + * and open the template in the editor. |
| 5 | + */ |
| 6 | + |
| 7 | +package org.cysecurity.cspf.jvl.controller; |
| 8 | + |
| 9 | +import java.io.IOException; |
| 10 | +import java.io.PrintWriter; |
| 11 | +import java.sql.Connection; |
| 12 | +import java.sql.ResultSet; |
| 13 | +import java.sql.Statement; |
| 14 | +import javax.servlet.ServletException; |
| 15 | +import javax.servlet.http.HttpServlet; |
| 16 | +import javax.servlet.http.HttpServletRequest; |
| 17 | +import javax.servlet.http.HttpServletResponse; |
| 18 | +import org.cysecurity.cspf.jvl.model.DBConnect; |
| 19 | +import org.json.JSONObject; |
| 20 | + |
| 21 | +/** |
| 22 | + * |
| 23 | + * @author breakthesec |
| 24 | + */ |
| 25 | +public class EmailCheck extends HttpServlet { |
| 26 | + |
| 27 | + /** |
| 28 | + * Processes requests for both HTTP <code>GET</code> and <code>POST</code> |
| 29 | + * methods. |
| 30 | + * |
| 31 | + * @param request servlet request |
| 32 | + * @param response servlet response |
| 33 | + * @throws ServletException if a servlet-specific error occurs |
| 34 | + * @throws IOException if an I/O error occurs |
| 35 | + */ |
| 36 | + protected void processRequest(HttpServletRequest request, HttpServletResponse response) |
| 37 | + throws ServletException, IOException { |
| 38 | + response.setContentType("application/json"); |
| 39 | + PrintWriter out = response.getWriter(); |
| 40 | + try { |
| 41 | + Connection con=new DBConnect().connect(getServletContext().getRealPath("/WEB-INF/config.properties")); |
| 42 | + String email=request.getParameter("email").trim(); |
| 43 | + JSONObject json=new JSONObject(); |
| 44 | + if(con!=null && !con.isClosed()) |
| 45 | + { |
| 46 | + ResultSet rs=null; |
| 47 | + Statement stmt = con.createStatement(); |
| 48 | + rs=stmt.executeQuery("select * from users where email='"+email+"'"); |
| 49 | + if (rs.next()) |
| 50 | + { |
| 51 | + json.put("available", "1"); |
| 52 | + } |
| 53 | + else |
| 54 | + { |
| 55 | + json.put("available", new Integer(0)); |
| 56 | + } |
| 57 | + } |
| 58 | + out.print(json); |
| 59 | + } |
| 60 | + catch(Exception e) |
| 61 | + { |
| 62 | + out.print(e); |
| 63 | + } |
| 64 | + finally { |
| 65 | + out.close(); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."> |
| 70 | + /** |
| 71 | + * Handles the HTTP <code>GET</code> method. |
| 72 | + * |
| 73 | + * @param request servlet request |
| 74 | + * @param response servlet response |
| 75 | + * @throws ServletException if a servlet-specific error occurs |
| 76 | + * @throws IOException if an I/O error occurs |
| 77 | + */ |
| 78 | + @Override |
| 79 | + protected void doGet(HttpServletRequest request, HttpServletResponse response) |
| 80 | + throws ServletException, IOException { |
| 81 | + processRequest(request, response); |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * Handles the HTTP <code>POST</code> method. |
| 86 | + * |
| 87 | + * @param request servlet request |
| 88 | + * @param response servlet response |
| 89 | + * @throws ServletException if a servlet-specific error occurs |
| 90 | + * @throws IOException if an I/O error occurs |
| 91 | + */ |
| 92 | + |
| 93 | + protected void doPost(HttpServletRequest request, HttpServletResponse response) |
| 94 | + throws ServletException, IOException { |
| 95 | + processRequest(request, response); |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * Returns a short description of the servlet. |
| 100 | + * |
| 101 | + * @return a String containing servlet description |
| 102 | + */ |
| 103 | + @Override |
| 104 | + public String getServletInfo() { |
| 105 | + return "Short description"; |
| 106 | + }// </editor-fold> |
| 107 | + |
| 108 | +} |
0 commit comments